org.cdlib.xtf.dynaXML.test
Class TestableDynaXML

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

public class TestableDynaXML
extends DynaXML

Extends the DynaXML servlet to allow switching between two different representations of the same document, to allow verification that the output is the same for both of them. One version will be the SearchTree, the other is annotated using TreeAnnotater. Any exceptions will be thrown upward rather than generating an error page.

Author:
Martin Haye
See Also:
Serialized Form

Field Summary
private  boolean dump
           
private  String prevAnnotatedPath
           
private  DocumentInfo prevAnnotatedTree
           
private  String searchTerm
           
private  boolean useAnnotated
           
 
Fields inherited from class DynaXML
forceLazy
 
Fields inherited from class TextServlet
stylesheetCache
 
Constructor Summary
TestableDynaXML()
           
 
Method Summary
protected  boolean authenticate(DocRequest docReq, HttpServletRequest req, HttpServletResponse res)
          Performs user authentication for a request, given the authentication info for the document.
static void dumpTree(String fileName, Source tree)
          Writes out a source tree, removing things like score and rank that can reasonably vary between the annotated and SearchTree versions of a document.
protected  void genErrorPage(HttpServletRequest req, HttpServletResponse res, Exception exc)
          Generate an error page based on the given exception.
 DocumentInfo getAnnotatedTree(String sourcePath)
          Get a version of the source tree with hits marked in context by a stupid but reliable annotater.
protected  Source getSourceDoc(DocRequest docReq, Transformer transformer)
          Does the work of locating and loading the source document.
 void setDump(boolean flag)
          Establishes whether to dump the tree on each iteration
 void setSearchTerm(String term)
          Sets the term to use in text searches
 void useAnnotated(boolean flag)
          Tells whether to use the annotated version or the SearchTree version.
 
Methods inherited from class DynaXML
createDocLocator, doGet, getConfig, getConfigName, getServletInfo, readConfig, runDocReqParser, setProfiling
 
Methods inherited from class TextServlet
addParam, addToken, addTokens, buildParamBlock, calcMimeType, convertUTF8inURL, cqlTokenize, createFilteredReceiver, createQueryProcessor, decodeURL, defaultTokenize, doPost, getCurRequest, getCurResponse, getCurServlet, getRealPath, getRequestURL, getText, isEmpty, isSessionTrackingEnabled, makeAttribList, makeHtmlString, makeHtmlString, rawTokenize, readBranding, requireOrElse, restoreWildcards, saveWildcards, service, setErrorGenSheet, stuffAttribs, stuffAttribs, stuffSpecialAttribs
 
Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
 
Methods inherited from class GenericServlet
destroy, 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

useAnnotated

private boolean useAnnotated

dump

private boolean dump

prevAnnotatedPath

private String prevAnnotatedPath

prevAnnotatedTree

private DocumentInfo prevAnnotatedTree

searchTerm

private String searchTerm
Constructor Detail

TestableDynaXML

public TestableDynaXML()
Method Detail

useAnnotated

public void useAnnotated(boolean flag)
Tells whether to use the annotated version or the SearchTree version.

Parameters:
flag - frue for annotated, false for SearchTree

setSearchTerm

public void setSearchTerm(String term)
Sets the term to use in text searches


getAnnotatedTree

public DocumentInfo getAnnotatedTree(String sourcePath)
                              throws IOException,
                                     SAXException,
                                     ParserConfigurationException,
                                     TransformerException
Get a version of the source tree with hits marked in context by a stupid but reliable annotater.

Parameters:
sourcePath - Path to the document
Returns:
Root of the annotated document
Throws:
IOException
SAXException
ParserConfigurationException
TransformerException

dumpTree

public static void dumpTree(String fileName,
                            Source tree)
Writes out a source tree, removing things like score and rank that can reasonably vary between the annotated and SearchTree versions of a document.

Parameters:
fileName - File to write to
tree - The document to dump

setDump

public void setDump(boolean flag)
Establishes whether to dump the tree on each iteration


getSourceDoc

protected Source getSourceDoc(DocRequest docReq,
                              Transformer transformer)
                       throws IOException,
                              SAXException,
                              ParserConfigurationException
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.

Overrides:
getSourceDoc in class DynaXML
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

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. In the case of testing, we never fail authentication.

Overrides:
authenticate in class DynaXML
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

genErrorPage

protected void genErrorPage(HttpServletRequest req,
                            HttpServletResponse res,
                            Exception exc)
Generate an error page based on the given exception. Utilizes the system error stylesheet to produce a nicely formatted HTML page.

Overrides:
genErrorPage in class TextServlet
Parameters:
req - The HTTP request we're responding to
res - The HTTP result to write to
exc - The exception producing the error. If it's a DynaXMLException, the attributes will be passed to the error stylesheet.