JavaServer Page

December 7, 2006

A Cron Expressions This appendix covers the string

Filed under: OpenCms 6 — webmaster @ 6:20 am

But OpenCms 6 has an extended cron expression format that is much more suitable for an enterprise environment. It has seven possible fields (with seconds and years added to the original five) and some convenient synonyms (such as month and day names that can be substituted for numbers in the appropriate fields). Unfortunately, the changes are such that cron expressions that worked in OpenCms 5 will definitely not work in OpenCms 6. Cron Expressions in OpenCms 6 A cron expression has six mandatory fields (or slots) and one optional field. Adjacent fields are separated by a space. The asterisk * is a wild card meaning “any legal values”. In theory, we could construct an empty expression that would look like this: * * * * * * *. (This expression will not work in OpenCms for reasons explained below.) The source of information for this text is the javaDoc (documentation contained in the source code) for the org.opencms.scheduler package’s CmsScheduledJobInfo class. For more information, you can consult the source code. Each field in a cron expression stands for a particular time period. Here is a list of the fields with all of their legal values: 1. Seconds: 0 to 59, * 2. Minutes: 0 to 59, * 3. Hours: 0 to 23, * 4. Day-of-the-month: 1 to 31, L, *, ? (modifier: W) 5. Month: 1 to 12, Jan to Dec, * 6. Day-of-the-week: 1 to 7, Sun to Sat, L, *, ? (modifiers: L, #) 7. Year (optional): 1970 to 2099, * Note that the first three fields use 0 as the first number, while the next three begin with 1. The day-of-the-month and day-of-the-week fields are mutually exclusive, so one of these two fields will always need to be empty. This is done using a question mark, ?. For example, if I want to run a job at noon on the first day of every month, the cron expression will look like this: 0 0 12 1 * ? Alternatively, if I want to run the job every Sunday, the string will look like this: 0 0 12 ? * 1

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost jsp Web Hosting services

A Cron Expressions This appendix covers the string

Filed under: OpenCms 6 — webmaster @ 6:20 am

A Cron Expressions This appendix covers the string format for setting job schedules using the Scheduled Jobs Management screen in the administration view, and how to work with cron expressions using the revised format for OpenCms 6. What are Cron Expressions? OpenCms can run specific tasks at specific times, eliminating the need for a human operator to manually run tasks on a regular basis. As we saw in Chapter 4, the Scheduled Jobs Management screen in the administration view provides an interface for creating, modifying, and removing scheduled jobs. One of the most confusing aspects using of this tool is setting the Cron expression field in the New Job screen to execute at the desired time. A cron expression is a string of characters, organized into six or seven fields separated by spaces, that provides detailed information about when a task should be run. While cron expressions may initially look daunting, they are fairly simple to write and can be much quicker to use than alternative systems. There are a number of pre-defined cron expressions from which you can select, but these times may not fit your needs. Here is a brief explanation of how these cron-like time settings work. Changes from OpenCms 5 The OpenCms 5 series used a version of the cron expression that is rooted in the traditional UNIX cron server. In this format, there are only five fields (minute, hour, day, month, and day-of-week).

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost jsp Web Hosting services

Documentation and TemplateOne Now that we have walked

Filed under: OpenCms 6 — webmaster @ 12:31 am

Summary In this chapter, we have explored the basics of customizing OpenCms, we have created a module for our own code, and we have created custom templates, resources and elements within that module. Using the OpenCms tag library and the scriptlet API, we have added useful functional elements to templates and documents. At this point, you should have all of the tools you need to start customizing your own OpenCms site.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost java Web Hosting services

Documentation and TemplateOne Now that we have walked

Filed under: OpenCms 6 — webmaster @ 12:31 am

Documentation and TemplateOne Now that we have walked through the process of creating a simple module, you may want to move on to more sophisticated creations. OpenCms includes plenty of documentation to help you on your way. You may want to look at the OpenCms TemplateOne templates, which provide a sophisticated pre-built template environment (built with tag libraries, scriptlets, and java objects). OpenCms includes built-in documentation on the TemplateOne templates. At this point, we have covered the basics of template creation. The remainder of this chapter will explain how to avoid some of the common pitfalls of OpenCms template development. A Few Things to Watch Out For Whether using a tag library or writing scriptlets, there are a few things that can cause confusion and surprise to developers new to the platform. The File System The VFS, in spite of its name, does not behave exactly like a real file system. Furthermore, neither the servlet engine nor the jsp interpreter is aware of the existence of the VFS. When using jsp tags, be wary of the jsp include and directive tags, and the import tag from the java Standard Tag Libraries (JSTL). These tags do not handle the VFS/real file system split very well and can have some unpredictable results. According to OpenCms developers, judicious use of the import tag will work for some files, but the caveats are many, so I do not recommend it. The best way to handle inclusions is to use the OpenCms tag library’s include tag (as we have done already), or its API equivalent, the CmsjspActionElement class’s include method. The built-in java IO classes are also not aware of the VFS, and it is not possible, for example, to open a FileReader object on a location inside of OpenCms. There should be no need for this, as the CmsObject class provides methods for VFS file access. Redirecting and Forwarding OpenCms provides a custom subclass of HttpServlet, and some of the behaviors of this subclass do not match what the jsp interpreter assumes. This is the case with forwarding (using the jsp forward tag), which simply does not work in OpenCms. In the OpenCms documentation, the recommendation is that developers attempt to use the tag library provided for handling the problem. However, redirecting is straightforward and can be done in a scriptlet by executing the response object’s sendRedirect method.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost java Web Hosting services

Documentation and TemplateOne Now that we have walked

Filed under: OpenCms 6 — webmaster @ 12:31 am

Dynamic Content and Publishing Development is usually done by a user who has administration privileges, and tests are often performed (as we’ve done so far) on the Offline project. However, security settings for a visitor to the site are markedly different from those for an internal administrator, and code that works during development may fail for security reasons when a visitor tries to execute it. Likewise, publishing files from the Offline project to the Online project can change expected behavior if some or all of the content is exported. When jsp pages are exported statically (not the default behavior), they will be rendered once into static HTML, and will lose all of their dynamic functionality. Likewise, hard-coded links that do not use the OpenCms tag library’s link tag can break or point to non-existent documents. Obviously, the solution to this problem is to be aware of the problem and test a lot. If you are doing static exports of content, make sure you test out the template code. When content is rendered as static HTML, the jsp template is also rendered once. In my early exposure to OpenCms, I discovered this when I used the java.util package’s Date class in my main template. Two days after publishing my files as static resources, I realized with horror (or acute embarrassment) that the date hadn’t changed since I published the project. Setting the export property to false for jsp files should keep this from happening. Structuring Code and Content OpenCms is designed to be flexible, allowing organizations to adapt it to their own needs. Because of this, jsp files can get scattered around the VFS, and valuable (and reusable) functionality can be lost in a labyrinth of content folders. A well designed development process, though, should not allow this to happen. The OpenCms module structure provides an ideal mechanism for structuring code in a way that promotes reuse and organization. That is why we created a module before writing the first jsp. By structuring things wisely from the beginning, we avoid a jsp diaspora. As a general rule, move as much jsp code as possible into a module, particularly code that performs useful functions. If you find that a large number of scripts have a functional similarity (e.g. a set of blogging scripts), you may decide to create a new module specifically for that set of tasks. As an added advantage, modules are designed to be versioned and moved, and they can vastly improve the development-to-production process. The site can be designed and developed in a module on a development server and then exported. Then it can be imported into the testing and production environments. Since content exists separately (outside of the module), there is no risk of losing valuable content or migrating development content into production. The built-in versioning makes it very easy to quickly ascertain the state of each server.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost java Web Hosting services

December 6, 2006

To copy the file, click on the configuration.xml

Filed under: OpenCms 6 — webmaster @ 8:09 pm

The result of our jsp in action looks like this: Note that the terms we specified in the CSV file, “CMS”, “VFS” and “WYSIWYG”, have a dotted underline. Hovering the mouse pointer over one of these terms (as I did above over the term CMS) displays a context box that shows what the abbreviation stands for (”Content Management System”). As I mentioned before, you can use the OpenCms decorate tag in a template file. That way, the contents of a page file are run through the decorator. But there is one caveat when doing this you will need to turn off caching for the import tag. For example, applying a decorator to the body of a template would look like this: This is from the body section of the template. The decorate tag is the same as in the previous example, but to make sure the decorator works, we need to set the include tag’s cacheable attribute to “false”. That is all there is to using the decorate tag. Of course, the examples I’ve given above are fairly straightforward. The decorator is an advanced tool, and with a little creativity, you can use it to accomplish more complex processing. At this point, we have walked through the basics of the OpenCms taglib. OpenCms includes additional documentation on tag libraries in the OpenCms jsp Taglib Documentation Alkacon documentation module.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost clan Web Hosting services

To copy the file, click on the configuration.xml

Filed under: OpenCms 6 — webmaster @ 8:09 pm

The next two fields, Pre-Text and Post-Text, specify what should come before and after each match. For our example, Pre-Text is and Post-Text is . However, we want the first occurrence of each term to be marked with the title. The next two fields, Pre-Text (first occurance) and Post-Text (first occurance), are for specifying pre- and post-text for the first occurrence only. For the first occurrence of any abbreviation, we want the title attribute to be filled using the second element in the CSV file created above. For VFS, the decorator should search the CSV file and find VFS|Virtual File System. We want that second field to be placed in the title attribute. So the field Pre-Text (first occurance) should be given the value, . {$decoration} will be replaced by the second field in the CSV file. There is a second variable, aside from {$decoration}, that is available the {$locale} variable, which will contain the name of the locale currently used. The final field, Decoration File, should contain the full path reference of the CSV file that holds the definitions. Once everything is complete, click the “save and close” button (the yellow floppy disk with a black X) to save the definition and exit the XML editor. We are now ready to test the decorator. Using the decorate Tag Going back to our jsp page in the /playground folder, we can now add a decorator section:

OpenCms is a CMS that uses the VFS to store files, and a WYSIWYG editor to create and modify content.

The decorator will search through all of the text between the decorate tags and surround any matching terms with abbr tags. The decorate tag has two attributes, file and locale. The file attribute tells the decorator where the XML configuration file is. The optional locale attribute lets you explicitly set which locale should be used.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost clan Web Hosting services

To copy the file, click on the configuration.xml

Filed under: OpenCms 6 — webmaster @ 8:09 pm

To copy the file, click on the configuration.xml file icon, choose Copy, and name the copy my_decorations.xml. Click on the file icon for my_decorations.xml and choose Edit from the menu. This will open the XML editor. If you are going to set up multiple locales, check the Locale depending decoration checkbox. If this is checked, OpencCms will automatically search for locale-specific CSV files for this decoration. Next, click the target button on the right. This will bring up a context menu with a button shaped like a green plus sign. Click this button to add a new decoration definition. Now, seven new fields are available. The first field, Name, is for giving this decorator a human-readable name. The Mark first occurance checkbox, if checked, instructs OpenCms to treat the first occurrence of a match differently from subsequent versions of a match. In our case, we are adding abbr elements. For the first occurrence, we want the value of the title attribute to be “Virtual File System”, but for subsequent occurrences, we don’t want to assign the value to the title attribute at all, so in this case, the box should be checked.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost clan Web Hosting services

In addition to information about the platform, the

Filed under: OpenCms 6 — webmaster @ 1:37 pm

and turn it into: In OpenCms, all files are stored in the VFS. Since the decorate tag can be inserted into templates, it can be used to automatically decorate the contents of page files authored in the WYSIWYG editor. Using the decorate tag is a little more complicated than other tags because the it uses a configuration file and one or more text files to figure out what to decorate and how to decorate it, so the first thing we will need to do is create the configuration files. Decorator Configuration Files There are two types of configuration files. First, there are CSV (Comma Separated Values) files that contain lists of the terms to be decorated. Also, there is an XML configuration file that contains information on how to decorate the terms in the CSV file. The configuration information is stored in a shared folder: /system/shared/decoration. (Note that you will have to be able to access the /system folder.) We will create our CSV file in this folder. To do this, create a text file in /system/shared/decoration called decorationAbbr.csv. This file will contain the fields that tell the decorator what to look for and what information needs to be added. VFS|Virtual File System CSV|Comma Separated Values CMS|Content Management System WYSIWYG|What You See Is What You Get Note that the field delimiter above is not a comma (as the name CSV would suggest) but a vertical pipe ( |’). The first entry is the pattern that the decorator will look for. The second entry is the information that the decorator will need to decorate the text in this case, the term that will be put in the title attribute of the abbr tag. In addition to the default decoration file, you can create decoration files for specific locales. For example, we could create a file named decorationAbbr_de.csv that contains decoration data for German-language locales. OpenCms allows multiple locales to be set using different files. Once the decorationAbbr.csv file has been saved, we can work on the XML configuration file. OpenCms comes with a generic decoration XML configuration file, which is stored in /system/shared/decoration/configuration.xml. Rather than modify this file, we will make a copy of the file and edit that copy.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost mac Web Hosting services

In addition to information about the platform, the

Filed under: OpenCms 6 — webmaster @ 1:37 pm

The image on the left is the one using the HTML img tag. OpenCms has scaled the one on the right. Here is the URL that OpenCms generates: http://localhost:8080/opencms/ opencms/playground/my_images/funny_head.jpg?__scale=w:120,h:130. You may notice that the scaling information is appended to the end. For images stored in the VFS, you can directly instruct OpenCms to scale images by providing this information at the end of a URL. The decorate Tag Another tag introduced in OpenCms 6.2 is the decorate tag. This tag can be used to take an existing piece of HTML and automatically add new formatting according to a pre-defined pattern. For example, we could set up a decorate tag that would find all instances of “VFS” and surround them with the HTML abbreviation tag, abbr. This would take the text: In OpenCms, all files are stored in the VFS.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost mac Web Hosting services

« Previous PageNext Page »

Powered by Java Web Hosting