Class Controller
- All Implemented Interfaces:
NodeOrderComparer
- Direct Known Subclasses:
IdentityTransformer
- Version:
- 10 December 1999: methods for building the tree extracted to class Builder,
methods for maintaining rulesets extracted to RuleManager.
The Controller class now incorporates the previous StylesheetInstance class. A StyleSheetInstance represents a single execution of a prepared stylesheet. A PreparedStyleSheet can be used any number of times, in series or in parallel, but each use of it to render a source document requires a separate Controller object, which is not reusable or shareable.
The Controller is capable of comparing whether nodes are in document order; therefore it acts as a NodeOrderComparer.
- Author:
- Michael H. Kay
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor is provided for Java-only programs, i.e.protected
Controller
(TransformerFactoryImpl factory) Create a Controller and initialise variables. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTraceListener
(TraceListener trace) Adds the specified trace listener to receive trace events from this instance.void
applyImports
(Context c, Mode mode, int min, int max, ParameterSet params) Apply a template imported from the stylesheet containing the current templatevoid
applyTemplates
(Context c, Expression select, Mode mode, ParameterSet parameters) ApplyTemplates to process selected nodes using the handlers registered for a particular mode.void
changeOutputDestination
(Properties props, Result result) Set a new output destination, supplying the output format details.void
Set a simple StringBuffer output destination.void
Clear the document pool.void
Reset the parameters to a null list.int
Compare the position of two nodes in document ordervoid
disableWhitespaceStripping
(boolean disable) Disable whitespace strippingGet the current binderyGet the document pool.Get the error listenerGet the KeyManagerGet the Emitter used for xsl:message outputGet the name pool in useGet the output properties for the transformation.getOutputProperty
(String name) Get the value of an output propertyGet the current outputtergetParameter
(String expandedName) Get a parameter to the transformationint
Get the policy for handling recoverable errorsGet the fallback URI resolver.int
Get the tree model in useGet the primary URI resolver.getUserData
(NodeInfo node, String name) Get the named user data property for the nodeboolean
Determine whether line numbering is enabledfinal boolean
boolean
Determine if whitespace stripping is disabledMake a builder for the selected tree modelmakeContext
(NodeInfo node) Create a new context with a given node as the current node and the only node in the current node list.Make an Emitter to be used for xsl:message outputvoid
pauseTracing
(boolean pause) void
removeTraceListener
(TraceListener trace) Removes the specified trace listener so that the next invocation of the render method will not send trace events to the listener.void
reportRecoverableError
(String message, SourceLocator location) Report a recoverable errorvoid
Report a recoverable errorvoid
reset()
Reset thisTransformer
to its original configuration.void
resetOutputDestination
(Outputter outputter) Close the current outputter, and revert to the previous outputter.void
Process a Document.void
void
setDiagnosticName
(String name) Set a diagnostic name for this transformation (accessible through toString())void
setErrorListener
(ErrorListener listener) Set the error listenervoid
setLineNumbering
(boolean onOrOff) Set line numbering (of the source document) on or offvoid
setMessageEmitter
(Emitter emitter) Set the Emitter to be used for xsl:message outputvoid
setNamePool
(NamePool pool) Set the name pool to be usedvoid
setOutputProperties
(Properties properties) Set the output properties for the transformation.void
setOutputProperty
(String name, String value) Set an output property for the transformation.void
setParameter
(String expandedName, Object value) Set a parameter for the transformation.void
setParams
(ParameterSet params) Set parameters supplied externally (typically, on the command line).void
Associate this Controller with a compiled stylesheetvoid
setRecoveryPolicy
(int policy) Set the policy for handling recoverable errorsvoid
void
setTraceListener
(TraceListener trace) void
setTreeModel
(int model) Set the tree data model to usevoid
setURIResolver
(URIResolver resolver) Set an object that will be used to resolve URIs used in document(), etc.void
setUserData
(NodeInfo node, String name, Object data) Set a user data property for a node.toString()
void
Process the source tree to SAX parse events.void
transformDocument
(NodeInfo startNode, Result result) Render a source XML document supplied as a tree.protected boolean
Does this transformation use preview mode?
-
Field Details
-
RECOVER_SILENTLY
public static final int RECOVER_SILENTLY- See Also:
-
RECOVER_WITH_WARNINGS
public static final int RECOVER_WITH_WARNINGS- See Also:
-
DO_NOT_RECOVER
public static final int DO_NOT_RECOVER- See Also:
-
-
Constructor Details
-
Controller
public Controller()Default constructor is provided for Java-only programs, i.e. applications that use the RuleManager to set up Java handlers for nodes, without using a stylesheet -
Controller
Create a Controller and initialise variables. Constructor is protected, the Controller should be created using newTransformer() in the PreparedStyleSheet class.
-
-
Method Details
-
reset
public void reset()Reset this
Transformer
to its original configuration.Transformer
is reset to the same state as when it was created withTransformerFactory.newTransformer()
,TransformerFactory.newTransformer(javax.xml.transform.Source source)
orTemplates.newTransformer()
.reset()
is designed to allow the reuse of existingTransformer
s thus saving resources associated with the creation of newTransformer
s.The reset
Transformer
is not guaranteed to have the sameURIResolver
orErrorListener
Object
s, e.g.Object.equals(Object obj)
. It is guaranteed to have a functionally equalURIResolver
andErrorListener
.NOTE: the Saxon implementation of this method does not clear the document pool. This is because the reason for resetting an existing Transformer rather than creating a new one is to reuse resources, and the document pool is the most important resource held by the Transformer. If there is a requirement to clear the document pool, then it is possible either (a) to call the
clearDocumentPool()
method, or (b) to create a new Transformer.- Overrides:
reset
in classTransformer
- Since:
- 1.5
-
getTransformerFactory
-
setDiagnosticName
Set a diagnostic name for this transformation (accessible through toString()) -
toString
-
run
Process a Document.This method is intended for use when performing a pure Java transformation, without a stylesheet. Where there is an XSLT stylesheet, use transformDocument() or transform() instead: those methods set up information from the stylesheet before calling run().
The process starts by calling the registered node handler to process the supplied node. Note that the same document can be processed any number of times, typically with different node handlers for each pass. The NodeInfo will typically be the root of a tree built using com.icl.saxon.om.Builder.
- Throws:
TransformerException
-
applyTemplates
public void applyTemplates(Context c, Expression select, Mode mode, ParameterSet parameters) throws TransformerException ApplyTemplates to process selected nodes using the handlers registered for a particular mode.- Parameters:
select
- A node-set expression (or more accurately a node-list) that determines which nodes are selected. Note: if the nodes are to be sorted, the select Expression will take care of this.mode
- Identifies the processing mode. It should match the mode defined when the element handler was registered using setHandler with a mode parameter. Set this parameter to null to invoke the default mode.parameters
- A ParameterSet containing the parameters to the handler/template being invoked. Specify null if there are no parameters.- Throws:
TransformerException
-
applyImports
public void applyImports(Context c, Mode mode, int min, int max, ParameterSet params) throws TransformerException Apply a template imported from the stylesheet containing the current template- Throws:
TransformerException
-
compare
Compare the position of two nodes in document order- Specified by:
compare
in interfaceNodeOrderComparer
- Parameters:
n1
- The first noden2
- The second node- Returns:
- invalid input: '<'0 if the first node is first in document order; >0 if the second node comes first in document order; 0 if the two parameters identify the same node
-
setOutputProperties
Set the output properties for the transformation. These properties will override properties set in the templates with xsl:output.- Specified by:
setOutputProperties
in classTransformer
-
getOutputProperties
Get the output properties for the transformation.- Specified by:
getOutputProperties
in classTransformer
-
setOutputProperty
Set an output property for the transformation.- Specified by:
setOutputProperty
in classTransformer
-
getOutputProperty
Get the value of an output property- Specified by:
getOutputProperty
in classTransformer
-
changeOutputDestination
Set a new output destination, supplying the output format details.
This affects all further output until resetOutputDestination() is called. Note that it is the caller's responsibility to close the Writer after use.- Parameters:
props
- Details of the new output formatresult
- Details of the new output destination- Throws:
TransformerException
-
changeToTextOutputDestination
Set a simple StringBuffer output destination. Used during calls to xsl:attribute, xsl:comment, xsl:processing-instruction -
getOutputter
Get the current outputter -
resetOutputDestination
Close the current outputter, and revert to the previous outputter.- Parameters:
outputter
- The outputter to revert to- Throws:
TransformerException
-
makeMessageEmitter
Make an Emitter to be used for xsl:message output- Throws:
TransformerException
-
setMessageEmitter
Set the Emitter to be used for xsl:message output -
getMessageEmitter
Get the Emitter used for xsl:message output -
setRecoveryPolicy
public void setRecoveryPolicy(int policy) Set the policy for handling recoverable errors -
getRecoveryPolicy
public int getRecoveryPolicy()Get the policy for handling recoverable errors -
setErrorListener
Set the error listener- Specified by:
setErrorListener
in classTransformer
-
getErrorListener
Get the error listener- Specified by:
getErrorListener
in classTransformer
-
reportRecoverableError
public void reportRecoverableError(String message, SourceLocator location) throws TransformerException Report a recoverable error- Throws:
TransformerException
- if the error listener decides not to recover from the error
-
reportRecoverableError
Report a recoverable error- Throws:
TransformerException
- if the error listener decides not to recover from the error
-
getDocumentPool
Get the document pool. This is used only for source documents, not for stylesheet modules -
clearDocumentPool
public void clearDocumentPool()Clear the document pool. This is sometimes useful when using the same Transformer for a sequence of transformations, but it isn't done automatically, because when the transformations use common look-up documents, the caching is beneficial. -
setLineNumbering
public void setLineNumbering(boolean onOrOff) Set line numbering (of the source document) on or off -
isLineNumbering
public boolean isLineNumbering()Determine whether line numbering is enabled -
makeContext
Create a new context with a given node as the current node and the only node in the current node list. -
getBindery
Get the current bindery -
getURIResolver
Get the primary URI resolver.- Specified by:
getURIResolver
in classTransformer
- Returns:
- the user-supplied URI resolver if there is one, or the system-defined one otherwise (Note, this isn't quite as JAXP specifies it).
-
getStandardURIResolver
Get the fallback URI resolver.- Returns:
- the the system-defined URIResolver
-
getKeyManager
Get the KeyManager -
setNamePool
Set the name pool to be used -
getNamePool
Get the name pool in use -
setTreeModel
public void setTreeModel(int model) Set the tree data model to use -
getTreeModel
public int getTreeModel()Get the tree model in use -
disableWhitespaceStripping
public void disableWhitespaceStripping(boolean disable) Disable whitespace stripping -
isWhitespaceStrippingDisabled
public boolean isWhitespaceStrippingDisabled()Determine if whitespace stripping is disabled -
makeBuilder
Make a builder for the selected tree model -
makeStripper
-
setDecimalFormatManager
-
getDecimalFormatManager
-
setRuleManager
-
getRuleManager
-
setTraceListener
-
getTraceListener
-
isTracing
public final boolean isTracing() -
pauseTracing
public void pauseTracing(boolean pause) -
setPreparedStyleSheet
Associate this Controller with a compiled stylesheet -
usesPreviewMode
protected boolean usesPreviewMode()Does this transformation use preview mode? -
addTraceListener
Adds the specified trace listener to receive trace events from this instance. Must be called before the invocation of the render method.- Parameters:
trace
- the trace listener.
-
removeTraceListener
Removes the specified trace listener so that the next invocation of the render method will not send trace events to the listener.- Parameters:
trace
- the trace listener.
-
getUserData
Get the named user data property for the node- Parameters:
name
- the name of the user data property to return- Returns:
- The value of the named user data property. Returns null if no property of that name has been set using setUserData() for this NodeInfo object.
-
setUserData
Set a user data property for a node.- Parameters:
name
- The name of the user data property to be set. Any existing user data property of the same name will be overwritten.data
- an object to be saved with this element, which can be retrieved later using getUserData().
-
transform
Process the source tree to SAX parse events.- Specified by:
transform
in classTransformer
- Parameters:
source
- The input for the source tree.result
- The destination for the result tree.- Throws:
TransformerException
- if the transformation fails. As a special case, the method throws a TerminationException (a subclass of TransformerException) if the transformation was terminated using xsl:message terminate="yes".
-
transformDocument
Render a source XML document supplied as a tree.
A new output destination should be created for each source document, by using setOutputDetails().- Parameters:
startNode
- A Node that identifies the source document to be transformed and the node where the transformation should startresult
- The output destination- Throws:
TransformerException
-
setParameter
Set a parameter for the transformation.- Specified by:
setParameter
in classTransformer
- Parameters:
expandedName
- The name of the parameter in {uri}local formatvalue
- The value object. This can be any valid Java object it follows the same conversion rules as a value returned from a Saxon extension function.
-
setParams
Set parameters supplied externally (typically, on the command line). (non-TRAX method retained for backwards compatibility)- Parameters:
params
- A ParameterSet containing the (name, value) pairs.
-
clearParameters
public void clearParameters()Reset the parameters to a null list.- Specified by:
clearParameters
in classTransformer
-
getParameter
Get a parameter to the transformation- Specified by:
getParameter
in classTransformer
-
setURIResolver
Set an object that will be used to resolve URIs used in document(), etc.- Specified by:
setURIResolver
in classTransformer
- Parameters:
resolver
- An object that implements the URIResolver interface, or null.
-