Java-based CMS
Java-based CMS Overview
This website and others that I own are updated using a content management system (CMS). I have tried several CMS systems including Typo3, Mambo, ez.no and Zope. However, I find OpenCMS to be the most useful for my purposes. OpenCMS is based on the Java programming language. It allows users to publish their own JSP pages and custom templates. It also has a WYSIWYG interface that makes adding graphics very simple.
Server
OpenCMS requires some sort of servlet container. I found that most of the articles describe how to configure OpenCMS on Apache Tomcat. I deciced to use a Virtual Private Server (VPS) to dependably host my websites offsite. My VPS runs Linux and had Apache 1 installed.
Configuration
On the VPS, I downloaded and installed Java, Apache Tomcat and OpenCMS. I found a couple an article that helped configure Tomcat appropriately. I went for the multi-site configuration. I currently host several domains from a single back-end.
Unfortunately, I needed Apache 2, but only Apache 1 was installed on my VPS. After some research, I found that it was possible to have Apache 1 point to an instance of Apache 2. So, I did not need to uninstall the original Apache, but could supplement it with Apache 2 running on a different port. So, I installed the latest Apache on my VPS and edited the configuration files of Apache 1 to point to Apache 2 for domains controlled by OpenCMS.
Template
The templates of OpenCMS are much more complicated than they need to be. There are loads of documentation trying to describe how to build a template from scratch. However, the overall concept is very simple. Just declare the Header, Body and Footer in a JSP file and set all files in a domain to use that JSP file as the template. I usually store a seperate JSP file for each domain in the /template folder of that domain.
Here's a summary of a JSP template file:
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<cms:template element="head">
<%@ page session="false" %>
<%@ page import="java.util.*" %>
<%@ page import="org.opencms.jsp.*" %><%
// Create a JSP action element
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
CmsJspNavBuilder nav=cms.getNavigation();
CmsJspNavElement element=nav.getNavigationForResource();
%>
<html>
...
<%
//Here's how to create a bread crumb trail to the current page...// Get a simple navigation of all pages / subfolders in the root folder
Iterator i = nav.getNavigationBreadCrumb(1,true).iterator();
String folder="/";while (i.hasNext()) {
CmsJspNavElement ne = (CmsJspNavElement)i.next();
out.println("<a xhref=\"" + cms.link(ne.getResourceName()) + "\">"+ne.getNavText() + "</a>/");
}//Show current resource name
if (!nav.getDefaultFile(cms.getCmsObject(),element.getParentFolderName()).endsWith(element.getFileName()))
out.println(element.getNavText());
%>
...
<%
//Here's how to create a vertical navigation menu// Get a simple navigation of all pages / subfolders in the root folder
i = cms.getNavigation().getSiteNavigation("/",0).iterator();while (i.hasNext()) {
org.opencms.jsp.CmsJspNavElement ne = (org.opencms.jsp.CmsJspNavElement)i.next();
out.println("<li><a xhref=\"" + cms.link(ne.getResourceName()) + "\">");
out.println(ne.getTitle() + "</a></li>");
if (element.getParentFolderName().startsWith("/"+ne.getFileName())){
Iterator i2=nav.getNavigationTreeForFolder(element.getParentFolderName(),1,99).iterator();
int currentLevel=0;
while (i2.hasNext()){
CmsJspNavElement e=(CmsJspNavElement)i2.next();
while(currentLevel<e.getNavTreeLevel()){out.println("<ul>");currentLevel++;}
while(currentLevel>e.getNavTreeLevel()){out.println("<ul>");currentLevel--;}
out.println("<li><a xhref=\"" + cms.link(e.getResourceName()) + "\">");
out.println(e.getNavText() + "</a></li>");
}
while(currentLevel>0){out.println("</ul>");currentLevel--;}
}
}
%>
...
</cms:template>
<cms:template element="body">
<cms:include element="text1" />
</cms:template>
<cms:template element="foot">
...
</html>
</cms:template>
There's a section for a bread crumb trail to the current page and also a section to create a navigation menu. The rest of the file is just the HTML used at the top and bottom of every page.
Conclusion
Setting up OpenCMS does take some work, but the advantages of having a Java-based CMS far outweigh non-Java alternatives.