ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Building an Open Source J2EE Weblogger

by David Johnson
04/17/2002

As a Java developer, you should be aware of the tremendous wealth of open source development software that is available for your use -- even if you have no desire to release any of your own software as open source. In this article, I will introduce you to some of the most useful open source Java development tools by showing you how I used these tools to develop a complete database-driven Web application called Roller.

Roller fits into the relatively new category of software called webloggers: applications that make it easy for you to maintain a weblog, also known as a blog -- a public diary where you link to recent reading on the Web and comment on items of interest to you.

The Roller Web application allows you to maintain a Web site that consists of a weblog, an organized collection of favorite Web bookmarks, and a collection of favorite news feeds. You can define Web pages to display your weblog, bookmarks, and news feeds. By editing the HTML templates that define these pages, you have almost total control over the layout and appearance of these pages. Most importantly, you can do all of this without leaving the Roller Web application -- no programming is required.

I used over a dozen open source development tools to develop Roller, the most useful of which are listed in Table 1; however, this article focuses on just four tools: the XDoclet code generator, the Castor persistence framework, the Struts Servlet/JSP framework, and the Velocity code-generation engine. In this article I will describe the Roller application, its architecture, and specifically how I used XDoclet, Castor, Struts, and Velocity in its development.

Table 1: Open source tools used in Roller Development

Name

Description

Developer

Type of License*

Castor

Persistence framework

Exolab

Similar to BSD license

HSQL

Small but powerful Java database

Thomas Meuller

Similar to BSD license

Jakarta Ant

XML-driven Java build system

Apache

Apache Public License

Jakarta Commons

Collections, utilities

Apache

Apache Public License

Jakarta Struts

Servlet/JSP framework

Apache

Apache Public License

Jakarta Tomcat

Servlet/JSP Server

Apache

Apache Public License

Jakarta Velocity

Template-driven code generator

Apache

Apache Public License

Netbeans

Integrated Dev. Environment

 

Sun Public License

Xerces

XML parser

Apache

Apache Public License

XDoclet

Code generator

Dreambean

Similar to MIT License

* For more information on open source licenses see opensource.org

The Roller Application

Roller does not support all of the features of commercial weblogging software (such as Userland's Radio or Pyra Labs' Blogger products), but Roller does support what I consider the essential weblogging features. With Roller you can:

  • Maintain a weblog, with user-defined categories. You can write new weblog entries and edit entries that have already been posted. You can define a set of weblog categories and can assign weblog entries to different categories. This allows you to maintain several different weblogs, each covering a different topic.

  • Publish your weblog as an RSS news feed. Roller makes your weblog available as a standard Rich Site Summary (RSS) news feed so that readers can subscribe to and read your weblog without visiting your Roller site.

  • Maintain a collection of favorite bookmarks, organized by bookmark folders. You can define new bookmark folders and can add, delete, and edit the bookmarks within these folders. You can then display these bookmarks on one or more of your Roller site's pages. This allows you to do blogrolling -- displaying links to your favorite weblogs.

  • Maintain a collection of favorite RSS news feeds. This allows you to display headlines with links to news stories from your favorite news sources or weblogs.

  • Define a set of Web pages to display your weblog, bookmarks, and news feeds. Pages are defined using HTML templates with embedded macros for each type of data. For example, there is a $Bookmarks macro that will draw a portion of your bookmark collection on a Web page and a $WeblogCalendar macro that will draw a calendar view of your past weblog entries. These templates allow you almost complete control over the layout and look-and-feel of your Web pages.

There are two types of Roller users: readers and editors. Readers are simply anonymous visitors to the Roller Web site. Editors have user accounts and must log in by providing a user name and password. Editors have the ability to edit their weblog entries, bookmarks, newsfeeds, and page templates.

Figure 1 illustrates the Roller application by showing the Roller Web page navigation tree. The boxes represent Web pages and the arrows represent links between pages. The gray pages are the public pages that any visitor may access, the yellow pages are the login pages, and the red pages are the pages that only editors can access.

Diagram.
Figure 1: Roller Web Pages

Roller Architecture

Internally, Roller is divided into a presentation tier and a business tier, as recommended in Sun's J2EE Pattern Catalog. The presentation tier is responsible for Roller's user interface, and the business tier is responsible for Roller's application logic and the persistence of application data. Figure 2 provides an overview of the Roller architecture.

Diagram.
Figure 2: Roller Architecture

The presentation tier is implemented using the Model-View-Controller (MVC) pattern and the Struts MVC framework. The Model is an abstraction of the application logic and application data and is represented by a set of interfaces defined in the org.roller.model package. The View is implemented using Servlets, JSP pages, and Velocity page templates. The Controller is Struts, which is responsible for receiving incoming requests and dispatching them to the View. The implementation of the presentation tier is further discussed in the sections on Struts and Velocity.

The business tier implements the interfaces in the org.roller.model package, using the Castor JDO persistence framework. The business tier exchanges data with the presentation tier in the form of simple, lightweight JavaBeans known as Value Objects. Value Objects are yet another of the Sun J2EE patterns. Each Value Object maps to a table in the Roller database.

Figure 3 shows the Roller Value Objects, their properties, and the relationships between them. Each editor is represented by a User object. Each User has a Website object, which represents the editor's Web site and which has weblog entries, bookmark folders, newsfeeds, and page templates. The Website object also specifies the default page template of the Web site and which page template is used for rendering a day of weblog entries.

Diagram.
Figure 3: Roller Value Objects


Pages: 1, 2

Next Pagearrow