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) 2018-2023 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.expr.instruct.GlobalContextRequirement;
import net.sf.saxon.expr.instruct.TerminationException;
import net.sf.saxon.lib.*;
import net.sf.saxon.s9api.*;
import net.sf.saxon.str.BMPString;
import net.sf.saxon.style.Compilation;
import net.sf.saxon.style.StylesheetPackage;
import net.sf.saxon.trace.*;
import net.sf.saxon.trans.Timer;
import net.sf.saxon.trans.*;
import net.sf.saxon.trans.packages.PackageDetails;
import net.sf.saxon.trans.packages.PackageLibrary;
import net.sf.saxon.transpile.CSharp;
import net.sf.saxon.transpile.CSharpModifiers;
import net.sf.saxon.transpile.CSharpReplaceBody;
import net.sf.saxon.value.DateTimeValue;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
* 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 #initializeConfiguration} method can be implemented to customize the configuration in which
* the transformation will run.
*
*/
public class Transform {
private Processor processor;
private XsltCompiler compiler;
protected boolean useURLs = false;
protected boolean showTime = false;
protected int repeat = 1;
protected String sourceParserName = null;
protected boolean schemaAware = false;
protected boolean allowExit = true;
protected boolean run = true;
private Logger traceDestination = new StandardLogger();
private boolean closeTraceDestination = false;
/**
* 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
*/
public static void main(String[] args) {
// the real work is delegated to another routine so that it can be used in a subclass
new Transform().doTransform(args);
}
/**
* 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.
*/
@CSharpModifiers(code = {"internal"})
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("diag", CommandLineOptions.TYPE_FILENAME,
"Display runtime diagnostics");
options.addRecognizedOption("dtd", CommandLineOptions.TYPE_ENUMERATION,
"Validate using DTD");
options.setPermittedValues("dtd", new String[]{"on", "off", "recover"}, "on");
options.addRecognizedOption("ea", CommandLineOptions.TYPE_BOOLEAN,
"Enable assertions");
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 in human-readable form");
options.addRecognizedOption("export", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Export compiled stylesheet to specified SEF file");
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 code to initialize the Saxon Configuration");
options.addRecognizedOption("it", CommandLineOptions.TYPE_QNAME,
"Name of initial template");
options.addRecognizedOption("jit", CommandLineOptions.TYPE_BOOLEAN,
"Enable just-in-time compilation");
options.addRecognizedOption("json", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Source JSON file for primary input");
options.addRecognizedOption("l", CommandLineOptions.TYPE_BOOLEAN,
"Maintain line numbers for source documents");
options.addRecognizedOption("lib", CommandLineOptions.TYPE_FILENAME_LIST | CommandLineOptions.VALUE_REQUIRED,
"List of file names of library packages used by the stylesheet");
options.addRecognizedOption("license", CommandLineOptions.TYPE_BOOLEAN,
"Check for local license file");
// options.addRecognizedOption("m", CommandLineOptions.TYPE_CLASSNAME,
// "Use named class to handle xsl:message output");
options.addRecognizedOption("nogo", CommandLineOptions.TYPE_BOOLEAN,
"Compile only, no evaluation");
options.addRecognizedOption("now", CommandLineOptions.TYPE_DATETIME | CommandLineOptions.VALUE_REQUIRED,
"Run with specified current date/time");
options.addRecognizedOption("ns", CommandLineOptions.TYPE_STRING | CommandLineOptions.VALUE_REQUIRED,
"Default namespace for element names (URI, or ##any, or ##html5)");
options.addRecognizedOption("o", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Use specified file for primary output");
options.addRecognizedOption("opt", CommandLineOptions.TYPE_STRING | CommandLineOptions.VALUE_REQUIRED,
"Enable/disable optimization options [-]cfgjklmnrsvwx");
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("relocate", CommandLineOptions.TYPE_BOOLEAN,
"Produce relocatable packages");
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 XML file for primary input");
options.addRecognizedOption("sa", CommandLineOptions.TYPE_BOOLEAN,
"Run in schema-aware mode");
options.addRecognizedOption("scmin", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Pre-load schema in SCM format");
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("target", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"Target Saxon edition for execution via -export");
options.setPermittedValues("target", new String[]{"EE", "PE", "HE", "JS", "JS2", "JS3"}, null);
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("Tlevel", CommandLineOptions.TYPE_STRING,
"Level of detail for trace listener output");
options.setPermittedValues("Tlevel", new String[]{"none", "low", "normal", "high"}, "normal");
options.addRecognizedOption("Tout", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"File for trace listener output");
options.addRecognizedOption("TP", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Use profiling trace listener, with specified output file");
options.addRecognizedOption("TPxsl", CommandLineOptions.TYPE_FILENAME | CommandLineOptions.VALUE_REQUIRED,
"Stylesheet for formatting -TP output");
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,
"Apply validation to source documents");
options.setPermittedValues("val", new String[]{"strict", "lax"}, "strict");
options.addRecognizedOption("versionmsg", CommandLineOptions.TYPE_BOOLEAN,
"No longer used");
options.addRecognizedOption("warnings", CommandLineOptions.TYPE_ENUMERATION | CommandLineOptions.VALUE_REQUIRED,
"No longer used");
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,
"Main stylesheet file");
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");
}
private static class TransformThread extends Thread {
private final Transform transform;
private final File outputDir;
private final XsltExecutable sheet;
private final CommandLineOptions options;
private final List