Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2013 Saxonica Limited.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package net.sf.saxon;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.expr.instruct.GlobalParameterSet;
import net.sf.saxon.expr.instruct.TerminationException;
import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.lib.TraceListener;
import net.sf.saxon.trace.AbstractTraceListener;
import net.sf.saxon.trace.ExpressionPresenter;
import net.sf.saxon.trace.TimingCodeInjector;
import net.sf.saxon.trace.TimingTraceListener;
import net.sf.saxon.trans.CommandLineOptions;
import net.sf.saxon.trans.CompilerInfo;
import net.sf.saxon.trans.LicenseException;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.DateTimeValue;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import javax.xml.transform.*;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
/**
* 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 {@link #main} method should instantiate the class and call the {@link #doTransform} 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 {@link #setFactoryConfiguration} method can be implemented
*/
public class Transform {
protected Configuration config;
protected CompilerInfo compilerInfo;
protected boolean useURLs = false;
protected boolean showTime = false;
protected int repeat = 1;
/*@Nullable*/ String sourceParserName = null;
boolean schemaAware = false;
boolean allowExit = true;
/**
* Main program, can be used directly from the command line.
*
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.
*
* @param args List of arguments supplied on operating system command line
* @throws java.lang.Exception Indicates that a compile-time or
* run-time error occurred
*/
public static void main(String args[])
throws java.lang.Exception {
// the real work is delegated to another routine so that it can be used in a subclass
(new Transform()).doTransform(args, "java net.sf.saxon.Transform");
}
/**
* Set the options that are recognized on the command line. This method can be overridden in a subclass
* to define additional command line options.
* @param options the CommandLineOptions in which the recognized options are to be registered.
*/
public void setPermittedOptions(CommandLineOptions options) {
options.addRecognizedOption("a", CommandLineOptions.TYPE_BOOLEAN,
"Use processing instruction to identify stylesheet");
options.addRecognizedOption("catalog", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Use specified catalog file to resolve URIs");
options.addRecognizedOption("config", (CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED),
"Use specified configuration file");
options.addRecognizedOption("cr", CommandLineOptions.TYPE_CLASSNAME | CommandLineOptions.VALUE_REQUIRED,
"Use specified collection URI resolver class");
options.addRecognizedOption("dtd", CommandLineOptions.TYPE_ENUMERATION,
"Validate using DTD");
options.setPermittedValues("dtd", new String[]{"on","off","recover"}, "on");
options.addRecognizedOption("expand", CommandLineOptions.TYPE_BOOLEAN,
"Expand attribute defaults from DTD or Schema");
options.addRecognizedOption("explain", CommandLineOptions.TYPE_FILENAME,
"Display compiled expression tree and optimization decisions");
options.addRecognizedOption("ext", CommandLineOptions.TYPE_BOOLEAN,
"Allow calls to Java extension functions and xsl:result-document");
options.addRecognizedOption("im", CommandLineOptions.TYPE_QNAME | CommandLineOptions.VALUE_REQUIRED,
"Name of initial mode");
options.addRecognizedOption("init", CommandLineOptions.TYPE_CLASSNAME,
"User-supplied net.sf.saxon.lib.Initializer class to initialize the Saxon Configuration");
options.addRecognizedOption("it", CommandLineOptions.TYPE_QNAME | CommandLineOptions.VALUE_REQUIRED,
"Name of initial template");
options.addRecognizedOption("l", CommandLineOptions.TYPE_BOOLEAN,
"Maintain line numbers for source documents");
options.addRecognizedOption("m", CommandLineOptions.TYPE_CLASSNAME,
"Use named class to handle xsl:message output");
options.addRecognizedOption("now", CommandLineOptions.TYPE_DATETIME | CommandLineOptions.VALUE_REQUIRED,
"Run with specified current date/time");
options.addRecognizedOption("o", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Use specified file for primary output");
options.addRecognizedOption("opt", CommandLineOptions.TYPE_INTEGER | CommandLineOptions.VALUE_REQUIRED,
"Use optimization level 0..10");
options.addRecognizedOption("or", CommandLineOptions.TYPE_CLASSNAME | CommandLineOptions.VALUE_REQUIRED,
"Use named OutputURIResolver class");
options.addRecognizedOption("outval", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Action when validation of output file fails");
options.setPermittedValues("outval", new String[]{"recover","fatal"}, null);
options.addRecognizedOption("p", CommandLineOptions.TYPE_BOOLEAN,
"Recognize query parameters in URI passed to doc()");
options.addRecognizedOption("quit", CommandLineOptions.TYPE_BOOLEAN | CommandLineOptions.VALUE_REQUIRED,
"Quit JVM if transformation fails");
options.addRecognizedOption("r", CommandLineOptions.TYPE_CLASSNAME | CommandLineOptions.VALUE_REQUIRED,
"Use named URIResolver class");
options.addRecognizedOption("repeat", CommandLineOptions.TYPE_INTEGER | CommandLineOptions.VALUE_REQUIRED,
"Run N times for performance measurement");
options.addRecognizedOption("s", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Source file for primary input");
options.addRecognizedOption("sa", CommandLineOptions.TYPE_BOOLEAN,
"Run in schema-aware mode");
options.addRecognizedOption("strip", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Handling of whitespace text nodes in source documents");
options.setPermittedValues("strip", new String[]{"none","all","ignorable"}, null);
options.addRecognizedOption("t", CommandLineOptions.TYPE_BOOLEAN,
"Display version and timing information, and names of output files");
options.addRecognizedOption("T", CommandLineOptions.TYPE_CLASSNAME,
"Use named TraceListener class, or standard TraceListener");
options.addRecognizedOption("TJ", CommandLineOptions.TYPE_BOOLEAN,
"Debug binding and execution of extension functions");
options.setPermittedValues("TJ", new String[]{"on","off"}, "on");
options.addRecognizedOption("TP", CommandLineOptions.TYPE_FILENAME,
"Use profiling trace listener, with specified output file");
options.addRecognizedOption("threads", CommandLineOptions.TYPE_INTEGER | CommandLineOptions.VALUE_REQUIRED,
"Run stylesheet on directory of files divided in N threads");
options.addRecognizedOption("tree", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Use specified tree model for source documents");
options.setPermittedValues("tree", new String[]{"linked","tiny","tinyc"}, null);
options.addRecognizedOption("traceout", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"File for output of trace() and -T output");
options.addRecognizedOption("u", CommandLineOptions.TYPE_BOOLEAN,
"Interpret filename arguments as URIs");
options.setPermittedValues("u", new String[]{"on","off"}, "on");
options.addRecognizedOption("val", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Apply validation to source documents");
options.setPermittedValues("val", new String[]{"strict","lax"}, "strict");
options.addRecognizedOption("versionmsg", CommandLineOptions.TYPE_BOOLEAN,
"Output warning when stylesheet specifies version='1.0");
options.addRecognizedOption("warnings", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Handling of recoverable dynamic errors");
options.setPermittedValues("warnings", new String[]{"silent","recover","fatal"}, null);
options.addRecognizedOption("x", CommandLineOptions.TYPE_CLASSNAME | CommandLineOptions.VALUE_REQUIRED,
"Use named XMLReader class for parsing source documents");
options.addRecognizedOption("xi", CommandLineOptions.TYPE_BOOLEAN,
"Expand XInclude directives in source documents");
options.addRecognizedOption("xmlversion", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Indicate whether XML 1.1 is supported");
options.setPermittedValues("xmlversion", new String[]{"1.0","1.1"}, null);
options.addRecognizedOption("xsd", CommandLineOptions.TYPE_FILENAME_LIST | CommandLineOptions.VALUE_REQUIRED,
"List of schema documents to be preloaded");
options.addRecognizedOption("xsdversion", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Indicate whether XSD 1.1 is supported");
options.setPermittedValues("xsdversion", new String[]{"1.0","1.1"}, null);
options.addRecognizedOption("xsiloc", CommandLineOptions.TYPE_BOOLEAN,
"Load schemas named in xsi:schemaLocation (default on)");
options.addRecognizedOption("xsl", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Stylesheet file");
options.addRecognizedOption("xsltversion", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Indicate whether the XSLT processor should support XSLT 2.0 or XSLT 3.0");
options.setPermittedValues("xsltversion", new String[]{"0.0","2.0","2.1","3.0"}, null);
options.addRecognizedOption("y", CommandLineOptions.TYPE_CLASSNAME | CommandLineOptions.VALUE_REQUIRED,
"Use named XMLReader class for parsing stylesheet and schema documents");
options.addRecognizedOption("?", CommandLineOptions.VALUE_PROHIBITED,
"Display command line help text");
}
class TransformThread extends Thread{
private File outputDir;
private Templates sheet;
private CommandLineOptions options;
private PrintStream traceDestination;
private List