// Patched by John Cowan to add -H option to invoke TagSoup parser package com.icl.saxon; import com.icl.saxon.tree.TreeBuilder; import com.icl.saxon.tinytree.TinyBuilder; import com.icl.saxon.om.Builder; import com.icl.saxon.om.Navigator; import com.icl.saxon.om.DocumentInfo; import com.icl.saxon.om.Namespace; import com.icl.saxon.om.NamePool; import com.icl.saxon.expr.*; import com.icl.saxon.style.*; import com.icl.saxon.output.*; import com.icl.saxon.trace.*; import com.icl.saxon.style.TerminationException; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.*; import org.w3c.dom.Node; import org.w3c.dom.Document; import java.util.*; import java.io.*; import java.net.URL; import java.net.MalformedURLException; import javax.xml.transform.*; import javax.xml.transform.sax.*; import javax.xml.transform.stream.*; /** * This StyleSheet class is the entry point to the Saxon XSLT Processor. This * class is provided to control the processor from the command line.
* * The XSLT syntax supported conforms to the W3C XSLT 1.0 and XPath 1.0 recommendation. * Only the transformation language is implemented (not the formatting objects). * Saxon extensions are documented in the file extensions.html * * @author M.H.Kay (mhkay@iclway.co.uk) * @author John Cowan (cowan@ccil.org) */ public class StyleSheet { protected TransformerFactoryImpl factory = new TransformerFactoryImpl(); protected NamePool namePool = NamePool.getDefaultNamePool(); boolean showTime = false; int repeat = 1; /** * Main program, can be used directly from the command line. *
The format is:
*java com.icl.saxon.StyleSheet [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.
*/ 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 StyleSheet()).doMain(args, new StyleSheet(), " java com.icl.saxon.StyleSheet"); } /** * Support method for main program. This support method can also be invoked from subclasses * that support the same command line interface * @param args the command-line arguments * @param app instance of the StyleSheet class (or a subclass) to be invoked * @param name name of the class, to be used in error messages */ protected void doMain(String args[], StyleSheet app, String name) { String sourceFileName = null; String styleFileName = null; File sourceFile = null; File styleFile = null; File outputFile = null; boolean useURLs = false; ParameterSet params = new ParameterSet(); Properties outputProperties = new Properties(); String outputFileName = null; boolean useAssociatedStylesheet = false; boolean wholeDirectory = false; // Check the command-line arguments. try { int i = 0; while (true) { if (i>=args.length) badUsage(name, "No source file name"); if (args[i].charAt(0)=='-') { if (args[i].equals("-a")) { useAssociatedStylesheet = true; i++; } else if (args[i].equals("-ds")) { factory.setAttribute( FeatureKeys.TREE_MODEL, new Integer(Builder.STANDARD_TREE)); i++; } else if (args[i].equals("-dt")) { factory.setAttribute( FeatureKeys.TREE_MODEL, new Integer(Builder.TINY_TREE)); i++; } else if (args[i].equals("-l")) { factory.setAttribute( FeatureKeys.LINE_NUMBERING, new Boolean(true)); i++; } else if (args[i].equals("-u")) { useURLs = true; i++; } else if (args[i].equals("-t")) { System.err.println(Version.getProductName()); System.err.println("Java version " + System.getProperty("java.version")); factory.setAttribute( FeatureKeys.TIMING, new Boolean(true)); Loader.setTracing(true); showTime = true; i++; } else if (args[i].equals("-3")) { // undocumented option: do it thrice i++; repeat = 3; } else if (args[i].equals("-9")) { // undocumented option: do it nine times i++; repeat = 9; } else if (args[i].equals("-o")) { i++; if (args.length < i+2) badUsage(name, "No output file name"); outputFileName = args[i++]; } else if (args[i].equals("-x")) { i++; if (args.length < i+2) badUsage(name, "No source parser class"); String sourceParserName = args[i++]; factory.setAttribute( FeatureKeys.SOURCE_PARSER_CLASS, sourceParserName); } else if (args[i].equals("-H")) { i++; String sourceParserName = "org.ccil.cowan.tagsoup.Parser"; factory.setAttribute( FeatureKeys.SOURCE_PARSER_CLASS, sourceParserName); } else if (args[i].equals("-y")) { i++; if (args.length < i+2) badUsage(name, "No style parser class"); String styleParserName = args[i++]; factory.setAttribute( FeatureKeys.STYLE_PARSER_CLASS, styleParserName); } else if (args[i].equals("-r")) { i++; if (args.length < i+2) badUsage(name, "No URIResolver class"); String r = args[i++]; factory.setURIResolver(makeURIResolver(r)); } else if (args[i].equals("-T")) { i++; TraceListener traceListener = new com.icl.saxon.trace.SimpleTraceListener(); factory.setAttribute( FeatureKeys.TRACE_LISTENER, traceListener); factory.setAttribute( FeatureKeys.LINE_NUMBERING, Boolean.TRUE); } else if (args[i].equals("-TL")) { i++; if (args.length < i+2) badUsage(name, "No TraceListener class"); TraceListener traceListener = makeTraceListener(args[i++]); factory.setAttribute( FeatureKeys.TRACE_LISTENER, traceListener); factory.setAttribute( FeatureKeys.LINE_NUMBERING, Boolean.TRUE); } else if (args[i].equals("-w0")) { i++; factory.setAttribute( FeatureKeys.RECOVERY_POLICY, new Integer(Controller.RECOVER_SILENTLY)); } else if (args[i].equals("-w1")) { i++; factory.setAttribute( FeatureKeys.RECOVERY_POLICY, new Integer(Controller.RECOVER_WITH_WARNINGS)); } else if (args[i].equals("-w2")) { i++; factory.setAttribute( FeatureKeys.RECOVERY_POLICY, new Integer(Controller.DO_NOT_RECOVER)); } else if (args[i].equals("-m")) { i++; if (args.length < i+2) badUsage(name, "No message Emitter class"); factory.setAttribute( FeatureKeys.MESSAGE_EMITTER_CLASS, args[i++]); } else if (args[i].equals("-noext")) { i++; factory.setAttribute( FeatureKeys.ALLOW_EXTERNAL_FUNCTIONS, new Boolean(false)); } else badUsage(name, "Unknown option " + args[i]); } else break; } if (args.length < i+1 ) badUsage(name, "No source file name"); sourceFileName = args[i++]; if (!useAssociatedStylesheet) { if (args.length < i+1 ) badUsage(name, "No stylesheet file name"); styleFileName = args[i++]; } for (int p=i; p