Book Image

Building Websites with OpenCms

Book Image

Building Websites with OpenCms

Overview of this book

This book takes you through the process of creating content-rich websites and applications using OpenCms. Although powerful and flexible, OpenCms can be daunting on first approach, but its advanced features reward the investment in learning. This book exists to ease Java developers into getting the most from OpenCms. OpenCms OpenCms is a professional-level, open source Website Content Management System, with which you can create and manage complex websites. Based on Java and XML technology, it fits into almost any modern IT environment. With hard-won experience of the practical difficulties faced by developers working with OpenCms, this book is the embodiment of the author's expertise, and the perfect way to master the system.
Table of Contents (12 chapters)
Building Websites with OpenCms
Credits
About the Author
Introduction

Technical Overview


OpenCms is written in Java. It makes use of industry-standard XML (eXtensible Markup Language), and uses Java DataBase Connectivity (JDBC) to store data in a relational database. Built in Java, OpenCms can run on different platforms, including numerous versions of UNIX and Linux, and Windows.

Hardware-wise, OpenCms is designed for scalability. It will run on hardware ranging from small laptops (I've run it on a Pentium III 733 Toshiba Tecra laptop with 256 MB RAM and Red Hat 8) to a distributed collection of servers.

Being a web-based application, OpenCms runs as a Java servlet inside a servlet container such as Apache Tomcat or BEA WebLogic. For data storage, it can use a number of SQL databases, including MySQL, Microsoft SQL Server, and Oracle.

At one time, OpenCms required developers to learn a proprietary XML schema for developing templates, but in version 5.0, OpenCms has changed direction and now uses Java Server Pages; we'll get into the details of the system later. Here is a brief summary of how each of these components works (and how they all work together).

The Web Server and Java Servlets

The web server handles incoming connections. As it sees connections intended for OpenCms, it hands them off to the servlet container for processing. The servlet container manages one or more Java servlets. Unlike a CGI script, which runs only for the amount of time it takes to process a single request, a servlet stays running until the server explicitly stops it (which usually only happens when the server shuts down). The job of the servlet container is to provide the runtime environment for the servlets.

While it is possible to run OpenCms on the command line, it is almost always run as a servlet.

The Database

OpenCms uses a database for persistent data storage. Information about file types, templates, and publishing is stored in the database, as is all the content. OpenCms supports a couple of major SQL-based databases, including MySQL, Microsoft SQL Server, and Oracle. Developers are working on ports to PostgreSQL and other databases.

OpenCms uses JDBC to connect the Servlet to the database during startup. Content is managed inside the database, though it can be exported from the database into static files during a publishing cycle.

Pages, Templates, and Java Server Pages

Content is stored in the database in the form of XML files. Layout information and processing code is also stored in the database, but not in the same XML document as the content. When a page is requested, the content is pulled out of the database and put into a template. Any special processing needed is run, and the results are sent back to the requester (usually a web browser) in the form of a complete HTML file.

Templates and custom code are written in two languages: XML Template, a simple XML-based language developed by the OpenCms team, and Java Server Pages, a standardized language for embedding Java processing instructions inside of an HTML or XML document. While XML Template is still used in OpenCms 5, it will be phased out and replaced by the more flexible and mature JSP technology in future releases.

Bringing it Together

Each of these pieces functions together for each request. A typical response to a document (we'll call it test.html) might look like this:

  1. 1. The web browser requests test.html.

  2. 2. The web server recognizes that the request must be handled by OpenCms; it passes it off to the OpenCms Servlet request handler.

  3. 3. OpenCms retrieves information about test.html (including the content) from the database.

  4. 4. OpenCms puts the content for test.html into its template, adding all of the necessary layout elements and interpreting any JSP or XML template code that it needs for fulfilling the request.

  5. 5. Once OpenCms has created the complete HTML document, the document is returned to the browser.

  6. 6. The web browser interprets the HTML, runs any JavaScript that it finds, and displays the test.html page.