Tip: , ,

Do you know how can I have a different sidebar for each page?
I use Custom Sidebars Plugin.

Openmcs cms:info tag explained

Posted on 31-3-2011 | , , ,

<cms:info> is one of the most useful tags of the OpenCms taglib, but when I have a look at other’s code I can see that people prefer other ways to get the same results that this tag offers just writing one line.I think that happens because a lack of documentation and examples about it. Googleing a little about this tag you can find two main sources of documentation:

  • Opencms cms:info tag docs
  • Opencms cms:info tag tests

That is the original documentation packed with opencms, a really short explanation of some of the possible properties and a test for these properties where some of them returns the same result, so you can’t see the differences between them.

I think I made a better example where I explain a little bit how the cms:info tag works and where you can see those differences.

The example has 3 files:

  • cmsinfo_probe1.jsp: Make an import of cmsinfo_probe2.jsp.
  • cmsinfo_probe2.jsp: Load a xml content and print the cms:info properties
  • element.html: A xml content to be loaded from cmsinfo_probe2.jsp and make some experiments.

I attach a zip with the test files.

In cmsinfo_probe1.jsp we make an import, this way we will be able to see de differences between ‘opencms.uri’ and ‘opencms.request.uri’:

1
2
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<cms:include page="cmsinfo_probe2.jsp" />

In cmsinfo_probe2.jsp a contentload is made because i thought that maybe the ‘opencms.request.element.uri’ parameter was going to show the uri of the element loaded by <cms:contentload>. I was wrong:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>cms:info probe</title>
</head>
<body>
  <cms:contentload collector="singleFile" param="%(opencms.folder)element.html">
  <h3>OpenCms Parameters</h3>
  <b>opencms.version:</b> <pre><cms:info property="opencms.version" /></pre><br/>
	<b>opencms.url: </b><pre><cms:info property="opencms.url" /></pre><br/>
	<b>opencms.uri:</b> <pre><cms:info property="opencms.uri" /></pre><br/>
	<b>opencms.webapp</b>: <pre><cms:info property="opencms.webapp" /></pre><br/>
	<b>opencms.webbasepath</b>: <pre><cms:info property="opencms.webbasepath" /></pre><br/>
	<b>opencms.request.uri</b>: <pre><cms:info property="opencms.request.uri" /></pre><br/>
	<b>opencms.request.element.uri</b>: <pre><cms:info property="opencms.request.element.uri" /></pre><br/>
	<b>opencms.request.folder</b>: <pre><cms:info property="opencms.request.folder" /></pre><br/>
		<h3>Non usual OpenCms Parameters</h3>
	<b>opencms.request.encoding</b>: <pre><cms:info property="opencms.request.encoding" /></pre><br/>
	<b>opencms.request.locale</b>: <pre><cms:info property="opencms.request.locale" /></pre><br/>
		<h3>Some system properties</h3>
	<b>java.class.version</b>: <pre><cms:info property="java.class.version" /></pre><br/>
	<b>java.class.path</b>: <pre><cms:info property="java.class.path" /></pre><br/>
	<b>java.library.path</b>: <pre><cms:info property="java.library.path" /></pre><br/>
	<b>java.vm.vendor</b>: <pre><cms:info property="java.vm.vendor" /></pre><br/>
	<b>file.separator:</b> <pre><cms:info property="file.separator" /></pre><br/>
	<b>java.io.tmpdir</b>: <pre><cms:info property="java.io.tmpdir" /></pre><br/>
	<b>user.dir</b>: <pre><cms:info property="user.dir" /></pre><br/>
</cms:contentload>
</body>
</html>

As you can see in the code, i try two parameters that are not in the official documentation (at least in the examples) but I could see in the source code of the taglib. They are ‘opencms.request.encoding’ and ‘opencms.request.locale’.

At the end of the jsp I try some java System properties, some of them I consider that they are more useful than the ones that opencms gives in those examples. Anyway, you can use as property anyone that you can retrieve by using the System.getProperty() method, you can check what are they for JAVA SE5.

The following is the result I got when I made click on cmsinfo_probe1.jsp from my OpenCms explorer:

OpenCms Parameters

opencms.version:

7.5.2

opencms.url:

http://localhost:8080/opencms752/opencms/system/modules/probes/resources/pruebas/cmsinfo/cmsinfo_probe2.jsp

opencms.uri:

/opencms752/opencms/system/modules/probes/resources/pruebas/cmsinfo/cmsinfo_probe2.jsp

opencms.webapp:

opencms752

opencms.webbasepath:

C:\opt\Tomcat5.5\webapps\opencms752\

opencms.request.uri:

/system/modules/probes/resources/pruebas/cmsinfo/cmsinfo_probe1.jsp

opencms.request.element.uri:

/system/modules/probes/resources/pruebas/cmsinfo/cmsinfo_probe2.jsp

opencms.request.folder:

/system/modules/probes/resources/pruebas/cmsinfo/

Non usual OpenCms Parameters

opencms.request.encoding:

ISO-8859-1

opencms.request.locale:

es

Some system properties

java.class.version:

49.0

java.class.path:

C:\opt\Tomcat5.5\bin\bootstrap.jar;C:\opt\Tomcat5.5\bin\ojdbc14-10.2.0.3.jar

java.library.path:

C:\opt\Tomcat5.5\bin;.;C:\WINDOWS\system32;C:\WINDOWS;D:\oracle\product\10.1.0\Db_1\bin;D:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin\client;C:\oracle\app\oracle\product\10.2.0\server\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\ESPANOL;C:\Archivos de programa\Intel\DMIX;C:\opt\jdk1.5.0_17\bin;C:\grails\bin;C:\Archivos de programa\TortoiseGit\bin;C:\Archivos de programa\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\

java.vm.vendor:

Sun Microsystems Inc.

file.separator:

\

java.io.tmpdir:

C:\opt\Tomcat5.5\temp

user.dir:

C:\opt\Tomcat5.5

The results tell us that ‘opencms.request.uri’ returns the path to the page requested by the user and all other uri’s and url’s refers to the current jsp that executes the code.

The property ‘opencms.request.folder’ also refers to the folder of the page requested by the user, in the example it would be the ‘cmsinfo_probe1.jsp’ folder.

Hope this helps somebody!

Leave a comment.

What do you think?

You can also comment using your facebook account.

Connect with Facebook

Subscribe to javimarque

Follow me on Facebook

RSS Delicious recommendations

  • Using promises in javascript
    Nice article about how the promises pattern works in JavaScript. I promise! […]
  • 15 Helpful WordPress Plugins for the Savvy User
    This is a old lists of plugins for wordpress but every developer should know them because they solve common problems like database administration or syntax highlighting. […]
  • HTML2PDF a easy html to pdf library for php
    This is an outstanding work that makes people working with php generate pdf files, and the only thing you got to know to format the pdf is knowing how to use HTML. […]
  • Scrolling Parallax: A jQuery Plugin | Jon Raasch's Blog
    Parallax is the best way of give depth to your web site. Background elements scroll at different speeds so they seems to be nearer and further. […]
  • Spritebox -
    A new webapp to create css easisly for your sprites image. Just upload or give the url of the image and select what parts of the sprites are individuals by an intuitive interface. You must try it. […]