/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: Process.java,v 1.2.4.2 2005/09/15 18:21:57 jeffsuttor Exp $
*/
//J2SE does not support Xalan interpretive
/*
import com.sun.org.apache.xalan.internal.trace.PrintTraceListener;
import com.sun.org.apache.xalan.internal.trace.TraceManager;
import com.sun.org.apache.xalan.internal.transformer.XalanProperties;
*/
/**
* The main() method handles the Xalan command-line interface.
* @xsl.usage general
*/
public class Process
{
/**
* Prints argument options.
*
* @param resbundle Resource bundle
*/
{
// System.out.println(resbundle.getString("optionE")); //" [-E (Do not expand entity refs)]");
// System.out.println(resbundle.getString("optionVALIDATE")); //" [-VALIDATE (Set whether validation occurs. Validation is off by default.)]");
System.out.println(resbundle.getString("optionEDUMP")); //" [-EDUMP {optional filename} (Do stackdump on error.)]");
System.out.println(resbundle.getString("optionXML")); //" [-XML (Use XML formatter and add XML header.)]");
System.out.println(resbundle.getString("optionPARAM")); //" [-PARAM name expression (Set a stylesheet parameter)]");
System.out.println(resbundle.getString("optionURIRESOLVER")); //" [-URIRESOLVER full class name (URIResolver to be used to resolve URIs)]");
System.out.println(resbundle.getString("optionENTITYRESOLVER")); //" [-ENTITYRESOLVER full class name (EntityResolver to be used to resolve entities)]");
System.out.println(resbundle.getString("optionCONTENTHANDLER")); //" [-CONTENTHANDLER full class name (ContentHandler to be used to serialize output)]");
System.out.println(resbundle.getString("optionSECUREPROCESSING")); //" [-SECURE (set the secure processing feature to true)]");
// J2SE does not support Xalan interpretive
/*
System.out.println("\n\t\t\t" + resbundle.getString("xslProc_xalan_options") + "\n");
System.out.println(resbundle.getString("optionQC")); //" [-QC (Quiet Pattern Conflicts Warnings)]");
// System.out.println(resbundle.getString("optionQ")); //" [-Q (Quiet Mode)]"); // sc 28-Feb-01 commented out
System.out.println(resbundle.getString("optionTT")); //" [-TT (Trace the templates as they are being called.)]");
System.out.println(resbundle.getString("optionTG")); //" [-TG (Trace each generation event.)]");
System.out.println(resbundle.getString("optionTS")); //" [-TS (Trace each selection event.)]");
System.out.println(resbundle.getString("optionTTC")); //" [-TTC (Trace the template children as they are being processed.)]");
System.out.println(resbundle.getString("optionTCLASS")); //" [-TCLASS (TraceListener class for trace extensions.)]");
System.out.println(resbundle.getString("optionLINENUMBERS")); //" [-L use line numbers]"
System.out.println(resbundle.getString("optionINCREMENTAL"));
System.out.println(resbundle.getString("optionNOOPTIMIMIZE"));
System.out.println(resbundle.getString("optionRL"));
*/
}
/**
* Command line interface to transform an XML document according to
* the instructions found in an XSL stylesheet.
* <p>The Process class provides basic functionality for
* performing transformations from the command line. To see a
* list of arguments supported, call with zero arguments.</p>
* <p>To set stylesheet parameters from the command line, use
* <code>-PARAM name expression</code>. If you want to set the
* parameter to a string value, simply pass the string value
* as-is, and it will be interpreted as a string. (Note: if
* the value has spaces in it, you may need to quote it depending
* on your shell environment).</p>
*
* @param argv Input parameters from command line
*/
// J2SE does not support Xalan interpretive
// main -> _main
{
// Runtime.getRuntime().traceMethodCalls(false); // turns Java tracing off
boolean doStackDumpOnError = false;
boolean setQuietMode = false;
boolean doDiag = false;
boolean isSecureProcessing = false;
// Runtime.getRuntime().traceMethodCalls(false);
// Runtime.getRuntime().traceInstructions(false);
/**
* The default diagnostic writer...
*/
{
}
else
{
// J2SE does not support Xalan interpretive
// false -> true
boolean useXSLTC = true;
{
{
useXSLTC = true;
}
}
if (useXSLTC)
{
}
try
{
}
{
// "XSL Process was not successful.");
}
boolean formatOutput = false;
boolean useSourceLocation = false;
// J2SE does not support Xalan interpretive
/*
PrintTraceListener tracer = null;
*/
boolean quietConflictWarnings = false;
int recursionLimit=-1;
{
{
// The -XSLTC option has been processed.
}
// J2SE does not support Xalan interpretive
/*
else if ("-TT".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
{
if (null == tracer)
tracer = new PrintTraceListener(diagnosticsWriter);
tracer.m_traceTemplates = true;
}
else
printInvalidXSLTCOption("-TT");
// tfactory.setTraceTemplates(true);
}
else if ("-TG".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
{
if (null == tracer)
tracer = new PrintTraceListener(diagnosticsWriter);
tracer.m_traceGeneration = true;
}
else
printInvalidXSLTCOption("-TG");
// tfactory.setTraceSelect(true);
}
else if ("-TS".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
{
if (null == tracer)
tracer = new PrintTraceListener(diagnosticsWriter);
tracer.m_traceSelection = true;
}
else
printInvalidXSLTCOption("-TS");
// tfactory.setTraceTemplates(true);
}
else if ("-TTC".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
{
if (null == tracer)
tracer = new PrintTraceListener(diagnosticsWriter);
tracer.m_traceElements = true;
}
else
printInvalidXSLTCOption("-TTC");
// tfactory.setTraceTemplateChildren(true);
}
*/
{
int indentAmount;
{
}
else
{
indentAmount = 0;
}
// TBD:
// xmlProcessorLiaison.setIndent(indentAmount);
}
{
inFileName = argv[++i];
else
}
{
else
}
{
outFileName = argv[++i];
else
}
{
xslFileName = argv[++i];
else
}
{
{
}
else
}
{
{
}
else
}
{
// TBD:
// xmlProcessorLiaison.setShouldExpandEntityRefs(false);
}
{
/* xmlProcessorLiaison.getParserDescription()+ */
}
// J2SE does not support Xalan interpretive
/*
else if ("-QC".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
quietConflictWarnings = true;
else
printInvalidXSLTCOption("-QC");
}
*/
{
setQuietMode = true;
}
{
doDiag = true;
}
{
outputType = "xml";
}
{
outputType = "text";
}
{
outputType = "html";
}
{
doStackDumpOnError = true;
{
dumpFileName = argv[++i];
}
}
{
{
try
{
}
catch (ConfigurationError cnfe)
{
new Object[]{ "-URIResolver" });
}
}
else
{
}
}
{
{
try
{
}
catch (ConfigurationError cnfe)
{
new Object[]{ "-EntityResolver" });
}
}
else
{
// "Missing argument for);
new Object[]{ "-EntityResolver" });
}
}
{
{
try
{
}
catch (ConfigurationError cnfe)
{
new Object[]{ "-ContentHandler" });
}
}
else
{
// "Missing argument for);
new Object[]{ "-ContentHandler" });
}
}
// J2SE does not support Xalan interpretive
/*
else if ("-L".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
tfactory.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
else
printInvalidXSLTCOption("-L");
}
else if ("-INCREMENTAL".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
tfactory.setAttribute
java.lang.Boolean.TRUE);
else
printInvalidXSLTCOption("-INCREMENTAL");
}
else if ("-NOOPTIMIZE".equalsIgnoreCase(argv[i]))
{
// Default is true.
//
// %REVIEW% We should have a generalized syntax for negative
// switches... and probably should accept the inverse even
// if it is the default.
if (!useXSLTC)
tfactory.setAttribute
java.lang.Boolean.FALSE);
else
printInvalidXSLTCOption("-NOOPTIMIZE");
}
else if ("-RL".equalsIgnoreCase(argv[i]))
{
if (!useXSLTC)
{
if (i + 1 < argv.length)
recursionLimit = Integer.parseInt(argv[++i]);
else
System.err.println(
XSLMessages.createMessage(
XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
new Object[]{ "-rl" })); //"Missing argument for);
}
else
{
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-')
i++;
printInvalidXSLTCOption("-RL");
}
}
*/
// Generate the translet class and optionally specify the name
// of the translet class.
{
if (useXSLTC)
{
{
}
else
}
else
{
i++;
printInvalidXalanOption("-XO");
}
}
// Specify the destination directory for the translet classes.
{
if (useXSLTC)
{
else
}
else
{
i++;
printInvalidXalanOption("-XD");
}
}
// Specify the jar file name which the translet classes are packaged into.
{
if (useXSLTC)
{
{
}
else
}
else
{
i++;
printInvalidXalanOption("-XJ");
}
}
// Specify the package name prefix for the generated translet classes.
{
if (useXSLTC)
{
else
}
else
{
i++;
printInvalidXalanOption("-XP");
}
}
// Enable template inlining.
{
if (useXSLTC)
{
}
else
printInvalidXalanOption("-XN");
}
// Turns on additional debugging message output
{
if (useXSLTC)
{
}
else
printInvalidXalanOption("-XX");
}
// Create the Transformer from the translet if the translet class is newer
// than the stylesheet.
{
if (useXSLTC)
{
}
else
printInvalidXalanOption("-XT");
}
{
isSecureProcessing = true;
try
{
}
catch (TransformerConfigurationException e) {}
}
else
}
// Print usage instructions if no xml and xsl file is specified in the command line
{
}
// Note that there are usage cases for calling us without a -IN arg
// The main XSL transformation occurs here!
try
{
if (null != dumpFileName)
{
}
if (null != xslFileName)
{
{
// Parse in the xml data into a DOM
dfactory.setNamespaceAware(true);
if (isSecureProcessing)
{
try
{
}
catch (ParserConfigurationException pce) {}
}
xslFileName));
}
else
{
// System.out.println("Calling newTemplates: "+xslFileName);
// System.out.println("Done calling newTemplates: "+xslFileName);
}
}
if (null != outFileName)
{
// One possible improvement might be to ensure this is
// a valid URI before setting the systemId, but that
// might have subtle changes that pre-existing users
// might notice; we can think about that later -sc r1.46
}
else
{
// We used to default to incremental mode in this case.
// We've since decided that since the -INCREMENTAL switch is
// available, that default is probably not necessary nor
// necessarily a good idea.
}
// J2SE does not support Xalan interpretive
/*
// This is currently controlled via TransformerFactoryImpl.
if (!useXSLTC && useSourceLocation)
stf.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
*/
// Did they pass in a stylesheet, or should we get it from the
// document?
if (null == stylesheet)
{
else
{
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_IN_MEDIA, new Object[]{inFileName, media})); //"No stylesheet found in: "
// + inFileName + ", media="
// + media);
else
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_PI, new Object[]{inFileName})); //"No xml-stylesheet PI found in: "
//+ inFileName);
}
}
if (null != stylesheet)
{
// Override the output format?
if (null != outputType)
{
}
// J2SE does not support Xalan interpretive
/*
if (transformer instanceof com.sun.org.apache.xalan.internal.transformer.TransformerImpl)
{
com.sun.org.apache.xalan.internal.transformer.TransformerImpl impl = (com.sun.org.apache.xalan.internal.transformer.TransformerImpl)transformer;
TraceManager tm = impl.getTraceManager();
if (null != tracer)
tm.addTraceListener(tracer);
impl.setQuietConflictWarnings(quietConflictWarnings);
// This is currently controlled via TransformerFactoryImpl.
if (useSourceLocation)
impl.setProperty(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
if(recursionLimit>0)
impl.setRecursionLimit(recursionLimit);
// sc 28-Feb-01 if we re-implement this, please uncomment helpmsg in printArgOptions
// impl.setDiagnosticsOutput( setQuietMode ? null : diagnosticsWriter );
}
*/
{
}
if (uriResolver != null)
if (null != inFileName)
{
{
// Parse in the xml data into a DOM
dfactory.setCoalescing(true);
dfactory.setNamespaceAware(true);
if (isSecureProcessing)
{
try
{
}
catch (ParserConfigurationException pce) {}
}
if (entityResolver != null)
// Now serialize output to disk with identity transformer
if (contentHandler != null)
{
}
else
}
{
for (int i = 0; i < 1; i++) // Loop for diagnosing bugs with inconsistent behavior
{
// System.out.println("Testing the TransformerHandler...");
// Use JAXP1.1 ( if possible )
try
{
factory.setNamespaceAware(true);
if (isSecureProcessing)
{
try
{
}
}
}
{
}
{
}
catch (NoSuchMethodError ex2){}
catch (AbstractMethodError ame){}
{
}
// J2SE does not support Xalan interpretive
/*
if (!useXSLTC)
stf.setAttribute(com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl.FEATURE_INCREMENTAL,
Boolean.TRUE);
*/
try
{
}
try
{
true);
}
}
else
{
if (entityResolver != null)
{
// Use JAXP1.1 ( if possible )
try
{
factory.setNamespaceAware(true);
if (isSecureProcessing)
{
try
{
}
}
}
{
}
{
}
catch (NoSuchMethodError ex2){}
catch (AbstractMethodError ame){}
{
}
if (contentHandler != null)
{
result);
}
else
{
}
}
else if (contentHandler != null)
{
}
else
{
// System.out.println("Starting transform");
// System.out.println("Done with transform");
}
}
}
else
{
new StringReader("<?xml version=\"1.0\"?> <doc/>");
}
}
else
{
// "XSL Process was not successful.");
}
// close output streams
{
try
{
}
}
if (doDiag)
{
}
}
{
while (throwable
{
}
if ((throwable instanceof NullPointerException)
|| (throwable instanceof ClassCastException))
doStackDumpOnError = true;
if (doStackDumpOnError)
else
{
+ throwable.getMessage());
}
// diagnosticsWriter.println(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUCCESSFUL, null)); //"XSL Process was not successful.");
if (null != dumpFileName)
{
dumpWriter.close();
}
}
if (null != dumpFileName)
{
dumpWriter.close();
}
if (null != diagnosticsWriter)
{
// diagnosticsWriter.close();
}
// if(!setQuietMode)
// diagnosticsWriter.println(resbundle.getString("xsldone")); //"Xalan: done");
// else
// diagnosticsWriter.println(""); //"Xalan: done");
}
}
/** It is _much_ easier to debug under VJ++ if I can set a single breakpoint
* before this blows itself out of the water...
* (I keep checking this in, it keeps vanishing. Grr!)
* */
{
throw new RuntimeException(msg);
}
/**
* Wait for a return key to continue
*
* @param resbundle The resource bundle
*/
{
try
{
}
}
/**
* Print a message if an option cannot be used with -XSLTC.
*
* @param option The option String
*/
{
System.err.println(XSLMessages.createMessage("xslProc_invalid_xsltc_option", new Object[]{option}));
}
/**
* Print a message if an option can only be used with -XSLTC.
*
* @param option The option String
*/
{
System.err.println(XSLMessages.createMessage("xslProc_invalid_xalan_option", new Object[]{option}));
}
}