Overall Process
Prototyping the XML
Making the XML Dynamic
Servlet Implementation
Finishing Touches
Up until now, the examples in this book have been short and to the point. The goal of this chapter is to show how a much more sophisticated web application is designed and implemented from the ground up. This is the culmination of everything covered so far, combining XML, servlets, XSLT, JDBC, JAXP, and JDOM into a fully functioning web-based discussion forum. As with the other examples in this book, the full source code is available from the companion web site.
Walking the line between "textbook quality" and "real-world" examples is difficult. First and foremost, the goal of this chapter is to demonstrate how to design and implement a nontrivial web application using XSLT and Java. The second goal is to produce a decent application that can actually be used in the real world. Hopefully this has been achieved. Although making an example of this size fit into a single chapter involves a few tradeoffs, the design is flexible enough to allow new features, such as user authentication, to be implemented without too much additional effort.
The discussion forum requires the following Java packages:
Java 2 Standard Edition v1.2 or later
JDOM beta 6
Any JAXP 1.1 compatible XML parser and XSLT processor
Any servlet container that supports Version 2.2 or later of the servlet specification
Either MySQL or Microsoft Access
Developing a web application using Java and XSLT can be broken down into several key steps. As in any software development project, a modular approach that can be dispatched to several developers simultaneously is highly desirable. This speeds the overall process and allows developers of different skill levels to participate.
Our process consists of the following high-level steps:
Define the requirements.
Create prototype XHTML web pages.
Create prototype XML datafiles.
Create XSLT stylesheets.
Design and implement the Java domain classes.
Design and implement the database and related code.
Create "XML producer" objects.
Implement the servlets and related code.
Although the list shown here approximates the order in which these steps will be performed, in larger applications it is typical to implement a vertical slice of the system first. This slice will implement one or two key screens and will require the development team to follow all of the previous steps. As more screens are added to the system, the process is followed again for each piece of functionality that is added. This is very typical of most lightweight software development processes in which the system is developed in iterative steps rather than trying to implement the entire system in one pass.
The remainder of this chapter will present the implementation of the discussion forum. The requirements, design, and code will be presented in roughly the same order as the list shown in this section.
An online discussion forum will be developed using Java and XSLT. For the reference implementation, all features will be accessible via a web browser using XHTML, and no client-side Java or JavaScript will be required. The target for deployment is a web-hosting provider that supports Java 2, servlet 2.2, and access to a relational database such as MySQL. It is assumed that any additional Java JAR files, such as those required for JAXP and JDOM, can be installed along with the web application.
The discussion forum will be divided into message boards, each of which covers a different topic such as "Dog Lovers" or "Cat Lovers." Each message belongs to one of these boards and may be a response to a previous message. This is known as a threaded discussion forum. Each message will also contain a subject, create date, author email, and the actual message text.
When visiting the web site, users can read existing messages, post new messages, or reply to existing messages. Only administrators can create new message boards. Although XHTML is specified for the reference implementation, every effort will be made to facilitate alternatives, such as XHTML Basic or WML. Other than practical limitations such as bandwidth and database capacity, no artificial constraints shall be placed on the number of boards or messages.
A few features will be omitted to keep this example reasonably sized. These include a web-based administrative interface, user authentication and security, and the ability to search the archive. Suggestions for implementing these features are mentioned at the end of this chapter.
The forum user interface consists of four primary screens, as shown in Figure 7-1. Each box represents a different web page that visitors encounter, and lines indicate screen-to-screen flow as the user clicks on links.
Creating a graphical layout of the web pages as shown here is sometimes called storyboarding, a common user interface design technique that has its roots in the animation, television, and motion picture industries. Such high-level diagrams typically start as hand-drawn sketches on paper, with the intent of capturing the overall application flow. This is a good place to start because it shows how everything fits together without delving too deeply into technical design details.
The "Discussion Forum Home" page is the starting point and displays the list of all message boards. For each message board, a list of months with messages is displayed. From this screen, the user can either click on a month to view a list of message subjects, or click on a link to post a new message. The user can always return to the home page from any other page in the application.
The "View Month" page shows message subjects for a particular month in a given board. These messages are displayed in a tree that shows the message subject, author, and create date. The structure of the tree represents threads of discussion, with replies indented underneath the original messages. From this page, the user can either select a message to view or click on a link to visit the "Post New Message" page.
The "View Message" screen shows details for an individual message. From this page, visitors can either return to the month view or click on a link to reply to this message.
The final page allows users to either post a new message or reply to an existing message. Since posting and replying are quite similar, much of the Java and XSLT stylesheet code is reused. Although using the same code for multiple web pages reduces the size of the application, it can add complexity because the code must be capable of two modes of operation.
Copyright © 2002 O'Reilly & Associates. All rights reserved.