Tuesday, November 3, 2009

Point 2: Creating a JSP Application to Process and Transform XML Documents Using JAXP












Point 2: Creating a JSP Application to Process and Transform XML Documents Using JAXP



The Java API for XML Processing (JAXP) allows you to parse and transform eXtensible Markup Language (XML) documents from JavaServer Pages (JSP) applications. JAXP provides implementation of the Document Object Model
(DOM) and Simple API for XML (SAX) for parsing XML documents. DOM parses and creates an object tree of an XML document. The object tree contains nodes that represent elements of the XML document. JAXP allows you to work with the nodes of the object tree and transform the object tree back to the XML document from JSP applications.


This chapter describes how to create an online music store application that saves data in XML documents. The JSP
pages of the application provide user interfaces and contain the logic to parse and transform XML documents.




Requirements of the Online Music Store Application


The online music store application allows an administrator to add or delete user login information. The administrator can also add or delete information about music and video albums from the XML documents. Application data, such as user information, album information, and album purchase information are stored in XML files. The JSP pages of the online music store application use the classes and interfaces of JAXP to read and write to the XML files. The XML files that store the application data are:




  • userlist.xml: Stores information about end users, such as user name, password, and role. An end user can have a user or administrator role.




  • musicalbumlist.xml: Stores information about music albums available in the music store.




  • videoalbumlist.xml: Stores information about video albums available in the music store.




  • musicpurchaselist.xml: Stores purchase information about music albums.




  • videopurchaselist: Stores purchase information about video albums.




The JSP pages of the application provide user interfaces that allow end users with user role to buy music albums and those with administrator role to add or delete album information. The JSP files of the online music store application are:




  • Logon.jsp: Displays text and password fields to obtain end user information.




  • DoLogon.jsp: Authenticates an end user and displays user interfaces that correspond to the end user role.




  • DoLogout.jsp: Invalidates the current session and forwards control to the Logon JSP page.




  • AdministratorPage.jsp: Displays hyperlinks to the other user interfaces of the application.




  • AddUser.jsp: Displays the fields to accept information about a new end user and records this information in the userlist.xml file.




  • AddMusicAlbum.jsp: Displays the fields to accept information about a new music album and records this information in the musicalbumlist.xml file.




  • AddVideoAlbum.jsp: Displays the fields to accept information about a new video album and records this information in the videolbumlist.xml file.




  • DeleteUser.jsp: Allows the administrator to remove information about an end user from the userlist.xml file.




  • DeleteMusicAlbum.jsp: Allows the administrator to remove information about a music album from the musicalbumlist.xml file.




  • DeleteVideoAlbum.jsp: Allows the administrator to remove information about a video album from the videoalbumlist.xml file.




  • PurchaseAlbum.jsp: Displays the user interface through which an end user can purchase music or video albums. The PurchaseAlbum.jsp page records purchase information in the musicpurchaselist.xml and videopurchaselist.xml files.





Figure 2-1 shows the architecture of the online music store application:






Figure 2-1: Architecture of the Online Music Store Application










No comments:

Post a Comment