| java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet servlet.ApplyXSLT
ApplyXSLT | public class ApplyXSLT extends HttpServlet (Code) | | ApplyXSLT supplies the basic
functions for transforming XML data using XSL stylesheets.
author: Spencer Shepard (sshepard@us.ibm.com) author: R. Adam King (rak@us.ibm.com) author: Tom Rowe (trowe@us.ibm.com) author: Don Leslie (donald_leslie@lotus.com) |
Field Summary | |
public static String | CURRENTDIR | final public static String | EOL String representing the end of line characters for the System. | final public static String | FS String representing the file separator characters for the System. | final protected static String | HEADER_NAME The HTTP Header used for matching the Stylesheet attribute via the
media properties file selected. | final public static String | ROOT String representing the current directory for properties files. | final protected static String | STYLESHEET_ATTRIBUTE The attribute name in the tag used in stylesheet selection. | protected ApplyXSLTProperties | ourDefaultParameters Operational parameters for this class. | protected OrderedProps | ourMediaProps Mapping of HTTP request's user-Agent values to stylesheet media= values. |
Method Summary | |
protected void | displayException(HttpServletResponse response, ApplyXSLTException xse, boolean debug) Invokes response.sendError setting an HTTP status code and optionally an error message
as an HTML page. | public void | doGet(HttpServletRequest request, HttpServletResponse response) HTTP Get method passed on to process(). | public String | getContentType(Templates templates) Returns the response content type specified by the media-type and encoding attributes of
the <xsl:output> element(s) of the stylesheet.
Parameters: xslSourceRoot - XSL Stylesheet to be examined for <xsl:output> elements. | protected StreamSource | getDocument(HttpServletRequest request, ApplyXSLTListener listener) Returns an XML XSLTInputSource DOM. | public String | getMedia(HttpServletRequest request) | protected StreamSource | getStylesheet(TransformerFactory tFactory, HttpServletRequest request, StreamSource xmlSource, ApplyXSLTListener listener) Returns a Templates (StylesheetRoot) object. | public static String | getXSLURLfromDoc(StreamSource xmlSource, String attributeName, String attributeValue, TransformerFactory tFactory) Returns the XSL stylesheet URL associated with the specified XML document. | public void | init(ServletConfig config) Initialize operational parameters from the configuration. | public void | process(TransformerFactory tFactory, HttpServletRequest request, HttpServletResponse response) Coordinates applying an XSL stylesheet to XML data using operational parameters.
If successfully applied, the result tree will be streamed to the response object
and the content type set according to the XSL stylesheet's <xsl:output> element(s).
If there is a problem in parsing the XML/XSL or if there is a problem in applying
the XSL to the XML, an exception will be streamed to the response object. | protected void | setDefaultParameters(ServletConfig config) Sets the default parameters for the servlet from the configuration. | protected void | setMediaProps(String mediaURLstring) Loads the media properties file specified by the given string.
Parameters: mediaURLstring - Location of the media properties file. | public void | setStylesheetParams(Transformer transformer, HttpServletRequest request) Defines and sets select top-level XSL stylesheet variables from the HTTP request, which
can be evaluated using <xsl:param-variable>. | protected URLConnection | toAcceptLanguageConnection(URL url, HttpServletRequest request) Returns a connection which respects the Accept-Language header of the HTTP request. | protected void | writeLog(ApplyXSLTException axe) | protected void | writeLog(String msg, int statusCode, Throwable t) | protected void | writeLog(String msg, int statusCode) |
EOL | final public static String EOL(Code) | | String representing the end of line characters for the System.
|
FS | final public static String FS(Code) | | String representing the file separator characters for the System.
|
HEADER_NAME | final protected static String HEADER_NAME(Code) | | The HTTP Header used for matching the Stylesheet attribute via the
media properties file selected.
|
ROOT | final public static String ROOT(Code) | | String representing the current directory for properties files. See init().
|
STYLESHEET_ATTRIBUTE | final protected static String STYLESHEET_ATTRIBUTE(Code) | | The attribute name in the tag used in stylesheet selection.
|
ourDefaultParameters | protected ApplyXSLTProperties ourDefaultParameters(Code) | | Operational parameters for this class.
Request-time values override init-time values which override class defaults.
See Also: ApplyXSLT.init |
ourMediaProps | protected OrderedProps ourMediaProps(Code) | | Mapping of HTTP request's user-Agent values to stylesheet media= values.
This mapping is defined by a file pointed to by the operational parameter "mediaURL" which can
either contain a full URL or a path relative to the System's server.root /servlets directory.
See Also: ApplyXSLT.setMediaProps See Also: ApplyXSLT.getMedia |
displayException | protected void displayException(HttpServletResponse response, ApplyXSLTException xse, boolean debug)(Code) | | Invokes response.sendError setting an HTTP status code and optionally an error message
as an HTML page.
If running in debug mode, also try to return a stack trace of the exception and
and xml/xsl processor messages.
Parameters: response - Where to stream the exception to Parameters: xse - The wrapper which contains the exception and its HTTP status code Parameters: debug - Indicates whether to include stack trace, etc. |
getContentType | public String getContentType(Templates templates)(Code) | | Returns the response content type specified by the media-type and encoding attributes of
the <xsl:output> element(s) of the stylesheet.
Parameters: xslSourceRoot - XSL Stylesheet to be examined for <xsl:output> elements. The response content type (MIME type and charset) of the stylesheet output See Also: ApplyXSLT.process |
getDocument | protected StreamSource getDocument(HttpServletRequest request, ApplyXSLTListener listener) throws ApplyXSLTException(Code) | | Returns an XML XSLTInputSource DOM. Attempts will be make to create the DOM from the following
sources:
- A relative URL specified in the HTTP request's path information. This capability is intended
for use by servlet engines that map some or all XML data to be processed at the server.
- A URL specified in the HTTP request's
URL= parameter. This capability
is intended for clients wishing to selectively process XML data at the server. For
security reasons, this URL will be forced to the local IP host.
- The HTTP request's XML input stream. This capability is intended for use by chained servlets.
Parameters: request - May contain or point to the XML XSLTInputSource Parameters: listener - To record detailed parsing messages for possible return to requestor XML XSLTInputSource DOM, or null if the XSLTInputSource could not be parsed exception: ApplyXSLTException - Thrown if exception occurs while handling request |
getStylesheet | protected StreamSource getStylesheet(TransformerFactory tFactory, HttpServletRequest request, StreamSource xmlSource, ApplyXSLTListener listener) throws ApplyXSLTException(Code) | | Returns a Templates (StylesheetRoot) object. Attempts will be make to create the Stylesheet
from the followingsources:
- A URL specified in the HTTP request's
xslURL= parameter. This capability
is intended for clients wishing to selectively override the server algorithm for applying XSL
stylesheets. For security reasons, this URL will be forced to the local IP host.
- XML association. XML documents may contain references to one or more stylesheets using
this W3C proposed recommendation.
If the XML document does contain such references, a best match will be chosen based on the browser
type making the request and the default association. This capability enables relationships to be
defined between client capabilities and stylesheets capable of acting on these capabilities.
- A configured default stylesheet URL
Parameters: request - May contain or point to the XSL XSLTInputSource Parameters: xmlSource - May point to the XSL XSLTInputSource Parameters: listener - To record detailed parsing messages for possible return to requestor XSL XSLTInputSource, or null if the request could not be parsed See Also: ApplyXSLT.makeDocument See Also: ApplyXSLT.getMedia See Also: ApplyXSLT.STYLESHEET_ATTRIBUTE See Also: ApplyXSLT.getXSLURLfromDoc See Also: ApplyXSLT.toAcceptLanguageConnection exception: ApplyXSLTException - Thrown if exception occurs while handling request |
getXSLURLfromDoc | public static String getXSLURLfromDoc(StreamSource xmlSource, String attributeName, String attributeValue, TransformerFactory tFactory)(Code) | | Returns the XSL stylesheet URL associated with the specified XML document. If multiple XSL
stylesheets are associated with the XML document, preference will be given to the stylesheet
which contains an attribute name/value pair that corresponds to the specified attributeName
and attributeValue.
Parameters: xmlSource - XML XSLTInputSource to be searched for associated XSL stylesheets Parameters: attributeName - Attribute name to provide preferential matching Parameters: attributeValue - Attribute value to provide preferential matching The preferred XSL stylesheet URL, or null if no XSL stylesheet association is found See Also: ApplyXSLT.getStylesheet |
setDefaultParameters | protected void setDefaultParameters(ServletConfig config)(Code) | | Sets the default parameters for the servlet from the configuration.
Also sets required system properties until we figure out why servlet
sometimess fails to read properties from properties files.
Parameters: config - Configuration |
setMediaProps | protected void setMediaProps(String mediaURLstring)(Code) | | Loads the media properties file specified by the given string.
Parameters: mediaURLstring - Location of the media properties file. Can be either a full URL or a path relativeto the System's server.root /servlets directory. If this parameter is null,server.root/servlets/media.properties will be used. See Also: ApplyXSL.CURRENTDIR |
setStylesheetParams | public void setStylesheetParams(Transformer transformer, HttpServletRequest request)(Code) | | Defines and sets select top-level XSL stylesheet variables from the HTTP request, which
can be evaluated using <xsl:param-variable>. The following variables will be
automatically set:
- ParameterName
- Each non-reserved request parameter returned from request.getParameterNames(). If a
parameter contains more than a single value, only the first value is available.
- servlet-RemoteAddr
- Contains String output from request.getRemoteAddr(), which is the IP address
of the client machine.
- servlet-RemoteHost
- Contains String output from request.getRemoteHost(), which is the host name
of the client machine.
- servlet-RemoteUser
- Contains String output from request.getRemoteUser(), which was the user name
accepted by the server to grant access to this servlet.
- servlet-Request
- Contains the request object.
Parameters: xslprocessor - Where to register parameters to be set Parameters: request - Provides access to all meaningful parameters to set See Also: ApplyXSLT.process |
toAcceptLanguageConnection | protected URLConnection toAcceptLanguageConnection(URL url, HttpServletRequest request) throws Exception(Code) | | Returns a connection which respects the Accept-Language header of the HTTP request. This
is useful when XSL files are internationalized for use with Web servers which respect this
header.
For example, Apache 1.3.6 may be configured for multiviews. Under this configuration,
requests for http://myhost/index.html would return http://myhost/index.html.fr to French browsers
and http://myhost/index.html.en to English browsers.
Parameters: url - Location to connect to Parameters: request - Could contain an Accept-Language header An Accept-Language-enabled URL connection See Also: ApplyXSLT.getStylesheet |
writeLog | protected void writeLog(ApplyXSLTException axe)(Code) | | Writes the following information to the servlet log:
- HTTP status code
- Message
- Stack trace
Parameters: axe - Contains valid HTTP status code, message, and stack trace (optional) |
writeLog | protected void writeLog(String msg, int statusCode, Throwable t)(Code) | | Writes the following information to the servlet log:
- HTTP status code
- Message
- Stack trace
Parameters: msg - Message to be logged Parameters: statusCode - Valid status code from javax.servlet.http.HttpServletResponse Parameters: t - Used to generate stack trace (may be =null to suppress stack trace) |
writeLog | protected void writeLog(String msg, int statusCode)(Code) | | Writes the following information to the servlet log:
- HTTP status code
- Message
Parameters: msg - Message to be logged Parameters: statusCode - Valid status code from javax.servlet.http.HttpServletResponse |
Methods inherited from javax.servlet.http.HttpServlet | protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected long getLastModified(HttpServletRequest req)(Code)(Java Doc) protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException(Code)(Java Doc)
|
|
|