|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectGenericServlet
HttpServlet
TextServlet
public abstract class TextServlet
Base class for the crossQuery and dynaXML servlets. Handles first-time initialization, config file loading and some parsing, error handling, and a few utility methods.
Nested Class Summary | |
---|---|
private class |
TextServlet.RequestWrapper
Wraps a servlet request, substituting a different parameter set that allows ';' in addition to '&' as a separator. |
private class |
TextServlet.ResponseWrapper
Wraps a servlet response, substituting a different output stream Note: Some deprecated methods are included in HttpServletResponseWrapper. |
Field Summary | |
---|---|
private String |
baseDir
Base directory specified in servlet config (if any) |
private long |
configFileLastModified
Last modification time of the configuration file, so we can decide when we need to re-initialize the servlet. |
private static ThreadLocal |
curRequest
Keeps track, per thread, of the HTTP servlet request being processed |
private static ThreadLocal |
curResponse
Keeps track, per thread, of the HTTP servlet response |
private static ThreadLocal |
curServlet
Keeps track, per thread, of the servlet performing a request |
private ThreadLocal<String> |
errorGenSheet
The error generator stylesheet to use |
private static HashMap<String,IndexWarmer> |
indexWarmers
Used for warming up indexes in the background |
private boolean |
isInitted
Flag to discern whether class has been initialized yet |
private static String |
SAVE_WILD_QMARK
During tokenization, the '?' |
private static String |
SAVE_WILD_STAR
During tokenization, the '*' wildcard has to be changed to a word to keep it from being removed. |
private ServletContext |
staticContext
Context useful for mapping partial paths to full paths |
StylesheetCache |
stylesheetCache
Caches stylesheets (based on their URL) |
Constructor Summary | |
---|---|
TextServlet()
|
Method Summary | |
---|---|
protected void |
addParam(XMLFormatter fmt,
String name,
String val,
Map tokenizerMap)
Adds the tokenized and un-tokenized version of the attribute to the given formatter. |
protected void |
addToken(XMLFormatter fmt,
String str,
boolean isWord)
Adds a token element to a parameter node. |
protected void |
addTokens(char inQuote,
XMLFormatter fmt,
String str)
Adds one or more token elements to a parameter node. |
void |
buildParamBlock(AttribList atts,
XMLFormatter fmt,
Map tokenizerMap,
String extra)
Creates a document containing tokenized and untokenized versions of each parameter. |
protected static String |
calcMimeType(Templates stylesheet)
Given a stylesheet, determine what the Mime type of the servlet response should be. |
static String |
convertUTF8inURL(String value)
Although not completely standardized yet, most modern browsers encode Unicode characters above U+007F to UTF8 in the URL. |
protected void |
cqlTokenize(XMLFormatter fmt,
String name,
String val)
Parse 'val' as a CQL query, and add the resulting XCQL to the parameter. |
Result |
createFilteredReceiver(Transformer trans,
HttpServletRequest req,
HttpServletResponse res)
Makes a Saxon Receiver that will transparently add a session IDs to URLs if they match the servlet URL, or other patterns configured in the conf file. |
QueryProcessor |
createQueryProcessor()
Create a QueryProcessor. |
static String |
decodeURL(String value)
Certain methods of HttpServletRequest do not decode escaped characters in the URL. |
protected void |
defaultTokenize(XMLFormatter fmt,
String name,
String val)
Break 'val' up into its component tokens and add elements for them. |
void |
destroy()
Called by the servlet container to indicate this servlet is being taken out of service. |
abstract void |
doGet(HttpServletRequest req,
HttpServletResponse res)
Derived classes must supply this method. |
void |
doPost(HttpServletRequest req,
HttpServletResponse resp)
Derived classes may optionally supply this method. |
private void |
firstTimeInit(boolean forceInit)
Ensures that the servlet has been properly initialized. |
protected void |
genErrorPage(HttpServletRequest req,
HttpServletResponse res,
Exception exc)
Generate an error page based on the given exception. |
abstract TextConfig |
getConfig()
Derived classes must supply this method. |
abstract String |
getConfigName()
Derived classes must supply this method. |
static HttpServletRequest |
getCurRequest()
Get the HTTP servlet request that is currently being processed by this thread, or null if none is being processed by this thread. |
static HttpServletResponse |
getCurResponse()
Get the HTTP servlet response that is currently being generated by this thread, or null if no request is being processed. |
static TextServlet |
getCurServlet()
Get the servlet that is currently executing a request in this thread, or null if no request is being processed by this thread. |
String |
getRealPath(String partialPath)
Translate a partial filesystem path to a full path. |
static String |
getRequestURL(HttpServletRequest req)
Gets the full URL, including query parameters, from an HTTP request. |
static String |
getRequestURL(HttpServletRequest req,
boolean raw)
Gets the full URL, including query parameters, from an HTTP request. |
static String |
getText(EasyNode element)
Extracts all of the text data from a tree element node. |
static boolean |
isEmpty(String s)
Utility function - check if string is null or "" |
boolean |
isSessionTrackingEnabled()
Tells whether session tracking was enabled in the config file |
protected AttribList |
makeAttribList(HttpServletRequest req)
Generate an AttribList from the parameters in a servlet request. |
static String |
makeHtmlString(String s)
Translates any HTML-special characters (like quote, ampersand, etc.) |
static String |
makeHtmlString(String s,
boolean keepTags)
Translates any HTML-special characters (like quote, ampersand, etc.) |
protected void |
rawTokenize(XMLFormatter fmt,
String name,
String val)
Interpret 'val' as a raw XML element, and output it. |
protected void |
readBranding(String path,
HttpServletRequest req,
Transformer targetTrans)
Reads a brand profile (a simple stylesheet) and stuffs all the output tags into the specified transformer as parameters. |
protected abstract TextConfig |
readConfig(String path)
Derived classes must supply this method. |
static void |
requireOrElse(String value,
String descrip)
Utlity function - if the value is null, throws an exception. |
protected static String |
restoreWildcards(String s)
Restores wildcards saved by saveWildcards(String) . |
protected static String |
saveWildcards(String s)
Converts wildcard characters into word-looking bits that would never occur in real text, so the standard tokenizer will keep them part of words. |
protected void |
service(HttpServletRequest req,
HttpServletResponse res)
General service method. |
void |
setErrorGenSheet(String newPath)
Switch to using a different error generator stylesheet than the default. |
protected void |
setupTrace(TextConfig config)
Sets up the trace facility for serlvet operation: 1. |
static void |
stuffAttribs(Transformer trans,
AttribList list)
Adds all the attributes in the list to the transformer as parameters that can be used by the stylesheet. |
void |
stuffAttribs(Transformer trans,
HttpServletRequest req)
Adds all URL attributes from the request into a transformer. |
void |
stuffSpecialAttribs(HttpServletRequest req,
Transformer trans)
Calculates and adds the "servlet.path" and "root.path" attributes to the given transformer. |
Methods inherited from class HttpServlet |
---|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service |
Methods inherited from class GenericServlet |
---|
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public StylesheetCache stylesheetCache
private ServletContext staticContext
private String baseDir
private boolean isInitted
private ThreadLocal<String> errorGenSheet
private long configFileLastModified
private static ThreadLocal curServlet
private static ThreadLocal curRequest
private static ThreadLocal curResponse
private static HashMap<String,IndexWarmer> indexWarmers
private static final String SAVE_WILD_STAR
private static final String SAVE_WILD_QMARK
Constructor Detail |
---|
public TextServlet()
Method Detail |
---|
public static String getText(EasyNode element)
element
- element to get text from
public String getRealPath(String partialPath)
partialPath
- A partial (or full) path
public static boolean isEmpty(String s)
s
- String to check
public static void requireOrElse(String value, String descrip) throws GeneralException
value
- The value to check for nulldescrip
- If exception is thrown, this will be the message.
GeneralException
- Only if the value is nullpublic static TextServlet getCurServlet()
public static HttpServletRequest getCurRequest()
public static HttpServletResponse getCurResponse()
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
private final void firstTimeInit(boolean forceInit)
protected void setupTrace(TextConfig config)
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
service
in class HttpServlet
ServletException
IOException
public void setErrorGenSheet(String newPath)
public abstract void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
doGet
in class HttpServlet
IOException
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
doGet(HttpServletRequest, HttpServletResponse)
is called and the parameters are decoded automatically by the
HttpServletRequest
, assuming they're URL encoded..
doPost
in class HttpServlet
IOException
ServletException
public abstract String getConfigName()
protected abstract TextConfig readConfig(String path)
path
- Path to the configuration file
public abstract TextConfig getConfig()
public boolean isSessionTrackingEnabled()
public static String getRequestURL(HttpServletRequest req)
public static String getRequestURL(HttpServletRequest req, boolean raw)
raw
- true to suppress un-escaping of % codes and probable
utf-8 coding in the URL.public void stuffAttribs(Transformer trans, HttpServletRequest req)
trans
- The transformer to stuff the parameters inreq
- The request containing the parameterspublic static void stuffAttribs(Transformer trans, AttribList list)
trans
- The transformer to stuff the parameters inlist
- The list containing attributes to stuffpublic void stuffSpecialAttribs(HttpServletRequest req, Transformer trans)
protected void readBranding(String path, HttpServletRequest req, Transformer targetTrans) throws Exception
path
- Filesystem path to the brand profilereq
- HTTP servlet request containing URL parameterstargetTrans
- Where to stuff the attributes into
Exception
- If an error occurs loading or parsing the profile.public Result createFilteredReceiver(Transformer trans, HttpServletRequest req, HttpServletResponse res) throws XPathException, IOException
trans
- The transformer that will do the workreq
- The servlet request being processedres
- The servlet response to output to
XPathException
IOException
public static String makeHtmlString(String s)
s
- The string to transformpublic static String makeHtmlString(String s, boolean keepTags)
s
- The string to transformpublic QueryProcessor createQueryProcessor()
DefaultQueryProcessor
is
created.
public static String decodeURL(String value)
public static String convertUTF8inURL(String value)
value
- value to convert
public void buildParamBlock(AttribList atts, XMLFormatter fmt, Map tokenizerMap, String extra)
protected void addParam(XMLFormatter fmt, String name, String val, Map tokenizerMap)
fmt
- formatter to add toname
- Name of the URL parameterval
- String value of the URL parametertokenizerMap
- tells which parameters to tokenize, and howprotected void rawTokenize(XMLFormatter fmt, String name, String val)
fmt
- formatter to add toname
- Name of the URL parameterval
- value to tokenize
TransformerException
protected void defaultTokenize(XMLFormatter fmt, String name, String val)
fmt
- formatter to add toname
- Name of the URL parameterval
- value to tokenizeprotected void cqlTokenize(XMLFormatter fmt, String name, String val)
fmt
- formatter to add toname
- Name of the URL parameterval
- value to tokenizeprotected void addTokens(char inQuote, XMLFormatter fmt, String str)
inQuote
- Non-zero means this is a quoted phrase, in which case the
element will be 'phrase' instead of 'token', and it will
be given sub-token elements.fmt
- formatter to add tostr
- The token valueprotected void addToken(XMLFormatter fmt, String str, boolean isWord)
fmt
- formatter to add tostr
- The token valueisWord
- true if token is a real word, false if only punctuationprotected static String saveWildcards(String s)
restoreWildcards(String)
.
protected static String restoreWildcards(String s)
saveWildcards(String)
.
protected static String calcMimeType(Templates stylesheet)
protected void genErrorPage(HttpServletRequest req, HttpServletResponse res, Exception exc)
req
- The HTTP request we're responding tores
- The HTTP result to write toexc
- The exception producing the error. If it's a
DynaXMLException, the attributes will be passed to
the error stylesheet.protected AttribList makeAttribList(HttpServletRequest req)
req
- Request to scan for attributes
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |