Package org.exolab.adaptx.xslt
Class XSLTProcessor
- java.lang.Object
-
- org.exolab.adaptx.util.ErrorObserverAdapter
-
- org.exolab.adaptx.xslt.XSLTProcessor
-
- All Implemented Interfaces:
ErrorObserver
,MessageObserver
public class XSLTProcessor extends ErrorObserverAdapter implements MessageObserver
This class represents an XSLT Processor that implements the W3C XSLT 1.0 Recommendation.- Version:
- $Revision: 4776 $ $Date: 2004-09-28 21:46:27 +0200 (Tue, 28 Sep 2004) $
- Author:
- Keith Visco
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ERR_OUTPUT_FLAG
The flag directive for the error log file -- added by Mohan Embarstatic java.lang.String
HELP_FLAG
The flag directive for the help screenstatic java.lang.String
INDENT_SIZE
Indent Size property namestatic java.lang.String
INPUT_FLAG
The flag directive for the xml input filestatic java.lang.String
OUTPUT_FLAG
The flag directive for the result tree output filestatic java.lang.String
STYLESHEET_FLAG
The flag directive for the stylesheet to usestatic java.lang.String
VALIDATE_FLAG
The flag directive for the turning on validationstatic java.lang.String
VERSION_FLAG
The flag directive for displaying the version-
Fields inherited from interface org.exolab.adaptx.util.ErrorObserver
FATAL, NORMAL, WARNING
-
-
Constructor Summary
Constructors Constructor Description XSLTProcessor()
Creates a new XSLTProcessor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addErrorObserver(ErrorObserver observer)
Adds the given ErrorObserver to the list of ErrorObservers for this processorvoid
addFunctionResolver(FunctionResolver fnResolver)
Adds the given FunctionResolver used for resovling extension functions.void
addMessageObserver(MessageObserver msgObserver)
Adds the given MessageObserver to this processors list of MessageObserversstatic URILocation
createURILocation(java.io.Reader reader, java.lang.String filename)
Creates a URILocation for the given Reader and Filename.static java.lang.String
getAppInfo()
Retrieves the name and version of this applicationXSLOutput
getOutputProperties()
Returns the XSLOutput object containing the output properties.java.lang.String
getParameter(java.lang.String name)
Returns the value of the top-level parameter associated with the given name.java.util.Enumeration
getParameterNames()
Returns an enumeration of all top-level parameter names.java.lang.String
getProperty(java.lang.String property)
Returns the property value associated with the given Stringstatic void
main(java.lang.String[] args)
Runs this XSLProcessor based on the given arguments.org.w3c.dom.Document
process(java.lang.String xmlFilename)
Processes the specified xml file, using the stylesheet specified by the xml stylesheet PI, and returns the resulting document.void
process(java.lang.String xmlFilename, java.io.Writer out)
Processes the specified xml file, using the stylesheet specified by the xml stylesheet PI, and the default ResultHandler.org.w3c.dom.Document
process(java.lang.String xmlFilename, java.lang.String xslFilename)
Processes the specified xml file, using the specified xsl file.void
process(java.lang.String xmlFilename, java.lang.String xslFilename, java.io.Writer out)
Processes the specified xml file, using the specified xsl file, and the default ResultHandler.void
process(java.lang.String xmlFilename, java.lang.String xslFilename, ResultHandler handler)
Processes the specified xml file, using the specified xsl file, and the desired ResultHandler.void
process(java.lang.String xmlFilename, XSLTStylesheet stylesheet, java.io.Writer out)
Processes the specified xml file, using the specified xsl file, and the default ResultHandler.void
process(java.lang.String xmlFilename, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml file, using the specified xsl file, and the desired ResultHandler.org.w3c.dom.Document
process(URILocation xmlLocation, URILocation xslLocation)
Processes the specified xml URILocation, using the specified xslt stylesheet URILocation, and the desired ResultHandler.void
process(URILocation xmlLocation, URILocation xslLocation, ResultHandler handler)
Processes the specified xml URILocation, using the specified xslt stylesheet URILocation, and the desired ResultHandler.void
process(URILocation xmlLocation, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml URILocation, using the specified xslt stylesheet, and the desired ResultHandler.XPathNode
process(XPathNode source, XSLTStylesheet stylesheet)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet.void
process(XPathNode source, XSLTStylesheet stylesheet, java.io.Writer out)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet, and the default ResultHandler.void
process(XPathNode source, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml source node (XPathNode), using the specified xsl stylesheet, and the desired ResultHandler.org.w3c.dom.Document
process(org.w3c.dom.Document xmlDocument, XSLTStylesheet stylesheet)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet.void
process(org.w3c.dom.Document xmlDocument, XSLTStylesheet stylesheet, java.io.Writer out)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet, and the default ResultHandler.void
process(org.w3c.dom.Document xmlDocument, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet, and the desired ResultHandler.org.w3c.dom.Document
process(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document xslDocument)
Processes the specified xml (DOM) Document, using the specified (DOM) xsl stylesheet.void
process(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document xslDocument, java.io.Writer out)
Processes the specified xml (DOM) Document, using the specified xsl (DOM) Document and the default ResultHandler.void
process(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document xslDocument, ResultHandler handler)
Processes the specified xml (DOM) Document, using the specified xsl (DOM) Document and the desired ResultHandler.void
receiveMessage(java.lang.String message)
Recieves a messagevoid
removeAllParameters()
Removes all the top-level parameter bindingsvoid
removeFunctionResolver(FunctionResolver fnResolver)
Removes the given FunctionResolver from the list of extension function resolvers.MessageObserver
removeMessageObserver(MessageObserver msgObserver)
Removes the given MessageObserver from this processors list of MessageObserversvoid
removeParameter(java.lang.String name)
Removes the top-level parameter binding with the given namevoid
setDocumentBase(java.lang.String documentBase)
Sets the document base for resolving relative URLsvoid
setDOMParser(DOMParser domParser)
Sets the DOMParser that will be used to read in XML Documentsvoid
setOutputProperties(XSLOutput output)
Sets the XSLOutput object containing the output properties.void
setParameter(java.lang.String name, java.lang.String value)
Sets a parameter which may be accessed using a top-level parameter in the XSLT Stylesheet.void
setProperty(java.lang.String property, java.lang.String value)
Sets the property value associated with the given String.void
setURIResolver(URIResolver resolver)
Sets the URIResolver for resolving all URIs.void
setValidation(boolean validate)
Sets whether or not to validate when reading an XML document.-
Methods inherited from class org.exolab.adaptx.util.ErrorObserverAdapter
receiveError, receiveError, receiveError, receiveError, receiveError, receiveError, removeAllErrorObservers, removeErrorObserver
-
-
-
-
Field Detail
-
HELP_FLAG
public static final java.lang.String HELP_FLAG
The flag directive for the help screen- See Also:
- Constant Field Values
-
INPUT_FLAG
public static final java.lang.String INPUT_FLAG
The flag directive for the xml input file- See Also:
- Constant Field Values
-
OUTPUT_FLAG
public static final java.lang.String OUTPUT_FLAG
The flag directive for the result tree output file- See Also:
- Constant Field Values
-
STYLESHEET_FLAG
public static final java.lang.String STYLESHEET_FLAG
The flag directive for the stylesheet to use- See Also:
- Constant Field Values
-
VALIDATE_FLAG
public static final java.lang.String VALIDATE_FLAG
The flag directive for the turning on validation- See Also:
- Constant Field Values
-
VERSION_FLAG
public static final java.lang.String VERSION_FLAG
The flag directive for displaying the version- See Also:
- Constant Field Values
-
ERR_OUTPUT_FLAG
public static final java.lang.String ERR_OUTPUT_FLAG
The flag directive for the error log file -- added by Mohan Embar- See Also:
- Constant Field Values
-
INDENT_SIZE
public static final java.lang.String INDENT_SIZE
Indent Size property name- See Also:
- Constant Field Values
-
-
Method Detail
-
addErrorObserver
public void addErrorObserver(ErrorObserver observer)
Adds the given ErrorObserver to the list of ErrorObservers for this processor- Overrides:
addErrorObserver
in classErrorObserverAdapter
- Parameters:
observer
- the ErrorObserver to add
-
addFunctionResolver
public void addFunctionResolver(FunctionResolver fnResolver)
Adds the given FunctionResolver used for resovling extension functions.- Parameters:
fnResolver
- the FunctionResolver to add- See Also:
org.exolab.adaptx.xpath.FunctionResolver
-
addMessageObserver
public void addMessageObserver(MessageObserver msgObserver)
Adds the given MessageObserver to this processors list of MessageObservers- Parameters:
msgObserver
- the MessageObserver to add to this processors list of MessageObservers
-
getAppInfo
public static java.lang.String getAppInfo()
Retrieves the name and version of this application
-
getOutputProperties
public XSLOutput getOutputProperties()
Returns the XSLOutput object containing the output properties. This is used for over-riding any output properties which may appear in the XSLT stylesheet.- Returns:
- the XSLOutput object, or null if not set.
-
getParameter
public java.lang.String getParameter(java.lang.String name)
Returns the value of the top-level parameter associated with the given name.- Parameters:
name
- the name of the top-level parameter whose value should be returned.- Returns:
- the parameter value
- See Also:
getParameterNames()
,removeParameter(java.lang.String)
,removeAllParameters()
,setParameter(java.lang.String,java.lang.String)
-
getParameterNames
public java.util.Enumeration getParameterNames()
Returns an enumeration of all top-level parameter names.- Returns:
- an enumeration of all top-level parameter names.
- See Also:
getParameter(java.lang.String)
,removeParameter(java.lang.String)
,removeAllParameters()
,setParameter(java.lang.String,java.lang.String)
-
getProperty
public java.lang.String getProperty(java.lang.String property)
Returns the property value associated with the given String- Returns:
- the property value associated with the given String
See xslp.properties for for a list of properties
-
createURILocation
public static URILocation createURILocation(java.io.Reader reader, java.lang.String filename)
Creates a URILocation for the given Reader and Filename. Filename must not be null.- Parameters:
reader
- the Reader to create the URILocation forfilename
- , the absolute filename for the URILocation- Returns:
- the new URILocation
-
main
public static void main(java.lang.String[] args)
Runs this XSLProcessor based on the given arguments. This method can be called from another Class however, one of the process methods should be more appropriate- Parameters:
args
- a list of arguments to this XSLProcessor
Though I do not recommend the following, if you need a static call to XSL:P use the following:
args = {"-i", "xmlfile.xml", "-s", "style.xsl","-o","result.html"}
-- OR --
args = {"-ixmlfile.xml", "-sstyle.xsl","-oresult.html"}
If the Stylesheet is referenced by the processing instruction use the following
args = {"-ixmlfile.xml","-oresult.html"}
-
process
public void process(java.lang.String xmlFilename, java.io.Writer out)
Processes the specified xml file, using the stylesheet specified by the xml stylesheet PI, and the default ResultHandler. All results are sent to the Writer.- Parameters:
xmlFilename
- the path to the XML file to processout
- the Writer to print all processing results to.
-
process
public org.w3c.dom.Document process(java.lang.String xmlFilename)
Processes the specified xml file, using the stylesheet specified by the xml stylesheet PI, and returns the resulting document.- Parameters:
xmlFilename
- the path to the XML file to process
-
process
public void process(java.lang.String xmlFilename, java.lang.String xslFilename, java.io.Writer out)
Processes the specified xml file, using the specified xsl file, and the default ResultHandler. All results are sent to the given Writer.- Parameters:
xmlFilename
- the href to the XML file to processxslFilename
- the href to the XSL file to use for processing. This stylesheet will supercede any embedded stylesheets in the xsl document. Set to null, to allow xml:stylesheet PI to be processed.out
- the Writer to print all processing results to.
-
process
public void process(java.lang.String xmlFilename, XSLTStylesheet stylesheet, java.io.Writer out)
Processes the specified xml file, using the specified xsl file, and the default ResultHandler. All results are sent to the given Writer.- Parameters:
xmlFilename
- the href to the XML file to processstylesheet
- the XSLStylesheet to use for processing This stylesheet will supercede any embedded stylesheets in the xsl document. Set to null, to allow xml:stylesheet PI to be processed.out
- the Writer to print all processing results to.
-
process
public void process(java.lang.String xmlFilename, java.lang.String xslFilename, ResultHandler handler)
Processes the specified xml file, using the specified xsl file, and the desired ResultHandler. All results are sent to the PrintWriter.- Parameters:
xmlFilename
- the path to the XML file to processxslFilename
- the path to the XSL file to use for processing. This stylesheet will supercede any embedded stylesheets in the xsl document.handler
- the ResultHandler which handles the result tree.
-
process
public void process(java.lang.String xmlFilename, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml file, using the specified xsl file, and the desired ResultHandler. All results are sent to the PrintWriter.- Parameters:
xmlFilename
- the path to the XML file to processstylesheet
- the XSLStylesheet to use for processing. This stylesheet will supercede any embedded stylesheets in the xsl document.handler
- the ResultHandler which handles the result tree.
-
process
public org.w3c.dom.Document process(java.lang.String xmlFilename, java.lang.String xslFilename)
Processes the specified xml file, using the specified xsl file.- Parameters:
xmlFilename
- the path to the XML file to processxslFilename
- the path to the XSL file to use for processing. This stylesheet will supercede any embedded stylesheets in the xsl document.- Returns:
- the resulting Document
-
process
public org.w3c.dom.Document process(URILocation xmlLocation, URILocation xslLocation)
Processes the specified xml URILocation, using the specified xslt stylesheet URILocation, and the desired ResultHandler.- Parameters:
xmlLocation
- the URILocation for the input XML sourcexslLocation
- the URILocation for the stylesheet to use. If present this stylesheet will supercede any embedded stylesheets in the xml document. Set to null, to allow the xml:stylesheet PI to be processed.- Returns:
- the resulting DOM Document
-
process
public void process(URILocation xmlLocation, URILocation xslLocation, ResultHandler handler)
Processes the specified xml URILocation, using the specified xslt stylesheet URILocation, and the desired ResultHandler.- Parameters:
xmlLocation
- the URILocation for the input XML sourcexslLocation
- the URILocation for the stylesheet to use. If present this stylesheet will supercede any embedded stylesheets in the xml document. Set to null, to allow the xml:stylesheet PI to be processed.handler
- the ResultHandler to use for processing the stylesheet
-
process
public void process(URILocation xmlLocation, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml URILocation, using the specified xslt stylesheet, and the desired ResultHandler.- Parameters:
xmlLocation
- the URILocation for the input XML sourcestylesheet
- the XSLTStylesheet to use (may be null). If present this stylesheet will supercede any embedded stylesheets in the xml document. Set to null, to allow the xml:stylesheet PI to be processed.handler
- the ResultHandler to use for processing the stylesheet
-
process
public org.w3c.dom.Document process(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document xslDocument)
Processes the specified xml (DOM) Document, using the specified (DOM) xsl stylesheet.- Parameters:
xmlDocument
- the XML Document to processxslDocument
- the XSL Document to use for processing.- Returns:
- the resulting Document
-
process
public void process(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document xslDocument, java.io.Writer out)
Processes the specified xml (DOM) Document, using the specified xsl (DOM) Document and the default ResultHandler. All results are sent to the specified PrintWriter.- Parameters:
xmlDocument
- the XML Document to processxslDocument
- the XSL Document to use for processing.out
- the Writer to print all processing results to.
-
process
public void process(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document xslDocument, ResultHandler handler)
Processes the specified xml (DOM) Document, using the specified xsl (DOM) Document and the desired ResultHandler. All results are sent to the specified PrintWriter.- Parameters:
xmlDocument
- the XML Document to processxslDocument
- the XSL Document to use for processing.out
- the PrintWriter to print all processing results to.handler
- the desired ResultHandler to use during processing
-
process
public XPathNode process(XPathNode source, XSLTStylesheet stylesheet)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet.- Parameters:
xmlDocument
- the XML Document to processstylesheet
- the XSLStylesheet to use for processing.- Returns:
- the resulting Document
-
process
public org.w3c.dom.Document process(org.w3c.dom.Document xmlDocument, XSLTStylesheet stylesheet)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet.- Parameters:
xmlDocument
- the XML Document to processstylesheet
- the XSLStylesheet to use for processing.- Returns:
- the resulting Document
-
process
public void process(XPathNode source, XSLTStylesheet stylesheet, java.io.Writer out)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet, and the default ResultHandler. All results are sent to the specified Writer.- Parameters:
source
- the XML source node (XPathNode) to processstylesheet
- the XSLStylesheet to use for processing.out
- the Writer to print all processing results to.
-
process
public void process(org.w3c.dom.Document xmlDocument, XSLTStylesheet stylesheet, java.io.Writer out)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet, and the default ResultHandler. All results are sent to the specified PrintWriter.- Parameters:
xmlDocument
- the XML Document to processstylesheet
- the XSLStylesheet to use for processing.out
- the PrintWriter to print all processing results to.
-
process
public void process(XPathNode source, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml source node (XPathNode), using the specified xsl stylesheet, and the desired ResultHandler. All results are sent to the specified ResultHandler.- Parameters:
source
- the XML source node to processstylesheet
- the XSLStylesheet to use for processing.handler
- the ResultHandler to handle the result.
-
process
public void process(org.w3c.dom.Document xmlDocument, XSLTStylesheet stylesheet, ResultHandler handler)
Processes the specified xml (DOM) Document, using the specified xsl stylesheet, and the desired ResultHandler. All results are sent to the specified ResultHandler.- Parameters:
xmlDocument
- the XML Document to processstylesheet
- the XSLStylesheet to use for processing.handler
- the desired ResultHandler to use during processing
-
receiveMessage
public void receiveMessage(java.lang.String message)
Recieves a message- Specified by:
receiveMessage
in interfaceMessageObserver
- Parameters:
message
- the message to recieve- See Also:
MessageObserver
-
removeFunctionResolver
public void removeFunctionResolver(FunctionResolver fnResolver)
Removes the given FunctionResolver from the list of extension function resolvers.- Parameters:
fnResolver
- the FunctionResolver to remove- See Also:
org.exolab.adaptx.xpath.FunctionResolver
-
removeMessageObserver
public MessageObserver removeMessageObserver(MessageObserver msgObserver)
Removes the given MessageObserver from this processors list of MessageObservers- Parameters:
msgObserver
- the MessageObserver to remove from this processors list of MessageObservers- Returns:
- the given MessageObserver if it was removed from the list, otherwise return null
-
removeParameter
public void removeParameter(java.lang.String name)
Removes the top-level parameter binding with the given name- Parameters:
name
- the name of the parameter binding to remove- See Also:
removeAllParameters()
,setParameter(java.lang.String,java.lang.String)
-
removeAllParameters
public void removeAllParameters()
Removes all the top-level parameter bindings
-
setDocumentBase
public void setDocumentBase(java.lang.String documentBase)
Sets the document base for resolving relative URLs- Parameters:
documentBase
- the document base to use while processing.
-
setDOMParser
public void setDOMParser(DOMParser domParser)
Sets the DOMParser that will be used to read in XML Documents- Parameters:
domParser
- the DOMParser that is to be used to read in XML Documents
Note:This will make a call to Configuration#setDOMParser which is static, so this DOMParser will be shared by all instances of XSL:P running in the same VM.
-
setOutputProperties
public void setOutputProperties(XSLOutput output)
Sets the XSLOutput object containing the output properties. This is used for over-riding any output properties which may appear in the XSLT stylesheet.- Parameters:
output
- the XSLOutput object to set.
-
setProperty
public void setProperty(java.lang.String property, java.lang.String value)
Sets the property value associated with the given String.
-
setParameter
public void setParameter(java.lang.String name, java.lang.String value)
Sets a parameter which may be accessed using a top-level parameter in the XSLT Stylesheet.- Parameters:
name
- the name of the parametervalue
- the value of the parameter
-
setURIResolver
public void setURIResolver(URIResolver resolver)
Sets the URIResolver for resolving all URIs. If null, the default URIResolver will be used.- Parameters:
resolver
- the URIResolver to use
-
setValidation
public void setValidation(boolean validate)
Sets whether or not to validate when reading an XML document. Note:This will turn on validation for the DOMParser returned by Configuration#getDOMParser(), which is static, so this validation (on/off) will be shared by all instances of XSL:P running in the same VM.- Parameters:
validate
- the boolean indicating whether to validate or not- Since:
- 19990408
-
-