<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thoughts Electrique &#187; Java</title>
	<atom:link href="http://www.sebastian.himberger.de/blog/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sebastian.himberger.de/blog</link>
	<description>Sebastian Himbergers blog about technology and software development</description>
	<lastBuildDate>Thu, 08 Jul 2010 17:05:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting up XWiki in Tomcat and MySQL</title>
		<link>http://www.sebastian.himberger.de/blog/2009/09/10/setting-up-xwiki-in-tomcat-and-mysql/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/09/10/setting-up-xwiki-in-tomcat-and-mysql/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 13:32:34 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XWiki]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=468</guid>
		<description><![CDATA[I recently set up a new XWiki 2.0 instance (with MySQL) for documentation purposes. Although some of the steps are already described in the XWiki manual I&#8217;ll document it here mainly because I keep forgetting things. Also step-by-step tutorials come in handy when you&#8217;re in a hurry.

Create the webapp directory
Since the configuration files have to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently set up a new <a title="XWiki Enterprise website" href="http://enterprise.xwiki.org" target="_blank">XWiki 2.0</a> instance (with MySQL) for documentation purposes. Although some of the steps are already described in the XWiki manual I&#8217;ll document it here mainly because I keep forgetting things. Also step-by-step tutorials come in handy when you&#8217;re in a hurry.</p>
<p><span id="more-468"></span></p>
<h3><strong>Create the webapp directory</strong></h3>
<p>Since the configuration files have to be modified an exploded WAR has to be used. The webapp directory has to be created and the WAR will be extracted inside of it.</p>
<pre class="terminal">mkdir xwiki &amp;&amp; cd xwiki
unzip ../xwiki.war
rm ../xwiki.war</pre>
<h3><strong>Create and configure a database</strong></h3>
<p>Create a database including a dedicated database user. Open the file <em>WEB-INF/hibernate.cfg.xml</em> and uncomment the MySQL block. Modify the following properties:</p>
<ul>
<li>connection.username</li>
<li>connection.password</li>
<li>connection.url</li>
</ul>
<p><strong>Important:</strong> Don&#8217;t forget to add the <a title="MySQL JDBC Connector" href="http://dev.mysql.com/downloads/connector/j/" target="_blank">MySQL JDBC driver</a> to your classpath (e.g. WEB-INF/lib).</p>
<p><strong>Note: </strong>It is of course also possible to use a container managed DataSource via JNDI.</p>
<h3><strong>Configure Logfile</strong></h3>
<p>Since the security manager restricts file IO to the webapp directory the logging has to be reconfigured. To do so the <em>log4.properties</em> file has to be copied from <em>xwiki-core-2.0-milestone-4.jar</em> to the <em>WEB-INF/classes</em> directory. After this the property <em>log4j.appender.file.File</em> has to be modified to point to a writeable path.</p>
<h3><strong>Add the context file to Tomcat</strong></h3>
<p>Add a file name <em>${context}.xml</em> to the <em>/conf/Catalina/localhost</em>&#8221; directory of <em>$CATALINA_HOME</em> (the Tomcat instance) and put the following content into it:</p>
<pre class="file">&lt;Context path="<strong>${contextPath}</strong>" docBase="<strong>${pathToWebapp}</strong>" &gt;&lt;/Context&gt;</pre>
<p>Eventually put in references to resources like DataSource&#8217;s etc.</p>
<h3><strong>Create the proxy settings in Apache HTTPD</strong></h3>
<p>You can use any proxy settings. I&#8217;m currently using a very simple setup:</p>
<pre class="file">&lt;Proxy ajp://localhost:10709*&gt;
  Allow from all
&lt;/Proxy&gt;

RewriteEngine On
RewriteRule ^/$ /<em>xwiki</em>/ [R=301,L]

ProxyPass        /      ajp://localhost:10709/
ProxyPassReverse /      ajp://localhost:10709/</pre>
<p><strong>Note:</strong> <em>xwiki </em>is the contextPath</p>
<h3><strong>Test the installation</strong></h3>
<p>Surf to http://www.yourdomain.com/. An empty XWiki page should be displayed. The first step should always be to register a user so the administration area is accessible. The default content can be imported by using the page <em>/${contextPath}/bin/import/XWiki/XWikiPreferences</em>.</p>
<p>I&#8217;ll probably blog more about XWiki and how to customize it in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/09/10/setting-up-xwiki-in-tomcat-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some pointers from the JBoss World 2009</title>
		<link>http://www.sebastian.himberger.de/blog/2009/09/07/some-pointers-from-the-jboss-world-2009/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/09/07/some-pointers-from-the-jboss-world-2009/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 17:30:47 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[JGroups]]></category>
		<category><![CDATA[JSR-299]]></category>
		<category><![CDATA[mod_cluster]]></category>
		<category><![CDATA[Opinionated]]></category>
		<category><![CDATA[RESTeasy]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=459</guid>
		<description><![CDATA[Last Week I attended the JBoss World in Chicago and I had a good time. My favorite Session was Large Clusters in JBoss presented by Bela Ban. It was a very hands-on explanation of the new mod_cluster and presented nicely some of the problems with clustered environments (such as binary incompatible rolling updates, management of [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-464" style="margin:5px; float: left;" title="JBoss World Logo" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2009/09/summitjbossworldpromo.png" alt="" width="200" height="150" />Last Week I attended the <a title="JBoss World Website" href="http://www.jbossworld.com/">JBoss World in Chicago</a> and I had a good time. My favorite Session was <strong>Large Clusters in JBoss presented by Bela Ban</strong>. It was a very hands-on explanation of the new <a title="mod_cluster website" href="http://jboss.org/mod_cluster/">mod_cluster</a> and presented nicely some of the problems with clustered environments (such as binary incompatible rolling updates, management of configuration files, discovery, etc.) and how to work with them (I always like sessions which keep it down a bit and don&#8217;t promote the technology as the next holy grail). I also enjoyed <strong>Putting Java to REST by Bill Burke</strong> which gave a good introduction to <a title="RESTeasy website" href="http://jboss.org/resteasy/">RESTeasy</a>. The library (including the JAX-RS standard) looks very straightforward and easy to comprehend (This is always something which I didn&#8217;t like about all the SOA stacks). I must say that I&#8217;m a bit skeptical about the announced <a href="http://www.jboss.org/reststar">REST-star</a> initiative. I think it may be a little early to start a standardization effort which will certainly make the technology seem more complex.</p>
<p><span id="more-459"></span></p>
<p>The JBoss Spring integration project (Snowdrop) seemed a bit too simple to me. After all I have used JBoss with Spring and to be honest it didn&#8217;t seem so complex to me as to deserve a whole session. Maybe it was useful for other people. For me it felt a bit like a marketing session (&#8220;look we support Spring too&#8221;). But I&#8217;m a cynic so maybe I&#8217;m just perceiving it wrong.</p>
<p>I liked the presentation on the new <a href="http://jcp.org/en/jsr/detail?id=299">JSR-299</a> which is called <strong>Contexts and Dependency Injection (CDI)</strong>. I my opinion the talk was a bit too focused on the <strong>DI</strong> part. I&#8217;m really into the topic of context and state management lately which is a topic which is still feels like an unsolved problem around web frameworks (Of course: full-stack-frameworks like Tapestry, JSR-299 or  Wicket offer proprietary solutions but then you have to buy into the whole framework which might be good but might also be a showstopper). It also seems we have just replaced XML with annotations. All the new frameworks are very annotation-heavy. It will be interesting to see how this plays out when you combine all the solutions together. I doubt the code will be very readable. But <strong>Pete Muir</strong> did an excellent job with presenting it.</p>
<p><strong>The migration from WebLogic to Tomcat by Joel Tosi</strong> spoke to my heart. Joel explained how the usage of the application server WebLogic at the CME lead to a huge complexity problem and how they solved it by basically stripping their platform down to the bare minimum (from a full blown JEE-stack down to Servlets and Persistence). It think complexity is a major problem with today&#8217;s solution. Often simplistic examples are used to sell new technology but if the application grows bigger it&#8217;s not clear how frameworks or programming models will scale up.</p>
<p><strong>To sum it up</strong>: I enjoyed the conference a lot. It learned a whole lot of stuff and sometimes felt like the dumbest person in the room (I still don&#8217;t know how ESBs or BPM works exactly &#8211; it remains a mystery to me). The new technologies look good but I think a more humble approach would suit them better. After all EJB2 was praised as a great solution so we should be a bit more careful. Maybe we&#8217;re always falling for the same pattern. Simplistic examples are good to explain a new technology but sometimes it would be interesting to present the big picture and show how it plays out in real applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/09/07/some-pointers-from-the-jboss-world-2009/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JSP to download OpenCms resources as a ZIP</title>
		<link>http://www.sebastian.himberger.de/blog/2009/06/25/jsp-to-download-opencms-resources-as-a-zip/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/06/25/jsp-to-download-opencms-resources-as-a-zip/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 18:09:38 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[OpenCms]]></category>
		<category><![CDATA[Sourcecode]]></category>
		<category><![CDATA[ZIP]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=443</guid>
		<description><![CDATA[What often bugged me is that I can upload a set of files into OpenCms as a ZIP file but can not download a tree of files as such (without the use of the database export feature). I had hacked together this little JSP some time ago. It allows you to dynamically download a set [...]]]></description>
			<content:encoded><![CDATA[<p>What often bugged me is that I can upload a set of files into OpenCms as a ZIP file but can not download a tree of files as such (without the use of the database export feature). I had hacked together this little JSP some time ago. It allows you to dynamically download a set of OpenCms resources as a ZIP file.</p>
<p>The JSP has no interface since I mainly use it for development. Simply create a JSP somewhere in the OpenCms VFS and then open the file via the browser. E.g.:</p>
<p>&#8220;http://workplace.com/system/createzip?<strong>source</strong>=<em>/system/modules/foo</em>&amp;<strong>filename</strong>=<em>foo-module.zip</em>&#8221;</p>
<p>The <strong>source</strong> parameter specifies which directory to zip up and the <strong>filename</strong> parameter which filename to use for the generated file. You can only zip up resources with a total size of 10 megabytes. This is mainly to prevent OutOfMemory errors to happen. You can easily increase the size by altering the variable <strong>maxSourceSize</strong> to any value you need.</p>
<p>If you find any bugs or want to give feedback simply leave a comment or send me an email.</p>
<p><span id="more-443"></span></p>
<pre class="file">&lt;%@page import="org.opencms.util.*,
                org.opencms.jsp.*,
                org.opencms.file.*,
                java.util.*,
                java.io.*,
                java.util.zip.*
" %&gt;&lt;%

// Maximum filesize to prevent OutOfMemory errors
long maxSourceSize = 1024*1024*10; // 10 Megabytes

// The filename to use as output
String filename = request.getParameter("filename");

// The directory to zip
String source = request.getParameter("source");

if (CmsStringUtil.isEmpty(filename) || CmsStringUtil.isEmpty(source )) {
  // Ensure that all parameters are given
  throw new IllegalArgumentException("Please specify the 'source' and the 'filename' parameter");
}

if (!source.endsWith("/")) { source = source + "/"; }

CmsJspActionElement cmsa = new CmsJspActionElement(pageContext,request,response);
CmsObject cmso = cmsa.getCmsObject();
List zipResources = new ArrayList();

// Collect all the resources
CmsResource sourceResource = cmso.readResource(source);
if (!sourceResource.isFolder()) {
  throw new IllegalArgumentException("Please specify a folder to zip");
}
List cmsResources = cmso.readResources(source,CmsResourceFilter.DEFAULT);
for (Iterator i = cmsResources.iterator(); i.hasNext();) {
  zipResources.add(i.next());
}

// Create the zip file
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zipfile = new ZipOutputStream(bos);

long currentSize = 0;
for (Iterator i = zipResources.iterator(); i.hasNext(); ) {
  CmsResource res = (CmsResource) i.next();

  currentSize += res.getLength();
  if (currentSize &gt; maxSourceSize) {
    // Ensure that we don't zip up too much
    throw new RuntimeException("Source size is bigger than: " + (maxSourceSize/1024) + " kilobytes");
  }

  String sourcePath = cmso.getRequestContext().getSitePath(res);
  String targetPath = sourcePath;
  if (targetPath.startsWith(source)) {
    targetPath = targetPath.substring(source.length());
  }

  //out.println("Zipping " + sourcePath + " as " + targetPath + "&lt;br/&gt;");
  if (res.isFile()) {
  ZipEntry zipentry = new ZipEntry(targetPath);
  zipfile.putNextEntry(zipentry);
      CmsFile file = cmso.readFile(res);
      zipfile.write(file.getContents(),0,file.getLength());
  }
}

zipfile.close();
byte[] content = bos.toByteArray();

response.setContentType("application/octet-stream");
response.setContentLength((int)content.length);
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"" );

response.getOutputStream().write(content,0,content.length);
response.getOutputStream().flush();

%&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/06/25/jsp-to-download-opencms-resources-as-a-zip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenCms and Google App Engine</title>
		<link>http://www.sebastian.himberger.de/blog/2009/06/24/opencms-and-google-app-engine/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/06/24/opencms-and-google-app-engine/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 10:07:44 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[App Engine]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenCms]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=415</guid>
		<description><![CDATA[Especially with the new JPA driver for OpenCms by Georgi Naplatanov the question of running OpenCms on Google App Engine came up quite often at the OpenCms Days 2009. I had the same Idea when I first heard of the Java support for App Engine and did some quick research on how to do this. [...]]]></description>
			<content:encoded><![CDATA[<p>Especially with the new JPA driver for OpenCms by Georgi Naplatanov the question of running OpenCms on <a title="AppEngine Java page" href="http://code.google.com/intl/de-DE/appengine/docs/java/overview.html" target="_blank">Google App Engine</a> came up quite often at the OpenCms Days 2009. I had the same Idea when I first heard of the Java support for App Engine and did some quick research on how to do this. The research showed that running OpenCms on Google App Engine would require a huge rewrite of some OpenCms core functionalities.</p>
<p><span id="more-415"></span></p>
<p>The problem with OpenCms and App Engine is that the applications on App Engine run in a restricted sandbox which limits what you can do in terms of Java API functionality. There&#8217;s also a JRE whitelist which limits the classes you can access in your application. If you look at the scalability model promoted by App Engine these limitations make a lot of sense but unfortunately they make running OpenCms on there nearly impossible. You can find a<a href="http://code.google.com/intl/de-DE/appengine/docs/java/runtime.html"> detailed description of the App Engine runtime at Google code</a>. The main problems are:</p>
<ul>
<li><strong>No filesystem access: </strong>OpenCms uses the filesystem for some very important tasks:
<ul>
<li>The JSP files are exported into the WEB-INF directory to be executable. This means there could be no dynamic updates or adds of JSP files through the workplace.</li>
<li>The configuration is stored in the filesystem and dynamically updated if e.g. the search configuration is updated or a module is installed. The configuration would have to be stored in the database.</li>
<li>The search index is stored in the filesystem. This could be circumvented if a Lucene database store like the one shipped with <a href="http://www.compass-project.org/" target="_blank">Compass </a>is used. Nevertheless this would have to be implemented.</li>
</ul>
</li>
<li><strong>No threading:</strong> OpenCms makes uses of threading for scheduled tasks, publishing and other tasks. Since App Engine doesn&#8217;t allow threads this would have to be implemented otherwise.</li>
<li><strong>Response-Time-Limit: </strong>App Engine imposes a time limit to handle request on the application. Escpecially the publishing mechanism in OpenCms causes very long response times. These parts would have to be rewritten.</li>
<li><strong>Persistent data has to be stored in the datastore</strong>: OpenCms uses an in memory HashMap to store the locking information (file locks). This makes it difficult to cluster OpenCms and also limits the use in Googles App Engine. This also affects the Flex-Cache: Publishing events would have to be propagated and I&#8217;m not sure if this would work with App Engine (comments are very welcome on this point).</li>
</ul>
<p>I had a short talk with Alexander about this topic and it at least seemed to us that making OpenCms run on the App Engine would be an enormous task and is currently not worth doing without excessive sponsoring.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/06/24/opencms-and-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restrict visibility of OpenCms templates to certain folders</title>
		<link>http://www.sebastian.himberger.de/blog/2009/06/03/restrict-visibility-of-opencms-templates-to-certain-folders/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/06/03/restrict-visibility-of-opencms-templates-to-certain-folders/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:51:26 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[OpenCms]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=401</guid>
		<description><![CDATA[Since I&#8217;m currently working on an OpenCms mutli site solution I was looking for a possibility to restrict the available templates of a site. I know this can be done via permissions but the manual implementation of this is rather painful. I&#8217;m currently in the process of extending the OpenCms security manager to take care [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m currently working on an OpenCms mutli site solution I was looking for a possibility to restrict the available templates of a site. I know this can be done via permissions but the manual implementation of this is rather painful. I&#8217;m currently in the process of extending the OpenCms security manager to take care of this but while doing this I found an (to me) unknown feature.</p>
<p>By usage of the property <em>folders.available</em> (you might have to define it first) on a template you can specify a list of comma seperated folders in which the template is available (in the dropdown).</p>
<p>Unfortunately this property works only on file level and can not be inherited via the folder hierarchy. Also it does not provide a secure solution since the template can always be set via the advanced property dialog.</p>
<p>But you never know when a feature could come in handy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/06/03/restrict-visibility-of-opencms-templates-to-certain-folders/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use the power of JSP tag files in OpenCms</title>
		<link>http://www.sebastian.himberger.de/blog/2008/12/12/use-the-power-of-jsp-tag-files-in-opencms/</link>
		<comments>http://www.sebastian.himberger.de/blog/2008/12/12/use-the-power-of-jsp-tag-files-in-opencms/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 09:22:38 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[OpenCms]]></category>
		<category><![CDATA[Sourcecode]]></category>
		<category><![CDATA[Taglibs]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=220</guid>
		<description><![CDATA[Since version 7 OpenCms is a Servlet 2.4 and JSP 2.0 conforming application. In addition to the improved expression language (EL) JSP 2.0 also brings in the possibility of developing custom tags(actions) using JSP rather than writing Java code. This allows for some pretty neat things and enables you to go one step further towards [...]]]></description>
			<content:encoded><![CDATA[<p>Since version 7 OpenCms is a <em>Servlet 2.4</em> and <em>JSP 2.0</em> conforming application. In addition to the improved expression language (<em>EL</em>) JSP 2.0 also brings in the possibility of developing custom tags(actions) using JSP rather than writing Java code. This allows for some pretty neat things and enables you to go one step further towards cleaner view code. I&#8217;ve used this in one of my last projects extensively to refactor common code like pagers and link generation. For example:</p>
<pre class="file">&lt;cms:include file="/system/modules/com.example.ocms.commons/elements/pager"&gt;
  &lt;cms:param name="currentPage"&gt;
    &lt;c:out value="${model.currentPage}"/&gt;
  &lt;/cms:param&gt;
  &lt;cms:param name="pageCount"&gt;
    &lt;c:out value="${model.pageCount}"/&gt;
  &lt;/cms:param&gt;
&lt;/cms:include&gt;</pre>
<p>Became:</p>
<pre class="file">&lt;wt:pager model="${model}"/&gt;</pre>
<p>Not does it only look cleaner and is much more focused, it also decouples your view more from the underlying CMS solution. Of course you could also develop a custom tag library using Java (which I have done a few times) but using a JSP the advantage that code can be changed on the fly and even from a web designer. You can always refactor your JSP taglib into a Java one if you need to do it. There are some limitations of JSP tag files (like you can&#8217;t use scriptlets in the body) but they are easy to get around.</p>
<p><strong>But as always:</strong> This is no silver bullet. There are problems with tag files which may not be obvious at the first glance.</p>
<p><span id="more-220"></span></p>
<h3>How to create a tag</h3>
<p>Creating a tag is easy. I will show you the necessary steps while developing a tag which allows the user to loop over the contents of an OpenCms <a href="http://www.opencms-wiki.org/Virtual_File_System">VFS</a> directory.</p>
<h4>Preparing your module</h4>
<p>As normal Java libraries too, JSP tags need to be exported into the filesystem to be read by the <a href="http://en.wikipedia.org/wiki/Java_Servlet#Servlet_containers">Servlet-Container</a>. Normally the tag files reside under a directory like <em>${yourwebapp}/WEB-INF/tags/mylibrary</em>. So what we will do is adding a new export point to the module containing our tag files.</p>
<p>First we create a new directory called <em>tags </em>inside the module we want to contain our tags (normally I create a module for each site). The resulting structure will look something like this</p>
<div id="attachment_227" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/create-tags-folder.png"><img class="size-full wp-image-227" title="The tags folder inside the module directory" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/create-tags-folder.png" alt="The tags folder inside the module directory" width="500" height="154" /></a><p class="wp-caption-text">The tags folder inside the module directory</p></div>
<p>Then we open the module administration and add an export point to our module (<em>Administration -&gt;  	<span class="link" onclick="openPage('/system/workplace/views/admin/admin-main.jsp?path=/modules');" onmouseover="sMH('navtool7');" onmouseout="hMH('navtool7');"><span style="white-space: nowrap;">Module Management</span></span> -&gt; Edit Your module -&gt; Module exportpoints -&gt; New exportpoint</em>).</p>
<div id="attachment_228" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/add-exportpoint.png"><img class="size-full wp-image-228" title="Adding the tags exportpoint" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/add-exportpoint.png" alt="Adding the tags exportpoint" width="500" height="138" /></a><p class="wp-caption-text">Adding the tags exportpoint</p></div>
<p>After pressing <em>OK</em> we are well prepared to add custom tags to our OpenCms module.</p>
<h4>Creating the tag file</h4>
<p>We now create a directory for our taglib. This will be located inside our newly created <em>tags </em>folder. Because we want to create a tag which interacts with the OpenCms VFS we will simply call the folder <em>vfs</em>. Inside this directory we create a new JSP resource called <em>directoryLoop.tag</em>. The result should look something like this:</p>
<div id="attachment_230" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/the-tag-file.png"><img class="size-full wp-image-230" title="The created tag file in the VFS" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/the-tag-file.png" alt="The created tag file in the VFS" width="500" height="57" /></a><p class="wp-caption-text">The created tag file in the VFS</p></div>
<p>Now it&#8217;s time to write some code <img src='http://www.sebastian.himberger.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h4>Writing the tag file</h4>
<p>I don&#8217;t want to go into the details of developing tag files in general. This topic has been covered by dozens of books and online tutorials. I have collected some links in this blog post which explain the development of tag files in detail. Have a look at the section <em>Further reading</em> if you want to find out.</p>
<p>I will assume you&#8217;ve already developed JSP files inside OpenCms so I won&#8217;t explain the steps in detail. If you have questions regarding the sourcecode simply post a comment.</p>
<p>Here&#8217;s the commented sourcecode for our tag file.</p>
<pre class="file">&lt;%@ tag body-content="scriptless" %&gt;
&lt;%@ tag import="org.opencms.jsp.*,
                org.opencms.file.*,
                java.util.*" %&gt;
&lt;%@ attribute name="folder" required="true" %&gt;
&lt;%@ variable name-given="resource" scope="NESTED" %&gt;
&lt;%@ variable name-given="status" scope="NESTED" %&gt;
&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;&lt;%

// First we get the pageContext variable.
// Tag files only have an explicit JspContext but in this case
// it is a PageContext which is a subclass of JspContext.
PageContext pageContext = (PageContext)jspContext;

// Instantiate the usual CmsObject to access OpenCms data
CmsJspActionElement cmsa = new CmsJspActionElement(pageContext ,request,response);
CmsObject cmso = cmsa.getCmsObject();

// Read the resources, note that we can access the tag
// parameters using the pageContext.
String folder = (String) pageContext.getAttribute("folder");
folder = cmso.getRequestContext().removeSiteRoot(folder);
List resources = cmso.readResources(folder,CmsResourceFilter.DEFAULT,false);

// We store the list of resources in the pageContext for usage with JSTL
pageContext.setAttribute("resources",resources);

%&gt;

&lt;c:forEach var="resource" items="${resources}" varStatus="status"&gt;
  &lt;jsp:doBody/&gt;
&lt;/c:forEach&gt;</pre>
<p>As you can see the tag file looks like a usual JSP file with only a few differences.</p>
<p>The tag exports two variables: The <em>current resource</em> and the <em>iteration status</em>. These can be accessed from the invoking JSP. We will make use of this in the next example.</p>
<p><strong>To use the tag you have to publish the file</strong> so it gets written to the file system. After you&#8217;re finished writing/modifying the tag: Don&#8217;t forget to publish it!</p>
<p><strong>You can&#8217;t preview tags</strong>, even though they are JSP files. You also won&#8217;t get compiler warnings. You always need a JSP file to test your tag files.</p>
<h4>Using the created tag</h4>
<p>We will use the created tag to implement a simple file browser. The file browser displays the contents of a folder and allows the user to navigate into subfolders recursively. Please note that <strong>this is definately no production ready code</strong>.</p>
<pre class="file"><strong>&lt;%@ taglib prefix="vfs" tagdir="/WEB-INF/tags/vfs" %&gt;</strong>
&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;

&lt;%-- Determine the current folder, set to "/" if no parameter given --%&gt;
&lt;c:set var="folder" value="${param.folder}"/&gt;
&lt;c:if test="${folder eq '' or folder == null}"&gt;
  &lt;c:set var="folder" value="/"/&gt;
&lt;/c:if&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;style type="text/css"&gt;

   .row-1 {
     background-color: #ECECEC;
   }

  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Resources of folder "${folder}"&lt;/h1&gt;
&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;&lt;/th&gt;
    &lt;th&gt;Name&lt;/th&gt;
    &lt;th&gt;Size&lt;/th&gt;
    &lt;th&gt;Date created&lt;/th&gt;
  &lt;/tr&gt;
<strong>  &lt;vfs:directoryLoop folder="${folder}"&gt;</strong>
  &lt;%-- We use the status for alternating row classes, useful for css --%&gt;
  &lt;tr class="row-${status.count % 2}"&gt;
    &lt;td&gt;
      &lt;%-- Display D for directory or F for file --%&gt;
      &lt;c:choose&gt;
        &lt;c:when test="${resource.folder}" &gt;D&lt;/c:when&gt;
        &lt;c:otherwise&gt;F&lt;/c:otherwise&gt;
      &lt;/c:choose&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%-- If the current resource is a folder, display a link --%&gt;
      &lt;c:choose&gt;
        &lt;c:when test="${resource.folder}" &gt;
          &lt;a href="?folder=${resource.rootPath}"&gt;${resource.name}&lt;/a&gt;
        &lt;/c:when&gt;
        &lt;c:otherwise&gt;${resource.name}&lt;/c:otherwise&gt;
      &lt;/c:choose&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%-- If the current resource is a file, display size --%&gt;
      &lt;c:if test="${!resource.folder}"&gt;${resource.length}&lt;/c:if&gt;
    &lt;/td&gt;
    &lt;td&gt;${resource.dateCreated}&lt;/td&gt;
  &lt;tr&gt;
<strong>  &lt;/vfs:directoryLoop&gt;</strong>
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>As you can see the tags are included with the directive.</p>
<pre class="file"><strong>&lt;%@ taglib prefix="vfs" tagdir="/WEB-INF/tags/vfs" %&gt;
</strong></pre>
<p>The usage of the tags is similar to normal tags with the exception that you can&#8217;t use scriptlets in the tag bodies. If the example is working you should see something like the following.</p>
<div id="attachment_241" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/ouput.png"><img class="size-full wp-image-241" title="The output of the created JSP" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/12/ouput.png" alt="The output of the created tag" width="500" height="178" /></a><p class="wp-caption-text">The output of the created JSP</p></div>
<p>If you have trouble reading the above code. Here is a more condensed version of a file using the tag:</p>
<pre><strong>&lt;%@ taglib prefix="vfs" tagdir="/WEB-INF/tags/vfs" %&gt;</strong>
&lt;ul&gt;
<strong>&lt;vfs:directoryLoop folder="/system/modules"&gt;</strong>
  &lt;li&gt;${resource.name}&lt;/li&gt;
<strong>&lt;/vfs:directoryLoop&gt;</strong>
&lt;/ul&gt;</pre>
<h3>Things to keep in mind</h3>
<p>JSP tag files and OpenCms really are a nice fit, but before you start working on converting all your custom includes to tag files keep in mind some of the disadvantages of tag files in respect to using <em>&lt;cms:include&gt;</em>.</p>
<ul>
<li><strong>Tag files are not seperated by online/offline</strong>. Since the tag files only get exported during publishing there is no way of developing the tags in the offline project. You always have to publish the tag file to see your changes (It&#8217;s like a normal, Java based, tag library). This means if you have an error in your code the live system will be affected by it. In my opinion this problem is not as big as it sounds. Tags are normally developed in a staged environment or on a developer machine and then deployed on the live server. Additionally they are no replacement for templates and therefore shouldn&#8217;t be changed often.</li>
<li><strong>Tag files are not cached</strong>. The output of a <em>&lt;cms:include&gt;</em> may be cached by the OpenCms FlexCache. This can speed up the rendering enormously, tag files are always processed. In my opinion this no big problem. Tag files will mostly always be used in JSP templates which in turn will be cached by the FlexCache. I would suggtest that tag files are used as the building blocks for JSP templates and therefore are one a finer granular level. The chunks you want to cache are normally much more coarse grained.</li>
</ul>
<h3>Finishing thoughts</h3>
<p>In my opinion JSP tag files are a great thing. They can help you clean up messy JSP templates and nicely decouple your JSPs from OpenCms (although I used a pretty OpenCms heavy example in this post). I hope this post was useful and helped you adding another tool to your toolbox. If you have further questions or need help regarding a specific project, please leave a comment or <a href="/contact">contact me directly</a>.</p>
<h3>Further Reading</h3>
<p>These tutorials can help you developing your own tag files or looking up classes used in this tutorial.</p>
<ul>
<li><a title="Encapsulating Reusable Content Using Tag Files" href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html" target="_blank">The JEE 5 tutorial on creating tag files</a></li>
<li><a title="Creating JSP 2.0 Tag Files" href="http://www.oracle.com/technology/pub/articles/cioroianu_tagfiles.html" target="_blank">An online tutorial on JSP tag files by Oracle</a></li>
<li><a title="Easy Custom Tags with Tag Files" href="http://today.java.net/pub/a/today/2003/11/14/tagfiles.html" target="_blank">A java.net article on tag files, short and good</a></li>
<li><a title="The OpenCms JavaDoc" href="http://files.opencms.org/javadoc/core/" target="_blank">The OpenCms JavaDoc, always handy</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2008/12/12/use-the-power-of-jsp-tag-files-in-opencms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display RSS Feeds in JSPs with RSS4JSP</title>
		<link>http://www.sebastian.himberger.de/blog/2008/12/11/display-rss-feeds-in-jsps-with-rss4jsp/</link>
		<comments>http://www.sebastian.himberger.de/blog/2008/12/11/display-rss-feeds-in-jsps-with-rss4jsp/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 11:40:47 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Rome]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Taglib]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=217</guid>
		<description><![CDATA[I recently discovered the freshly released RSS4JSP tag library. Its a wrapper around the mature and widely used Rome RSS library which was developed by Sun and then open sourced. The library allows you to simply display (news) feeds inside your JSP pages.
While it&#8217;s certainly a young project, I found it very useful and easy [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered the freshly released <a href="http://sourceforge.net/projects/rss4jsp/">RSS4JSP </a>tag library. Its a wrapper around the mature and widely used <a href="https://rome.dev.java.net/">Rome RSS library</a> which was developed by Sun and then open sourced. The library allows you to simply display (news) feeds inside your JSP pages.</p>
<p>While it&#8217;s certainly a young project, I found it very useful and easy to use. I gave it a try to create the <em>Latest blog posts</em> box on my, OpenCms based, <a href="http://www.sebastian.himberger.de/">homepage</a>. The box was created during 5 minutes which I think is impressive (given that you have to type the HTML too).</p>
<p>Unfortunately the project does not allow the syndication of multiple feeds into one feed (This is a nice feature of Rome which I used in a recent project) but maybe it will be added in the future (or I will add it myself).</p>
<p><a title="RSS4JSP at Sourceforge" href="https://sourceforge.net/projects/rss4jsp/" target="_blank">Check it out at sourceforge</a> or <a title="rss4jsp: A Tag Library for Project Rome" href="http://philhaigh.blogspot.com/2008/11/rss4jsp-tag-library-for-project-rome.html" target="_blank">visit the authors blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2008/12/11/display-rss-feeds-in-jsps-with-rss4jsp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enterprise grade software is an euphemism</title>
		<link>http://www.sebastian.himberger.de/blog/2008/12/04/enterprise-grade-software-is-an-euphemism/</link>
		<comments>http://www.sebastian.himberger.de/blog/2008/12/04/enterprise-grade-software-is-an-euphemism/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 19:48:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cal Henderson]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Enterprise]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=163</guid>
		<description><![CDATA[I recently had to restart a Java webapplication because somehow the JDBC connection to the database server was hanging completely. This reminded me of a sentence a friend of mine told me during the OpenCms Days 2008.
&#8220;Enterprise software just means that it&#8217;s targeted at customers who can afford the guy who restarts the application server [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to restart a Java webapplication because somehow the JDBC connection to the database server was hanging completely. This reminded me of a sentence a friend of mine told me during the OpenCms Days 2008.</p>
<blockquote><p><em>&#8220;Enterprise software just means that it&#8217;s targeted at customers who can afford the guy who restarts the application server every few hours.&#8221;</em></p></blockquote>
<p>I had to laugh because while the quote is clearly cynical it has a true core. Especially if you compare languages like Java and PHP it&#8217;s true that PHP doesn&#8217;t have these kind problems. This is mostly because of the <em>throw-away-the-state</em> nature of PHP. After every served request PHP forgets what it&#8217;s done before and has to completely rebuild the working environment at the next request. Java in contrast is able to remember things between requests. Which makes it more powerful but also harder to maintain (more state, more problems). I&#8217;m really not sure if I&#8217;m buying into this <em>enterprise-thing</em> anymore. Especially if you need scalability you definitely want to keep application state at a minimum and without state you don&#8217;t really need those big interconnected clusters of application servers any more.</p>
<p>Here is a nice talk about scalability and <em>serious</em> (speak enterprise) languages I found recently. It&#8217;s from Cal Henderson a software development guy at <a href="http://www.flickr.com/">Flickr</a>. It&#8217;s really worth watching. Even if you&#8217;re not into Python and Django.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/i6Fr65PFqfk&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/i6Fr65PFqfk&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>(Watch it at: <a href="http://www.youtube.com/watch?v=i6Fr65PFqfk&amp;feature=PlayList&amp;p=D415FAF806EC47A1&amp;index=10">http://www.youtube.com/watch?v=i6Fr65PFqfk&amp;feature=PlayList&amp;p=D415FAF806EC47A1&amp;index=10</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2008/12/04/enterprise-grade-software-is-an-euphemism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
