Project 4

cscie259.project4.scamazon
Class Receipt

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bycscie259.project4.scamazon.ScamazonServlet
              extended bycscie259.project4.scamazon.Receipt
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class Receipt
extends ScamazonServlet

This servlet produces Scamazon.com's receipts as PDFs.

Any references to the local file system in the servlet's context are resolved with respect to project4-6.0/webapps/scamazon/.

Based on version 1.1.2.1 of Apache's FopServlet.java, per the below copyright notice; original source from FOP 0.20.5rc2's distribution.

$Id: FopServlet.java,v 1.1.2.1 2003/01/13 16:27:14 jeremias Exp $ Copyright (C) 2001 The Apache Software Foundation. All rights reserved. For details on use and redistribution please refer to the LICENSE file included with these sources.

Given an XSL-FO file or, alternatively, XML and XSLT which together yield XSL-FO, produces PDF, which is returned directly to the browser.

Current usage:

   http://$HOSTNAME.fas.harvard.edu:n/scamazon/servlet/receipt?fo=foo.fo&ext=.pdf
   http://$HOSTNAME.fas.harvard.edu:n/scamazon/servlet/receipt?xml=foo.xml&xsl=foo.xsl&ext=.pdf
 
Per http://xml.apache.org/fop/embedding.html, "Some browsers have problems handling the PDF result sent back to the browser. IE is particularly bad and different versions behave differently. Having a '.pdf' on the end of the URL may help."

Hence our inclusion of the unused "ext" parameter in the current usage.

You MAY modify this file.

Version:
6.0
Author:
The Apache Software Foundation, Computer Science E-259, YOUR NAME GOES HERE
See Also:
Serialized Form

Nested Class Summary
private  class Receipt.myURIResolver
          Resolves references to files.
 
Nested classes inherited from class cscie259.project4.scamazon.ScamazonServlet
ScamazonServlet.AnErrorListener
 
Field Summary
static java.lang.String FO_REQUEST_PARAM
          HTTP parameter referencing an XSL-FO file
private  org.apache.avalon.framework.logger.Logger log
           
static java.lang.String XML_REQUEST_PARAM
          HTTP parameter referencing an XML file
static java.lang.String XSLT_REQUEST_PARAM
          HTTP parameter referencing an XSLT file
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Fields inherited from class javax.servlet.GenericServlet
 
Constructor Summary
Receipt()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Responds to GETs in the same manner as POSTs.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Respond to POSTs in the same manner as GETs.
 void doWork(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles operations involving receipts.
 void processXSL(java.lang.String xml, java.lang.String xsl, javax.servlet.http.HttpServletResponse response)
          Renders an XML file into a PDF file by applying a stylesheet that converts the XML to XSL-FO.
 void renderFO(org.xml.sax.InputSource foFile, javax.servlet.http.HttpServletResponse response)
          Renders an FO input source into a PDF file which is written directly to the response object's OutputStream.
 
Methods inherited from class cscie259.project4.scamazon.ScamazonServlet
forward, redirect
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FO_REQUEST_PARAM

public static final java.lang.String FO_REQUEST_PARAM
HTTP parameter referencing an XSL-FO file

See Also:
Constant Field Values

log

private org.apache.avalon.framework.logger.Logger log

XML_REQUEST_PARAM

public static final java.lang.String XML_REQUEST_PARAM
HTTP parameter referencing an XML file

See Also:
Constant Field Values

XSLT_REQUEST_PARAM

public static final java.lang.String XSLT_REQUEST_PARAM
HTTP parameter referencing an XSLT file

See Also:
Constant Field Values
Constructor Detail

Receipt

public Receipt()
Method Detail

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException,
                  javax.servlet.ServletException
Responds to GETs in the same manner as POSTs.

Overrides:
doGet in class ScamazonServlet
Parameters:
request - HTTP request object
response - HTTP response object
Throws:
java.io.IOException - if an IO-related error occurs
javax.servlet.ServletException - if a servlet-related error occurs

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException,
                   javax.servlet.ServletException
Respond to POSTs in the same manner as GETs.

Overrides:
doPost in class ScamazonServlet
Parameters:
request - HTTP request object
response - HTTP response object
Throws:
java.io.IOException - if an IO-related error occurs
javax.servlet.ServletException - if a servlet-related error occurs

doWork

public void doWork(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException
Handles operations involving receipts.

Specified by:
doWork in class ScamazonServlet
Parameters:
request - HTTP request object
response - HTTP response object
Throws:
javax.servlet.ServletException - if a servlet-related error occurs

processXSL

public void processXSL(java.lang.String xml,
                       java.lang.String xsl,
                       javax.servlet.http.HttpServletResponse response)
                throws javax.servlet.ServletException
Renders an XML file into a PDF file by applying a stylesheet that converts the XML to XSL-FO. The PDF is written directly to the response object's OutputStream.

Parameters:
xml - name of XML input file
xsl - name of XSLT input file
response - HTTP response object
Throws:
javax.servlet.ServletException - if a servlet-related error occurs

renderFO

public void renderFO(org.xml.sax.InputSource foFile,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException
Renders an FO input source into a PDF file which is written directly to the response object's OutputStream.

Parameters:
foFile - XSL-FO file
response - HTTP response object
Throws:
javax.servlet.ServletException - if a servlet-related error occurs

Project 4