[ Team LiB ] Previous Section Next Section

19.5 Exercises

Exercise 19-1. Two of the examples in this chapter were designed to parse the web.xml files (introduced in Chapter 20) that configure web applications. The Tomcat servlet container uses a file named tomcat-users.xml to configure its user database. The file shipped by default with Tomcat 5 looks like this:

<?xml version='1.0' encoding='utf-8'?>
  <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"/>

Write a program that uses the SAX API to parse the tomcat-users.xml file and output the values of the username and roles attributes of each <user> tag.

Exercise 19-2. Using a DOM parser instead of a SAX parser, write a program that behaves identically to the program you developed in the previous exercise.

Exercise 19-3. Implement the javax.swing.tree.JTreeModel interface on top of a DOM document tree, so that an XML document can be displayed in a Swing JTree component. Write a demonstration program that does this with sample XML files.

Exercise 19-4. The WebAppConfig program of Example 19-2 provides the beginning of a framework for programmatic manipulation of web.xml configuration files. Extend this example so that it allows servlets, URL mappings, and initialization parameters to be added to, edited, and removed from the file. Provide a command-line or Swing-based interface to your configuration program.

    [ Team LiB ] Previous Section Next Section