Introduction

Cantina is a content management system for java web applications. It provides a web gui to store content in a database (as many vendors supported as does hibernate) and a tag library to get this content from your JSP web application.

Content is stored in objects called Documents. The important properties of a Document are:

  • its document ID, a unique identifier for the document, chosen by you
  • its content type (like text/html or image/jpeg, see RFC 1341)
  • its contents (text or binary)
Documents can contain translations. A translation is a localized version of the document's content for a particular Locale (see javadoc).

Documents are organized in Realms. Realms are groups of documents and have important properties like:

  • a unique name
  • a fallback locale (when trying to access an unexisting translation of a document, the fallback translation will be used instead)
  • more to come

Users of the systems are the users of the J2EE servlet container you use to run cantina. J2EE authentication model is based on user roles. To be able to edit documents in a Cantina Realm, the user must be in the role that matches the name of the realm.

Installing the Web GUI

In this example, we will install cantina under a tomcat 5.0 servlet container, using a mysql database installed on a unix machine. This procedure has not been tested in a Windows environment. MySQL installation is beyond the scope of this doc.

You will need to download the following:

Expand the four archive in the same directory that we'll call INSTALL_DIR. In a SH terminal, change the current directory to INSTALL_DIR and set up your environment by typing:

export INSTALL_DIR=`pwd`

export JAVA_HOME=path-to-your-jdk

export CATALINA_HOME=$INSTALL_DIR/jakarta-tomcat-5.0.28

alias ant=$INSTALL_DIR/apache-ant-1.6.2/bin/ant

export ANT_HOME=$INSTALL_DIR/apache-ant-1.6.2
    

Install the mysql driver in the tomcat directory:

cp mysql-connector-java-3.0.15-ga/mysql-connector-java-3.0.15-ga-bin.jar jakarta-tomcat-5.0.28/common/lib
    

Setup mysql connection in Tomcat by editing the file jakarta-tomcat-5.0.28/conf/server.xml and adapt the lines marked with a + sign.

      
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
                debug="0"/>

      <!-- Global JNDI resources -->
      <GlobalNamingResources>

+     <Resource name="jdbc/cantinaDS"
+               auth="Container"
+               scope="Shareable"
+               type="javax.sql.DataSource" description="mysql"/>
+     <ResourceParams name="jdbc/cantinaDS">
+       <parameter>
+         <name>factory</name>
+         <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+       </parameter>
+       <parameter>
+         <name>url</name>
+         <value>jdbc:mysql://localhost:3306/cantina?autoReconnect=true</value>
+       </parameter>
+       <parameter>
+         <name>username</name>
+         <value>cantina_user</value>
+       </parameter>
+       <parameter>
+         <name>password</name>
+         <value>cantina_password</value>
+       </parameter>
+       <parameter>
+         <name>maxWait</name>
+         <value>10000</value>
+       </parameter>
+       <parameter>
+         <name>maxActive</name>
+         <value>100</value>
+       </parameter>
+       <parameter>
+         <name>driverClassName</name>
+         <value>org.gjt.mm.mysql.Driver</value>
+       </parameter>
+       <parameter>
+         <name>maxIdle</name>
+         <value>30</value>
+       </parameter>
+     </ResourceParams>

    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>

 
      

Configure the cantina and the demo webapps at the bottom of the file:

      
      <!-- Logger shared by all Contexts related to this virtual host.  By
           default (when using FileLogger), log files are created in the "logs"
           directory relative to $CATALINA_HOME.  If you wish, you can specify
           a different directory with the "directory" attribute.  Specify either a
           relative (to $CATALINA_HOME) or absolute path to the desired
           directory.-->
      <Logger className="org.apache.catalina.logger.FileLogger"
               directory="logs"  prefix="localhost_log." suffix=".txt"
          timestamp="true"/>

+     <Context path="/cantina" docBase="cantina" debug="0" >
+       <ResourceLink name="jdbc/cantinaDS" global="jdbc/cantinaDS" type="javax.sql.DataSource"/>
+     </Context>
    </Host>

  </Engine>
 
    

Now we will create the cantina web application. We need to init your mysql database, by creating the necessary tables. Cantina uses Hibernate to manage persistence. Hibernate can create the SQL tables and you can take advantage of that feature by editing the file: webgui/WEB-INF/classes/hibernate.properties and uncommenting the line (removing the # sign):

hibernate.hbm2ddl.auto=create
    

Change directory to $INSTALL_DIR/cantina-0.5 to build the WAR archive:

cd $INSTALL_DIR/cantina-0.5
ant
    

The result is a cantina.war archive, to be copied in the tomcat webapps directory

cp cantina.war $INSTALL_DIR/jakarta-tomcat-5.0.28/webapps/
    

Create a new user for tomcat by editing the file $INSTALL_DIR/jakarta-tomcat-5.0.28/conf/tomcat-users.xml

      
  <?xml version='1.0' encoding='utf-8'?>
  <tomcat-users>
    <role rolename="tomcat"/>
    <role rolename="role1"/>
    <user username="tomcat" password="tomcat" roles="tomcat"/>
    <user username="both" password="tomcat" roles="tomcat,role1"/>
    <user username="role1" password="tomcat" roles="role1"/>
+   <user username="cantinaAdmin" password="secret" roles="cantina,cantinaAdmin,manager,cantinaDemo"/>
  </tomcat-users>
 
    

Start tomcat:

sh $INSTALL_DIR/jakarta-tomcat-5.0.28/bin/startup.sh
    

Hit http://localhost:8080/cantina, and log in as cantinaAdmin (pass: secret). You should see the homepage of cantina. Because the web GUI to create groups of documents is not created yet, issue the following statement in your (now initialized) MySQL database:

insert into realms(`realm_name`) values ('cantinaDemo');
    

To avoid initializing the mysql database on the next run, re-comment the "auto=create"line in $INSTALL_DIR/cantina-0.5/webgui/WEB-INF/classes/hibernate.properties

hibernate.connection.driver_class=org.gjt.mm.mysql.Driver
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.datasource=java:comp/env/jdbc/cantinaDS
#hibernate.hbm2ddl.auto=create
    

Rerun ant and copy the new cantina.war in $INSTALL_DIR/jakarta-tomcat-5.0.28/webapps

cd $INSTALL_DIR/cantina-0.5
ant
cp cantina.war $INSTALL_DIR/jakarta-tomcat-5.0.28/webapps
    

Tomcat should automatically reload the web application (there is a bug in tomcat 5.0.28 related to JNDI datasources so better restart tomcat). Hit http://localhost:8080/cantina again

sh $INSTALL_DIR/jakarta-tomcat-5.0.28/bin/shutdown.sh
sh $INSTALL_DIR/jakarta-tomcat-5.0.28/bin/startup.sh
    

Using

In this section, we create content using the Web GUI and display it in a demo web application.

On the cantina homepage at http://localhost:8080/cantina

  • Fill the Create Document form, naming it sampleDocument, choosing the realm cantinaDemo we created earlier in MySQL, and a content type of text/html. Hit the Go button.
  • You are now taken on the document's Detail Page stating its realm and content type. You also see that it doesn't have any translations.
  • In the Add a translation form, choose the English locale and hit the Go button. If this locale doesn't appear in the list, it is not installed on your system. Choose another one).
  • You are now taken to the edition form. Fill some content and hit Save.

Now that we have content stored, let's display it. We need to create a demo web application.

cd $INSTALL_DIR
mkdir jakarta-tomcat-5.0.28/webapps/demo
cp -r cantina-0.5/webgui/WEB-INF jakarta-tomcat-5.0.28/webapps/demo/WEB-INF
      

Edit $INSTALL_DIR/jakarta-tomcat-5.0.28/conf/server.xml and add the following lines:

      
      <Logger className="org.apache.catalina.logger.FileLogger"
               directory="logs"  prefix="localhost_log." suffix=".txt"
          timestamp="true"/>

+     <Context path="/demo" docBase="demo" debug="0" >
+       <ResourceLink name="jdbc/cantinaDS" global="jdbc/cantinaDS" type="javax.sql.DataSource"/>
+     </Context>
      <Context path="/cantina" docBase="cantina" debug="0" >
      
    

Create a new JSP file $INSTALL_DIR/jakarta-tomcat-5.0.28/webapps/demo/index.jsp with the following content:

    
<%@ taglib uri="/WEB-INF/tld/cantina.tld" prefix="document" %>
<html>
<document:write documentId="sampleDocument" locale="en"/>
</html>

    

restart tomcat and hit http://localhost:8080/demo you will see the content you input in the web GUI. If you do not see the content and chose another locale in the web GUI, adapt the locale parameter (see javadoc of java.util.Locale for the token syntax).

Incoming Features

Coming very soon:

  • Web GUI for realm administration
  • Storage of binary data (images) and servlet to serve them
  • A way to delete documents