Package net.sf.saxon
Class Transform
- java.lang.Object
-
- net.sf.saxon.Transform
-
- Direct Known Subclasses:
DOMTransform
,JDOM2Transform
,Transform
public class Transform extends java.lang.Object
This Transform class is the command-line entry point to the Saxon XSLT Processor.It is possible to subclass this class to provide a customized command line interface. In writing such a subclass:
- The
main(java.lang.String[])
method should instantiate the class and call thedoTransform(java.lang.String[])
method, passing the argument list. The argument list can be augmented or modified if required: for example, by adding a -config argument to cause the configuration to be initialized from a configuration file. - The
initializeConfiguration(net.sf.saxon.Configuration)
method can be implemented to customize the configuration in which the transformation will run.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowExit
protected int
repeat
protected boolean
run
protected boolean
schemaAware
protected boolean
showTime
protected java.lang.String
sourceParserName
protected boolean
useURLs
-
Constructor Summary
Constructors Constructor Description Transform()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyLocalOptions(CommandLineOptions options, Configuration config)
Customisation hook: apply options defined locally in a subclass.protected void
badUsage(java.lang.String message)
Report incorrect usage of the command line, with a list of the options and arguments that are availablevoid
doTransform(java.lang.String[] args)
Support method for main program.void
doTransform(java.lang.String[] args, java.lang.String command)
Support method for main program.protected Configuration
getConfiguration()
Get the configuration.protected void
initializeConfiguration(Configuration config)
Customisation hook called immediately after the Configuration object is instantiated.static void
main(java.lang.String[] args)
Main program, can be used directly from the command line.protected Xslt30Transformer
newTransformer(XsltExecutable sheet, CommandLineOptions options)
Create a new Transformer.protected static long
now()
Get current time in nanosecondsjava.util.List<javax.xml.transform.Source>
preprocess(java.util.List<javax.xml.transform.Source> sources)
Preprocess the list of sources.protected void
processFile(javax.xml.transform.Source source, XsltExecutable sheet, java.io.File outputFile, CommandLineOptions options)
Process a single file using a supplied stylesheetprotected void
quit(java.lang.String message, int code)
Exit with a messagevoid
setFactoryConfiguration(boolean schemaAware, java.lang.String className)
Customisation hook called immediately after the Configuration object is instantiated.void
setPermittedOptions(CommandLineOptions options)
Set the options that are recognized on the command line.
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
Main program, can be used directly from the command line.The format is:
java net.sf.saxon.Transform [options] source-file style-file >output-file
followed by any number of parameters in the form {keyword=value}... which can be referenced from within the stylesheet.
This program applies the XSL style sheet in style-file to the source XML document in source-file.
- Parameters:
args
- List of arguments supplied on operating system command line
-
setPermittedOptions
public void setPermittedOptions(CommandLineOptions options)
Set the options that are recognized on the command line. This method can be overridden in a subclass to define additional command line options.- Parameters:
options
- the CommandLineOptions in which the recognized options are to be registered.
-
doTransform
public void doTransform(java.lang.String[] args)
Support method for main program. This support method can also be invoked from subclasses that support the same command line interface- Parameters:
args
- the command-line arguments
-
doTransform
public void doTransform(java.lang.String[] args, java.lang.String command)
Support method for main program. This support method can also be invoked from subclasses that support the same command line interface- Parameters:
args
- the command-line argumentscommand
- not used, retained for backwards compatibility
-
initializeConfiguration
protected void initializeConfiguration(Configuration config)
Customisation hook called immediately after the Configuration object is instantiated. The intended purpose of this hook is to allow a subclass to supply an OEM license key programmatically, but it can also be used for other initialization of the Configuration. This method is called before analyzing the command line options, so configuration settings made at this stage may be overridden when the command line options are processed. However, if a configuration file is used, the settings defined in the configuration file will have been applied.- Parameters:
config
- the Configuration object
-
setFactoryConfiguration
public void setFactoryConfiguration(boolean schemaAware, java.lang.String className) throws LicenseException
Customisation hook called immediately after the Configuration object is instantiated. This hook is retained for backwards compatibility but it is recommended to implementinitializeConfiguration(net.sf.saxon.Configuration)
in preference. This method is called afterinitializeConfiguration(net.sf.saxon.Configuration)
, but only if the configuration was not created using a configuration file. The default implementation does nothing.- Parameters:
schemaAware
- True if the transformation is to be schema-awareclassName
- Always null.- Throws:
LicenseException
- can be thrown if there is no valid license available
-
applyLocalOptions
protected void applyLocalOptions(CommandLineOptions options, Configuration config)
Customisation hook: apply options defined locally in a subclass. This method allows a subclass to recognize and implement command line options that are not recognized by the superclass. To prevent Saxon rejecting such options as errors, the methodsetPermittedOptions(net.sf.saxon.trans.CommandLineOptions)
must be overridden in the subclass to add details of options recognized in the subclass.- Parameters:
options
- the CommandLineOptions. This will contain details of all the options that were specified on the command line. Those that are recognized by the standard Saxon command line interface will already have been processed; other options can now be processed by the subclass.config
- the Saxon Configuration
-
preprocess
public java.util.List<javax.xml.transform.Source> preprocess(java.util.List<javax.xml.transform.Source> sources) throws XPathException
Preprocess the list of sources. This method exists so that it can be overridden in a subclass, typically to handle kinds of Source implemented as extensions to the basic Saxon capability- Parameters:
sources
- the list of Source objects- Returns:
- a revised list of Source objects
- Throws:
XPathException
- if a Source object is not recognized
-
getConfiguration
protected Configuration getConfiguration()
Get the configuration.- Returns:
- the Saxon configuration
-
quit
protected void quit(java.lang.String message, int code)
Exit with a message- Parameters:
message
- The message to be outputcode
- The result code to be returned to the operating system shell
-
newTransformer
protected Xslt30Transformer newTransformer(XsltExecutable sheet, CommandLineOptions options) throws SaxonApiException
Create a new Transformer. This method is protected so it can be overridden in a subclass, allowing additional options to be set on the Transformer- Parameters:
sheet
- The XsltExecutable object representing the compiled stylesheetoptions
- The commmand line options- Returns:
- the newly constructed Controller to be used for the transformation
- Throws:
SaxonApiException
- if any error occurs
-
now
protected static long now()
Get current time in nanoseconds- Returns:
- the current time in nanoseconds (since VM startup)
-
processFile
protected void processFile(javax.xml.transform.Source source, XsltExecutable sheet, java.io.File outputFile, CommandLineOptions options) throws SaxonApiException
Process a single file using a supplied stylesheet- Parameters:
source
- The source XML document to be transformed (maybe null if an initial template is specified)sheet
- The Templates object identifying the stylesheetoutputFile
- The output file to contain the results of the transformationoptions
- The command line options- Throws:
SaxonApiException
- If the transformation fails
-
badUsage
protected void badUsage(java.lang.String message)
Report incorrect usage of the command line, with a list of the options and arguments that are available- Parameters:
message
- The error message
-
-