|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
XML Protocols Using FOP for Industrial Needs
Using FOP for Industrial Needs
By: Rajesh Zade
Sep. 27, 2002 12:00 AM
The Web has given us an easy-to-use, easy-to-market, and easy-to-navigate medium for conducting business. We've come to a stage where mainstream people are comfortable shopping on the Web. What it lacks is the ability to ensure that what the end user has browsed or accepted is the same as what was processed on the back end. In other words, how do you make sure the confirmation of a transaction is the same as the transaction itself? This article discusses how XML and Formatting Objects Processor (FOP) technology can be used to address this problem. The FOP initiative is a part of the Apache organization and is a subproject of the XML project ( http://xml.apache.org/fop/index.html). It is a Java application that enables rendering of XML input data to various output formats such as PDF, PCL, SVG, XML, Print, AWT, TXT, and RTF (not yet supported). Among these formats, PDF is the most popular option. The latest version of FOP supports the XSL-FO version 1.0 W3C recommendation ( www.w3.org/TR/2001/REC-xsl-20011015/). FOP is a Java rendering engine invoked at runtime that applies an XSL-FO stylesheet to XML data and produces an output format based on properties that the runtime engine was initialized with. For example, you can fetch data from the database, represent it in XML format, and then apply an XSL-FO stylesheet to generate a PDF report. This process executes within the server tier. The resulting PDF stream can be presented to the end user in the same way that a PDF document can be set up for download from the Web.
Why XML and FOP?
It makes perfect sense to follow this approach until you capture data and navigate from page to page, but not after the input data has been processed and you're ready to show the results. The main flaw with rendering end results in HTML format is that the result page is easily editable. For example, you can get a final receipt from Amazon.com for a purchase in HTML, save it on a local machine, and then edit it to look like a completely different purchase. Or you can get an insurance quote for a car, change its premium by editing the HTML, print it, and fax it back to the company to claim lower premiums. You probably don't stand a chance of actually grabbing that phony deal, but just imagine how much time a sales representative would have to spend to disprove it! The solution to this problem is that whenever you want to present to a customer what he or she is going to pay - a final receipt or a quote - you probably want to present it in a noneditable form close to the printed receipt you get at the checkout counter, something like a receipt presented as a PDF document. Therefore, it would be more accurate to show a final receipt within a browser as a PDF page instead of an HTML page. You can advise your customer to print that receipt as a proof of purchase. Another advantage of using XML and FOP: if FOP solves your problem at the client tier, then XML solves it at the server tier. The XSL-FO stylesheet is applied to XML data, and XML data at that instance depends on many parameters a customer must have chosen to finally select that product. For example, a customer may get some discounts that may be applicable for that purchase. Another example: when highly configurable products, such as PCs, are sold on the Web, they vary from customer to customer. Granted, you have information about all the parts in your database, but you don't have information about a particular configuration. That configuration is already represented in the XML data. When the customer actually clicks that final buy button and the response is sent back to the server, your systems can easily work from XML data for that purchase instead of going all the way back to the database. The main idea here is to make the final proof of purchase noneditable and also keep it in sync with the back-end processes. It makes the hard copy and the electronic copy virtually the same.
Putting it to real use
Case Study: Insurance Quote Processing
Figure 1 shows the QuoteSessionBean that's responsible for collecting user-specific data to generate the quote in XML form. The QuoteSessionBean can interact with various business objects or get data straight from the database to generate the XML file (code not provided). Once the XML file is ready, something like a Reporter object that wraps the FOP calls can apply the XSL-FO stylesheet to the XML data and stream an auto policy quote as a PDF report to the user. Once the user accepts the quote and clicks the submit button, the application-tier object, such as QuoteProcessor, can work from the Quote XML file to finalize the quote.
Quote in XML form
XSL-FO stylesheet
In Listing 2 the FOP root section has the simple definition and flow of a PDF document with a title and three sections, one each for Customer, Coverage, and Summary. Following this definition there are matching templates for Customer, Address, Contact, Coverage, Options, and Summary tags. Note: The code in Listing 2 illustrates only FOP-specific items. See the "Resources" section at the end of this article for directions on obtaining the full stylesheet.
Generating dynamic PDF reports
Say you have a flag called "showdiscount" defined in discount.xml as:
<discounts> and a variable displayControl defined in stylesheet as: <xsl:variable name="displayControl" select="document(discount.xml')"/> You can have the following statement around any <fo> block to control the display of that block only to your preferred customers: <xsl:if test="$displayControl@showdiscount = 'true'"> <fo:block> Preferred Customer Discount Details </fo:block> </xsl:if>
PDF Output
<<install_dir>>\fop-0.20.3> You can also invoke the FOP rendering engine from within any Java application or any application server (see Figure 2).
Back-end processing components
Conclusion
This results in significant cost savings for businesses and reduces processing overheads within the applications.
Resources
Reader Feedback: Page 1 of 1
Your Feedback
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||