B2B with XML
Fulfillment System Uses XML and XSLT
August 2000 |
 |
The Fulfillment System (FS) module is a servlet
that parses XML documents sent by the HRS to notify the hotel staff (for example,
a manager or desk clerk) about confirmed room reservations. Here is the sequence
of events:
- A customer reserves a hotel room.
- The HRS generates an XML document to store the reservation data.
- The HRS sends the XML document to the FS. (A production app would send the
document via FTP; this sample just writes it to the file system using a predefined
path.)
- The FS applies an XSLT transformation to convert the XML to HTML, then displays
it to the desk clerk at the hotel.
The servlet
spec requires every servlet to implement a service method that
executes in reponse to client requests. The following code from xmla2a.hrs.HRSServlet.service
shows how the HRS builds an XML document and writes it to a file.
This method uses classes created by the Oracle XML Class Generator for Java. Working with the XML Parser for Java, the
Class Generator produces a set of Java source files based on an input
DTD. You can then use the source files to construct, validate, and print
an XML document that complies with the specified DTD. For example, the Class
Generator used the DTD file Booking_FS.dtd to produce
the class Booking_FS, instantiated in the example code below.
...
// Example: output file name for user ID 30 is 30.xml
String l_fileName = ConnectionParams.s_pathOfFile +
"xmlfiles/" + m_userIDForCommunication + ".xml";
File l_xmlFile = new File(l_fileName);
FileOutputStream l_fStream = new FileOutputStream(l_xmlFile);
// Forming XML Document for Local Hotels (l_localHotels is a Vector).
/* The following code executes earlier in the method to init the Vector. l_localHotels.addElement(new Integer(l_hotelId).toString()); l_localHotels.addElement(new String("Reservation")); l_localHotels.addElement(l_resvDetails.m_arrDate); l_localHotels.addElement(new Integer(l_resvDetails.m_numNights)); l_localHotels.addElement(new Integer(l_resvDetails.m_numRooms)); l_localHotels.addElement(l_resvDetails.m_roomType); l_localHotels.addElement(l_resvDetails.m_currency); l_localHotels.addElement(l_userName); l_localHotels.addElement(l_discountRate); l_localHotels.addElement(" ");
*/
for (int p_i = 0; p_i < l_localHotels.size(); p_i += 10){
Booking_FS l_booking = new Booking_FS();
Hotel_Id l_hotelId1 =
new Hotel_Id(new Integer(l_localHotels.elementAt(p_i).toString()).toString());
Arrival_Date l_arrivalDate =
new Arrival_Date((String)l_localHotels.elementAt(p_i+2));
No_Of_Nights l_noOfNights =
new No_Of_Nights(new Integer(l_localHotels.elementAt(p_i+3).toString()).toString());
No_Of_Rooms l_noOfRooms =
new No_Of_Rooms(new Integer(l_localHotels.elementAt(p_i+4).toString()).toString());
Room_Type l_roomType =
new Room_Type((String)l_localHotels.elementAt(p_i+5));
Currency l_currency =
new Currency((String)l_localHotels.elementAt(p_i+6));
Discount_Rate l_disRate =
new Discount_Rate((String)l_localHotels.elementAt(p_i+8));
// Add data as tree nodes to l_booking.
l_booking.addNode(l_hotelId1);
l_booking.addNode(l_arrivalDate);
l_booking.addNode(l_noOfNights);
l_booking.addNode(l_noOfRooms);
l_booking.addNode(l_roomType);
l_booking.addNode(l_currency);
l_booking.addNode(l_disRate);
l_bookingList.addNode(l_booking);
}
l_bd1.addNode(l_bookingList);
l_bd1.validateContent();
...
// Write the XML to a file.
l_bd1.print(l_fStream);
m_localHotelData=new String();
m_localHotelData=l_fStream.toString();
l_fStream.close();
...
|
The following code from xmla2a.fs.FulfillmentSystemServlet.service
shows how the FS parses an XML file and converts the results to HTML (by applying
an XSL stylesheet) to display in the customer's browser.
...
public final String m_pathOfFile =
"C:\\Program Files\\Oracle\\JDeveloper 3.0\\public_html\\a2afiles\\";
...
public void service(HttpServletRequest p_request, HttpServletResponse p_response) throws ServletException, IOException {
...
if(l_reqType == null ){
File l_file = new File(m_pathOfFile + "xmlfiles");
m_fileName = l_file.list();
...
// create a XML document with the file
XMLDocument l_userDoc = null;
l_pathOfFile = m_pathOfFile + "xmlfiles\\" +
(String)m_fileNames.elementAt(0);
l_userDoc = XMLHandler.parseXMLDocument(l_pathOfFile);
...
// Transform XML to HTML using confirmation.xsl
String l_htmlPage = XMLHandler.TransformXMLToHTML(l_userDoc,
m_pathOfFile + "xslfiles/" + "confirmation.xsl");
m_fileNames.removeElementAt(0);
l_out.println(l_htmlPage); // Display the HTML output in the browser.
l_out.close();
}
...
}
|
Questions or comments? Post a message in OTN's Sample Code discussion
forum or send email to the author.
B2B with XML: Fulfillment System
Author: Robert Hall, Oracle
Corporation
Date: August 2000
This document is provided for information purposes only and
the information herein is subject to change without notice. Please report any
errors herein to Oracle Corporation. Oracle Corporation does not provide any
warranties covering and specifically disclaims any liability in connection with
this document.
Oracle is a registered trademark and Enabling the Information
Age is a trademark or registered trademark of Oracle Corporation. All other
company and product names mentioned are used for identification purposes only
and may be trademarks of their respective owners.
Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.
Worldwide Inquiries:
+1.650.506.7200
Copyright © Oracle Corporation 2000
All Rights Reserved
|