public class Processor extends Object
A processor is first configured either manually by populating
processing step list stepList
and parameter map
parameterMap
or automatically by invoking method configure(java.lang.String[])
.
A processor can then be used to perform a conversion by invoking
process(Object,File,ProgressMonitor)
or (lower-level method)
executeSteps(Object,Map,ProgressMonitor)
.
A processor must not be shared between threads.
Modifier and Type | Field and Description |
---|---|
protected static String |
optionsHelp |
Map<String,String> |
parameterMap
Parameters used to parameterize the conversion.
|
List<ProcessStep> |
stepList
The list of processing steps executed in turn by this processor
to perform the conversion.
|
Constructor and Description |
---|
Processor()
Contructs a processor having no processing steps and
no conversion parameters.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addShorthand(List<String> argList,
String shorthand,
String param) |
int |
configure(String[] args)
Initializes
stepList and parameterMap by parsing
specified arguments. |
protected int |
configure(String[] args,
StringBuilder optionList) |
Object |
executeSteps(Object input,
Map<String,String> parameters,
ProgressMonitor monitor)
Executes the processing steps contained in
stepList
passing them the parameters contained in parameterMap . |
static String |
fileURLToPath(String path)
Utility needed to use XSLT element extension
saxon:output
converting specified absolute file: URI to
a native absolute file path (possibly containing accented characters). |
protected static String |
fileVarValue(File file,
String modifiers) |
protected static String |
getOptionsHelp() |
static Plugin |
getPlugin(String name)
Returns plugin having specified name if registered;
null otherwiise. |
static Plugin[] |
getPlugins()
Returns the list of registered plugins; a possibly empty array.
|
int |
indexOfStep(String stepName)
Returns the index within
stepList of the processing step
having specified name. |
static void |
initResolver(URL resourceDirURL)
Adds a "w2x:" entry pointing to specified URL
to the XML catalogs used by processors to resolve URLs.
|
static String[] |
loadOptionsFile(File optionsFile)
Loads the w2x command-line options contained in specified file.
|
protected static void |
loadOptionsFile(URL optionsFileURL,
List<String> argList) |
static String[] |
parseOptions(String options,
URL baseURL)
Parse specified w2x command-line options.
|
protected static void |
parseOptions(String options,
URL optionsFileURL,
List<String> argList) |
Object |
process(Object input,
File outFile,
ProgressMonitor monitor)
Executes the processing steps contained in
stepList
passing them the parameters contained in parameterMap . |
static void |
registerPlugins(Plugin... plugins)
Register specified plugins.
|
static String[] |
splitOptions(String options) |
protected static String |
substituteVars(String text,
File inFile,
File outFile,
Map<String,String> params) |
protected static void |
updateOptionsHelp(Plugin[] plugins) |
protected static URL |
urlOrFile(String path,
URL optionsFileURL) |
protected static String |
urlVarValue(URL url,
String modifiers) |
protected static void |
usage(String error,
URL errorURL) |
protected static String optionsHelp
public final List<ProcessStep> stepList
public Processor()
public static final void initResolver(URL resourceDirURL)
resourceDirURL
- the URL of the directory having
xed/ and xslt/ subdirectories.
May be null
, in which case it is set
to resource /w2x_resources. That is, the
xed/ and xslt/ subdirectories are expected
to be found in w2x_all.jar.
public static final void registerPlugins(Plugin... plugins)
getPlugins()
,
getPlugin(java.lang.String)
public static final Plugin[] getPlugins()
public static final Plugin getPlugin(String name)
null
otherwiise.protected static final void updateOptionsHelp(Plugin[] plugins)
protected static final String getOptionsHelp()
public int indexOfStep(String stepName)
stepList
of the processing step
having specified name. Returns -1 if such step is not found.public int configure(String[] args) throws UsageException
stepList
and parameterMap
by parsing
specified arguments.args
- arguments specifying the conversion.
This arguments are parsed exactly like the arguments of the w2x command-line utility are. Therefore please refer to the documentation of the w2x command-line utility to learn which arguments should be passed to this method.
UsageException
- if the contents of the args array
cannot be successfully parsedprotected int configure(String[] args, StringBuilder optionList) throws UsageException
UsageException
protected static void usage(String error, URL errorURL) throws UsageException
UsageException
protected static void loadOptionsFile(URL optionsFileURL, List<String> argList) throws UsageException
UsageException
protected static void parseOptions(String options, URL optionsFileURL, List<String> argList) throws UsageException
UsageException
protected static URL urlOrFile(String path, URL optionsFileURL) throws UsageException
UsageException
protected void addShorthand(List<String> argList, String shorthand, String param) throws UsageException
UsageException
public static String[] loadOptionsFile(File optionsFile) throws UsageException
The result of this utility method may be passed to configure(java.lang.String[])
.
optionsFile
- a plain text, UTF-8 encoded, file containing
w2x command-line optionsUsageException
- if, for any reason,
the contents of specified file cannot be loaded or parsedparseOptions(String, URL)
public static String[] parseOptions(String options, URL baseURL) throws UsageException
The result of this utility method may be passed to configure(java.lang.String[])
.
options
- options to be parsedbaseURL
- URL used to resolve relative URLs.
May be null
.UsageException
- if, specified options cannot be parsedloadOptionsFile(File)
public Object process(Object input, File outFile, ProgressMonitor monitor) throws Exception
stepList
passing them the parameters contained in parameterMap
.input
- the Document
or
the File
which is the input of the conversionoutFile
- the File
which is the output of the conversion.
May be null
.
outFile is used to finish configuring the processing steps by adding implicit parameters such as convert.xhtml-file, transform.out-file or save.out-file.
monitor
- used to monitor the progress of the processing steps.
May be null
.Document
or
the File
which is the result/output of the conversionException
- if for any reason, this method failsexecuteSteps(Object,Map,ProgressMonitor)
protected static final String substituteVars(String text, File inFile, File outFile, Map<String,String> params)
public static final String fileURLToPath(String path)
saxon:output
converting specified absolute file: URI to
a native absolute file path (possibly containing accented characters).
This utility is needed to workaround the following Saxon 6.5 limitation:
Saxon 6.5 interprets thehref
attribute ofsaxon:output
as a filename relative to the current working directory. You can use an absolute filename if you want, but not an absolute URI. This is a documented restriction, not a bug.
public Object executeSteps(Object input, Map<String,String> parameters, ProgressMonitor monitor) throws Exception
stepList
passing them the parameters contained in parameterMap
.input
- the Document
or
the File
which is the input of the conversionparameters
- all the parameters passed to this processor.
Variables, if any, are expected to have been substituted in the parameter values.
monitor
- used to monitor the progress of the processing steps.
May be null
.Document
or
the File
which is the result/output of the conversionException
- if for any reason, this method failsprocess(Object,File,ProgressMonitor)