org.cdlib.xtf.dynaXML
Class DynaXML

Object
  extended by GenericServlet
      extended by HttpServlet
          extended by TextServlet
              extended by DynaXML
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
TestableDynaXML

public class DynaXML
extends TextServlet

Main dynaXML servlet. Processes a URL requesting a document, using the docReqParser stylesheet to parse the request and locate the document. Checks permissions based on the book being accessed and the requestor's IP address or other parameters. Performs optional text querying and search hit marking, and finally transforms the annotated document using a display stylesheet to form the final HTML result page.

See Also:
Serialized Form

Field Summary
(package private)  Authenticator authenticator
          Handles authentication
private  DynaXMLConfig config
          Holds global servlet configuration info
private  DocLocator docLocator
          Locator used to find lazy and non-lazy document files
 
Fields inherited from class TextServlet
stylesheetCache
 
Constructor Summary
DynaXML()
           
 
Method Summary
private  void apply(DocRequest docReq, HttpServletRequest req, HttpServletResponse res)
          Loads the source document, optionally performs a text search on it, and then runs the document formatter to produce the final HTML result page.
protected  boolean authenticate(DocRequest docReq, HttpServletRequest req, HttpServletResponse res)
          Performs user authentication for a request, given the authentication info for the document.
 DocLocator createDocLocator()
          Create a DocLocator.
 void doGet(HttpServletRequest req, HttpServletResponse res)
          Handles the HTTP 'get' method.
private  String getClientIP(HttpServletRequest req)
          Retrieves the IP address of the client who is requesting a page from this servlet.
 TextConfig getConfig()
          Retrieves the current configuration information (that was read in by readConfig()).
 String getConfigName()
          Called by the superclass to find out the name of our specific config file.
 String getServletInfo()
          Informational method required by Servlet interface.
protected  Source getSourceDoc(DocRequest docReq, Transformer transformer)
          Does the work of locating and loading the source document.
protected  TextConfig readConfig(String configPath)
          Reads in the configuration file and sets up our helpers (caching, authentication, etc.)
protected  DocRequest runDocReqParser(HttpServletRequest req, AttribList attribs)
          Creates a document request by running the docReqParser stylesheet and the given attributes.
 void setProfiling(boolean flag)
          Tells the servlet whether to perform stylesheet profiling.
 
Methods inherited from class TextServlet
addParam, addToken, addTokens, buildParamBlock, calcMimeType, convertUTF8inURL, cqlTokenize, createFilteredReceiver, createQueryProcessor, decodeURL, defaultTokenize, destroy, doPost, genErrorPage, getCurRequest, getCurResponse, getCurServlet, getRealPath, getRequestURL, getRequestURL, getText, isEmpty, isSessionTrackingEnabled, makeAttribList, makeHtmlString, makeHtmlString, rawTokenize, readBranding, requireOrElse, restoreWildcards, saveWildcards, service, setErrorGenSheet, setupTrace, stuffAttribs, stuffAttribs, stuffSpecialAttribs
 
Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
 
Methods inherited from class GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

authenticator

Authenticator authenticator
Handles authentication


config

private DynaXMLConfig config
Holds global servlet configuration info


docLocator

private DocLocator docLocator
Locator used to find lazy and non-lazy document files

Constructor Detail

DynaXML

public DynaXML()
Method Detail

getConfigName

public String getConfigName()
Called by the superclass to find out the name of our specific config file.

Specified by:
getConfigName in class TextServlet

readConfig

protected TextConfig readConfig(String configPath)
Reads in the configuration file and sets up our helpers (caching, authentication, etc.)

Specified by:
readConfig in class TextServlet
Parameters:
configPath - Path to the configuration file
Returns:
Parsed config information

getConfig

public TextConfig getConfig()
Retrieves the current configuration information (that was read in by readConfig()).

Specified by:
getConfig in class TextServlet

getClientIP

private String getClientIP(HttpServletRequest req)
Retrieves the IP address of the client who is requesting a page from this servlet. Handles un-reverse-proxying if necessary.

Parameters:
req - The HTTP request being processed
Returns:
The IP address (e.g. 123.22.182.1), or empty string if not able to figure it out.

doGet

public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
           throws IOException
Handles the HTTP 'get' method. Based on the HTTP request, produces an appropriate response.

Specified by:
doGet in class TextServlet
Parameters:
req - The HTTP request
res - The HTTP response
Throws:
IOException - If unable to write the output stream.

runDocReqParser

protected DocRequest runDocReqParser(HttpServletRequest req,
                                     AttribList attribs)
                              throws Exception
Creates a document request by running the docReqParser stylesheet and the given attributes.

Parameters:
req - The original HTTP request
attribs - Attributes to pass to the stylesheet.
Returns:
A parsed document request, or null if before that step
Throws:
Exception

authenticate

protected boolean authenticate(DocRequest docReq,
                               HttpServletRequest req,
                               HttpServletResponse res)
                        throws Exception
Performs user authentication for a request, given the authentication info for the document.

Parameters:
docReq - Info structure containing authentication parameters
req - The request being processed
res - Where to send results if authentication fails
Returns:
true iff authentication succeeds
Throws:
Exception

getServletInfo

public String getServletInfo()
Informational method required by Servlet interface. Doesn't seem to matter what it says.

Specified by:
getServletInfo in interface Servlet
Overrides:
getServletInfo in class GenericServlet
Returns:
A string describing this servlet.

apply

private void apply(DocRequest docReq,
                   HttpServletRequest req,
                   HttpServletResponse res)
            throws Exception
Loads the source document, optionally performs a text search on it, and then runs the document formatter to produce the final HTML result page.

Parameters:
docReq - Document information (stylesheet, source, etc.)
req - The original HTTP request
res - Where to send the HTML response
Throws:
TransformerException - If there's an error in the stylesheet.
IOException - If stylesheet or source can't be read.
Exception

getSourceDoc

protected Source getSourceDoc(DocRequest docReq,
                              Transformer transformer)
                       throws IOException,
                              SAXException,
                              ParserConfigurationException,
                              InvalidDocumentException
Does the work of locating and loading the source document. Handles fetching a file from a URL, lazy file, or a plain XML file on disk. Also fires up a text query if requested.

Parameters:
docReq - Tells which document to load, the query to apply, tec.
transformer - The XSLT transformer that will be used on the document.
Returns:
An XML Source object representing the loaded document.
Throws:
IOException - If a problem is encountered loading a file or URL
SAXException - If the document cannot be parsed as valid XML
ParserConfigurationException - Miscellaneous configuration problems
InvalidDocumentException

createDocLocator

public DocLocator createDocLocator()
Create a DocLocator. Checks the system property "org.cdlib.xtf.DocLocatorClass" to see if there is a user- supplied implementation. If not, a DefaultDocLocator is created.


setProfiling

public void setProfiling(boolean flag)
Tells the servlet whether to perform stylesheet profiling. The profile is (currently) sent to Trace.info().

Parameters:
flag - If true, subsequent XSLT transformations will be profiled.