8130058: jaxp: Investigate removal of com/sun/org/apache/xalan/internal/xslt/Process.java
Com/sun/org/apache/xalan/internal/xslt/Process.java removed. A copy modified to not depend on internal APIs is put in test/javax/xml/jaxp/internaltest/javax/xml/transform/cli/ProcessXSLT.java. The CLITest is preserved and uses that new copy. Reviewed-by: joehw, lancea
This commit is contained in:
parent
d2e2494f9e
commit
ae9ba69804
@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* reserved comment block
|
|
||||||
* DO NOT REMOVE OR ALTER!
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright 2003-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
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* 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: Version.java,v 1.1.2.1 2005/08/01 02:11:19 jeffsuttor Exp $
|
|
||||||
*/
|
|
||||||
package com.sun.org.apache.xalan.internal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Administrative class to keep track of the version number of
|
|
||||||
* the Xalan release.
|
|
||||||
* <P>This class implements the upcoming standard of having
|
|
||||||
* org.apache.project-name.Version.getVersion() be a standard way
|
|
||||||
* to get version information. This class will replace the older
|
|
||||||
* com.sun.org.apache.xalan.internal.processor.Version class.</P>
|
|
||||||
* <P>See also: com/sun/org/apache/xalan/internal/res/XSLTInfo.properties for
|
|
||||||
* information about the version of the XSLT spec we support.</P>
|
|
||||||
* @xsl.usage general
|
|
||||||
*/
|
|
||||||
public class Version
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the basic version string for the current Xalan release.
|
|
||||||
* Version String formatted like
|
|
||||||
* <CODE>"<B>Xalan</B> <B>Java</B> v.r[.dd| <B>D</B>nn]"</CODE>.
|
|
||||||
*
|
|
||||||
* Futurework: have this read version info from jar manifest.
|
|
||||||
*
|
|
||||||
* @return String denoting our current version
|
|
||||||
*/
|
|
||||||
public static String getVersion()
|
|
||||||
{
|
|
||||||
return getProduct()+" "+getImplementationLanguage()+" "
|
|
||||||
+getMajorVersionNum()+"."+getReleaseVersionNum()+"."
|
|
||||||
+( (getDevelopmentVersionNum() > 0) ?
|
|
||||||
("D"+getDevelopmentVersionNum()) : (""+getMaintenanceVersionNum()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Print the processor version to the command line.
|
|
||||||
*
|
|
||||||
* @param argv command line arguments, unused.
|
|
||||||
*/
|
|
||||||
public static void _main(String argv[])
|
|
||||||
{
|
|
||||||
System.out.println(getVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of product: Xalan.
|
|
||||||
*/
|
|
||||||
public static String getProduct()
|
|
||||||
{
|
|
||||||
return "Xalan";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation Language: Java.
|
|
||||||
*/
|
|
||||||
public static String getImplementationLanguage()
|
|
||||||
{
|
|
||||||
return "Java";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Major version number.
|
|
||||||
* Version number. This changes only when there is a
|
|
||||||
* significant, externally apparent enhancement from
|
|
||||||
* the previous release. 'n' represents the n'th
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* Clients should carefully consider the implications
|
|
||||||
* of new versions as external interfaces and behaviour
|
|
||||||
* may have changed.
|
|
||||||
*/
|
|
||||||
public static int getMajorVersionNum()
|
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Release Number.
|
|
||||||
* Release number. This changes when:
|
|
||||||
* - a new set of functionality is to be added, eg,
|
|
||||||
* implementation of a new W3C specification.
|
|
||||||
* - API or behaviour change.
|
|
||||||
* - its designated as a reference release.
|
|
||||||
*/
|
|
||||||
public static int getReleaseVersionNum()
|
|
||||||
{
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maintenance Drop Number.
|
|
||||||
* Optional identifier used to designate maintenance
|
|
||||||
* drop applied to a specific release and contains
|
|
||||||
* fixes for defects reported. It maintains compatibility
|
|
||||||
* with the release and contains no API changes.
|
|
||||||
* When missing, it designates the final and complete
|
|
||||||
* development drop for a release.
|
|
||||||
*/
|
|
||||||
public static int getMaintenanceVersionNum()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Development Drop Number.
|
|
||||||
* Optional identifier designates development drop of
|
|
||||||
* a specific release. D01 is the first development drop
|
|
||||||
* of a new release.
|
|
||||||
*
|
|
||||||
* Development drops are works in progress towards a
|
|
||||||
* compeleted, final release. A specific development drop
|
|
||||||
* may not completely implement all aspects of a new
|
|
||||||
* feature, which may take several development drops to
|
|
||||||
* complete. At the point of the final drop for the
|
|
||||||
* release, the D suffix will be omitted.
|
|
||||||
*
|
|
||||||
* Each 'D' drops can contain functional enhancements as
|
|
||||||
* well as defect fixes. 'D' drops may not be as stable as
|
|
||||||
* the final releases.
|
|
||||||
*/
|
|
||||||
public static int getDevelopmentVersionNum()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if ((new String("")).length() == 0)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return Integer.parseInt("");
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* reserved comment block
|
|
||||||
* DO NOT REMOVE OR ALTER!
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* The Apache Software License, Version 1.1
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
|
|
||||||
* reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* 3. The end-user documentation included with the redistribution,
|
|
||||||
* if any, must include the following acknowledgment:
|
|
||||||
* "This product includes software developed by the
|
|
||||||
* Apache Software Foundation (http://www.apache.org/)."
|
|
||||||
* Alternately, this acknowledgment may appear in the software itself,
|
|
||||||
* if and wherever such third-party acknowledgments normally appear.
|
|
||||||
*
|
|
||||||
* 4. The names "Xerces" and "Apache Software Foundation" must
|
|
||||||
* not be used to endorse or promote products derived from this
|
|
||||||
* software without prior written permission. For written
|
|
||||||
* permission, please contact apache@apache.org.
|
|
||||||
*
|
|
||||||
* 5. Products derived from this software may not be called "Apache",
|
|
||||||
* nor may "Apache" appear in their name, without prior written
|
|
||||||
* permission of the Apache Software Foundation.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
||||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
||||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
* ====================================================================
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many
|
|
||||||
* individuals on behalf of the Apache Software Foundation and was
|
|
||||||
* originally based on software copyright (c) 1999, International
|
|
||||||
* Business Machines, Inc., http://www.apache.org. For more
|
|
||||||
* information on the Apache Software Foundation, please see
|
|
||||||
* <http://www.apache.org/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sun.org.apache.xerces.internal.impl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class defines the version number of the parser.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Version {
|
|
||||||
|
|
||||||
//
|
|
||||||
// Data
|
|
||||||
//
|
|
||||||
|
|
||||||
/** Version string.
|
|
||||||
* @deprecated getVersion() should be used instead. */
|
|
||||||
public static final String fVersion = getVersion();
|
|
||||||
|
|
||||||
private static final String fImmutableVersion = "Xerces-J 2.7.1";
|
|
||||||
|
|
||||||
// public methods
|
|
||||||
|
|
||||||
/* Print out the version information.
|
|
||||||
* @return the version of the parser.
|
|
||||||
*/
|
|
||||||
public static String getVersion() {
|
|
||||||
return fImmutableVersion;
|
|
||||||
} // getVersion(): String
|
|
||||||
|
|
||||||
//
|
|
||||||
// MAIN
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints out the version number to System.out. This is needed
|
|
||||||
* for the build system.
|
|
||||||
*/
|
|
||||||
public static void main(String argv[]) {
|
|
||||||
System.out.println(fVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // class Version
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @test
|
|
||||||
* @modules java.xml/com.sun.org.apache.xerces.internal.impl
|
|
||||||
* java.xml/com.sun.org.apache.xalan.internal
|
|
||||||
* @bug 6979306
|
|
||||||
* @summary Test JAXP component version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
public class Bug6979306Test {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
String[] input = {};
|
|
||||||
com.sun.org.apache.xerces.internal.impl.Version.main(input);
|
|
||||||
com.sun.org.apache.xalan.internal.Version._main(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @modules java.xml/com.sun.org.apache.xalan.internal.xslt
|
* @modules java.xml/com.sun.org.apache.xml.internal.utils
|
||||||
* @summary Test internal transform CLI.
|
* @summary Test internal transform CLI.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public class CLITest {
|
|||||||
try {
|
try {
|
||||||
String[] args = new String[] { "-XSLTC", "-XSL", getClass().getResource("tigertest.xsl").toString(), "-IN",
|
String[] args = new String[] { "-XSLTC", "-XSL", getClass().getResource("tigertest.xsl").toString(), "-IN",
|
||||||
getClass().getResource("tigertest-in.xml").toString(), };
|
getClass().getResource("tigertest-in.xml").toString(), };
|
||||||
com.sun.org.apache.xalan.internal.xslt.Process._main(args);
|
ProcessXSLT.main(args);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Assert.fail(e.getMessage());
|
Assert.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,913 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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 $
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This file is a copied and modified version of
|
||||||
|
// com/sun/org/apache/xalan/internal/xslt/Process.java
|
||||||
|
// which has been modified to only use public exported APIs.
|
||||||
|
// The only adherence is with
|
||||||
|
// com.sun.org.apache.xml.internal.utils.DefaultErrorHandler
|
||||||
|
// which we try to instantiate using reflection, as that class
|
||||||
|
// can do a better job at reporting error location.
|
||||||
|
// We however don't have a hard dependency on it. We will use
|
||||||
|
// our own ErrorHandler if the default one is not accessible.
|
||||||
|
//
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.xml.XMLConstants;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import javax.xml.transform.Source;
|
||||||
|
import javax.xml.transform.Templates;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerConfigurationException;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||||
|
import javax.xml.transform.URIResolver;
|
||||||
|
import javax.xml.transform.dom.DOMResult;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.sax.SAXResult;
|
||||||
|
import javax.xml.transform.sax.SAXSource;
|
||||||
|
import javax.xml.transform.sax.SAXTransformerFactory;
|
||||||
|
import javax.xml.transform.sax.TransformerHandler;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import javax.xml.transform.stream.StreamSource;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.xml.transform.ErrorListener;
|
||||||
|
import javax.xml.transform.SourceLocator;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
import org.xml.sax.ContentHandler;
|
||||||
|
import org.xml.sax.EntityResolver;
|
||||||
|
import org.xml.sax.ErrorHandler;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
import org.xml.sax.XMLReader;
|
||||||
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main() method handles the Xalan command-line interface.
|
||||||
|
*/
|
||||||
|
public class ProcessXSLT
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints argument options.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected static void printArgOptions() {
|
||||||
|
System.out.println("xslproc options: ");
|
||||||
|
System.out.println("\n\t\t\t" + "-Common Options-" + "\n");
|
||||||
|
System.out.println(" [-XSLTC (use XSLTC for transformation)]"); //" [-XSLTC (use XSLTC for transformation)]
|
||||||
|
System.out.println(" [-IN inputXMLURL]"); //" [-IN inputXMLURL]");
|
||||||
|
System.out.println(" [-XSL XSLTransformationURL]"); //" [-XSL XSLTransformationURL]");
|
||||||
|
System.out.println(" [-OUT outputFileName]"); //" [-OUT outputFileName]");
|
||||||
|
|
||||||
|
System.out.println(" [-E (Do not expand entity refs)]"); //" [-V (Version info)]");
|
||||||
|
|
||||||
|
System.out.println(" [-EDUMP {optional filename} (Do stackdump on error.)]"); //" [-EDUMP {optional filename} (Do stackdump on error.)]");
|
||||||
|
System.out.println(" [-XML (Use XML formatter and add XML header.)]"); //" [-XML (Use XML formatter and add XML header.)]");
|
||||||
|
System.out.println(" [-TEXT (Use simple Text formatter.)]"); //" [-TEXT (Use simple Text formatter.)]");
|
||||||
|
System.out.println(" [-HTML (Use HTML formatter.)]"); //" [-HTML (Use HTML formatter.)]");
|
||||||
|
System.out.println( " [-PARAM name expression (Set a stylesheet parameter)]"); //" [-PARAM name expression (Set a stylesheet parameter)]");
|
||||||
|
|
||||||
|
System.out.println(" [-MEDIA mediaType (use media attribute to find stylesheet associated with a document.)]");
|
||||||
|
System.out.println(" [-FLAVOR flavorName (Explicitly use s2s=SAX or d2d=DOM to do transform.)] ");
|
||||||
|
System.out.println(" [-DIAG (Print overall milliseconds transform took.)]");
|
||||||
|
System.out.println(" [-URIRESOLVER full class name (URIResolver to be used to resolve URIs)]"); //" [-URIRESOLVER full class name (URIResolver to be used to resolve URIs)]");
|
||||||
|
System.out.println(" [-ENTITYRESOLVER full class name (EntityResolver to be used to resolve entities)]"); //" [-ENTITYRESOLVER full class name (EntityResolver to be used to resolve entities)]");
|
||||||
|
waitForReturnKey();
|
||||||
|
System.out.println(" [-CONTENTHANDLER full class name (ContentHandler to be used to serialize output)]"); //" [-CONTENTHANDLER full class name (ContentHandler to be used to serialize output)]");
|
||||||
|
System.out.println(" [-SECURE (set the secure processing feature to true.)]"); //" [-SECURE (set the secure processing feature to true)]");
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("\n\t\t\t"+ "-Options for XSLTC-" + "\n");
|
||||||
|
System.out.println(" [-XO [transletName] (assign the name to the generated translet)]");
|
||||||
|
waitForReturnKey();
|
||||||
|
System.out.println(" [-XD destinationDirectory (specify a destination directory for translet)]");
|
||||||
|
System.out.println(" [-XJ jarfile (packages translet classes into a jar file of name <jarfile>)]");
|
||||||
|
System.out.println(" [-XP package (specifies a package name prefix for all generated translet classes)]");
|
||||||
|
System.out.println(" [-XN (enables template inlining)]");
|
||||||
|
System.out.println(" [-XX (turns on additional debugging message output)]");
|
||||||
|
System.out.println(" [-XT (use translet to transform if possible)]");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public static void main(String argv[]) {
|
||||||
|
|
||||||
|
// Runtime.getRuntime().traceMethodCalls(false); // turns Java tracing off
|
||||||
|
boolean doStackDumpOnError = false;
|
||||||
|
boolean doDiag = false;
|
||||||
|
boolean setQuietMode = false;
|
||||||
|
String msg = null;
|
||||||
|
boolean isSecureProcessing = false;
|
||||||
|
|
||||||
|
// Runtime.getRuntime().traceMethodCalls(false);
|
||||||
|
// Runtime.getRuntime().traceInstructions(false);
|
||||||
|
/**
|
||||||
|
* The default diagnostic writer...
|
||||||
|
*/
|
||||||
|
java.io.PrintWriter diagnosticsWriter = new PrintWriter(System.err, true);
|
||||||
|
java.io.PrintWriter dumpWriter = diagnosticsWriter;
|
||||||
|
String flavor = "s2s";
|
||||||
|
|
||||||
|
if (argv.length < 1) {
|
||||||
|
printArgOptions();
|
||||||
|
} else {
|
||||||
|
// J2SE does not support Xalan interpretive
|
||||||
|
// false -> true
|
||||||
|
boolean useXSLTC = true;
|
||||||
|
for (int i = 0; i < argv.length; i++) {
|
||||||
|
if ("-XSLTC".equalsIgnoreCase(argv[i])) {
|
||||||
|
useXSLTC = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformerFactory tfactory;
|
||||||
|
if (useXSLTC) {
|
||||||
|
String key = "javax.xml.transform.TransformerFactory";
|
||||||
|
String value = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
|
||||||
|
Properties props = System.getProperties();
|
||||||
|
props.put(key, value);
|
||||||
|
System.setProperties(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
tfactory = TransformerFactory.newInstance();
|
||||||
|
tfactory.setErrorListener(createDefaultErrorListener());
|
||||||
|
} catch (TransformerFactoryConfigurationError pfe) {
|
||||||
|
pfe.printStackTrace(dumpWriter);
|
||||||
|
// "XSL Process was not successful.");
|
||||||
|
msg = "XSL Process was not successful.";
|
||||||
|
diagnosticsWriter.println(msg);
|
||||||
|
|
||||||
|
tfactory = null; // shut up compiler
|
||||||
|
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean formatOutput = false;
|
||||||
|
boolean useSourceLocation = false;
|
||||||
|
String inFileName = null;
|
||||||
|
String outFileName = null;
|
||||||
|
String dumpFileName = null;
|
||||||
|
String xslFileName = null;
|
||||||
|
String treedumpFileName = null;
|
||||||
|
String outputType = null;
|
||||||
|
String media = null;
|
||||||
|
List<String> params = new ArrayList<>();
|
||||||
|
boolean quietConflictWarnings = false;
|
||||||
|
URIResolver uriResolver = null;
|
||||||
|
EntityResolver entityResolver = null;
|
||||||
|
ContentHandler contentHandler = null;
|
||||||
|
int recursionLimit = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < argv.length; i++) {
|
||||||
|
if ("-XSLTC".equalsIgnoreCase(argv[i])) {
|
||||||
|
// The -XSLTC option has been processed.
|
||||||
|
} // J2SE does not support Xalan interpretive
|
||||||
|
else if ("-INDENT".equalsIgnoreCase(argv[i])) {
|
||||||
|
int indentAmount;
|
||||||
|
|
||||||
|
if (((i + 1) < argv.length) && (argv[i + 1].charAt(0) != '-')) {
|
||||||
|
indentAmount = Integer.parseInt(argv[++i]);
|
||||||
|
} else {
|
||||||
|
indentAmount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ("-IN".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
inFileName = argv[++i];
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -IN");
|
||||||
|
}
|
||||||
|
} else if ("-MEDIA".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length) {
|
||||||
|
media = argv[++i];
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -MEDIA"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else if ("-OUT".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
outFileName = argv[++i];
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -OUT"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else if ("-XSL".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
xslFileName = argv[++i];
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -XSL"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else if ("-FLAVOR".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length) {
|
||||||
|
flavor = argv[++i];
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -FLAVOR"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else if ("-PARAM".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 2 < argv.length) {
|
||||||
|
String name = argv[++i];
|
||||||
|
|
||||||
|
params.add(name);
|
||||||
|
|
||||||
|
String expression = argv[++i];
|
||||||
|
|
||||||
|
params.add(expression);
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -PARAM"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else if ("-E".equalsIgnoreCase(argv[i])) {
|
||||||
|
|
||||||
|
} else if ("-V".equalsIgnoreCase(argv[i])) {
|
||||||
|
diagnosticsWriter.println(">>>>>>> Java Version "
|
||||||
|
+ System.getProperty("java.version") + ", "
|
||||||
|
+ /* xmlProcessorLiaison.getParserDescription()+ */ "<<<<<<<");
|
||||||
|
} // J2SE does not support Xalan interpretive
|
||||||
|
/*
|
||||||
|
else if ("-QC".equalsIgnoreCase(argv[i]))
|
||||||
|
{
|
||||||
|
if (!useXSLTC)
|
||||||
|
quietConflictWarnings = true;
|
||||||
|
else
|
||||||
|
printInvalidXSLTCOption("-QC");
|
||||||
|
}
|
||||||
|
*/ else if ("-Q".equalsIgnoreCase(argv[i])) {
|
||||||
|
setQuietMode = true;
|
||||||
|
} else if ("-DIAG".equalsIgnoreCase(argv[i])) {
|
||||||
|
doDiag = true;
|
||||||
|
} else if ("-XML".equalsIgnoreCase(argv[i])) {
|
||||||
|
outputType = "xml";
|
||||||
|
} else if ("-TEXT".equalsIgnoreCase(argv[i])) {
|
||||||
|
outputType = "text";
|
||||||
|
} else if ("-HTML".equalsIgnoreCase(argv[i])) {
|
||||||
|
outputType = "html";
|
||||||
|
} else if ("-EDUMP".equalsIgnoreCase(argv[i])) {
|
||||||
|
doStackDumpOnError = true;
|
||||||
|
|
||||||
|
if (((i + 1) < argv.length) && (argv[i + 1].charAt(0) != '-')) {
|
||||||
|
dumpFileName = argv[++i];
|
||||||
|
}
|
||||||
|
} else if ("-URIRESOLVER".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length) {
|
||||||
|
try {
|
||||||
|
Class<?> uriResolverClass = Class.forName(argv[++i]);
|
||||||
|
Constructor<?> ctor = uriResolverClass.getConstructor();
|
||||||
|
ctor.setAccessible(true);
|
||||||
|
uriResolver = (URIResolver) ctor.newInstance();
|
||||||
|
|
||||||
|
tfactory.setURIResolver(uriResolver);
|
||||||
|
} catch (Throwable cnfe) {
|
||||||
|
msg = "Class not found for option -URIResolver";
|
||||||
|
System.err.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
msg = "Missing argument for -URIResolver";
|
||||||
|
System.err.println(msg); //"Missing argument for);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
} else if ("-ENTITYRESOLVER".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length) {
|
||||||
|
try {
|
||||||
|
Class<?> entityResolverClass = Class.forName(argv[++i]);
|
||||||
|
Constructor<?> ctor = entityResolverClass.getConstructor();
|
||||||
|
ctor.setAccessible(true);
|
||||||
|
entityResolver = (EntityResolver) ctor.newInstance();
|
||||||
|
} catch (Throwable cnfe) {
|
||||||
|
msg = "Class not found for option -EntityResolver";
|
||||||
|
System.err.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// "Missing argument for);
|
||||||
|
msg = "Missing argument for -EntityResolver";
|
||||||
|
System.err.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
} else if ("-CONTENTHANDLER".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (i + 1 < argv.length) {
|
||||||
|
try {
|
||||||
|
Class<?> contentHandlerClass = Class.forName(argv[++i]);
|
||||||
|
Constructor<?> ctor = contentHandlerClass.getConstructor();
|
||||||
|
ctor.setAccessible(true);
|
||||||
|
contentHandler = (ContentHandler) ctor.newInstance();
|
||||||
|
} catch (Throwable cnfe) {
|
||||||
|
msg = "Class not found for option -ContentHandler";
|
||||||
|
System.err.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// "Missing argument for);
|
||||||
|
msg = "Missing argument for -ContentHandler";
|
||||||
|
System.err.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
} else if ("-XO".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
tfactory.setAttribute("generate-translet", "true");
|
||||||
|
tfactory.setAttribute("translet-name", argv[++i]);
|
||||||
|
} else {
|
||||||
|
tfactory.setAttribute("generate-translet", "true");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
printInvalidXalanOption("-XO");
|
||||||
|
}
|
||||||
|
} // Specify the destination directory for the translet classes.
|
||||||
|
else if ("-XD".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
tfactory.setAttribute("destination-directory", argv[++i]);
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -XD"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printInvalidXalanOption("-XD");
|
||||||
|
}
|
||||||
|
} // Specify the jar file name which the translet classes are packaged into.
|
||||||
|
else if ("-XJ".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
tfactory.setAttribute("generate-translet", "true");
|
||||||
|
tfactory.setAttribute("jar-name", argv[++i]);
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -XJ"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printInvalidXalanOption("-XJ");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Specify the package name prefix for the generated translet classes.
|
||||||
|
else if ("-XP".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
tfactory.setAttribute("package-name", argv[++i]);
|
||||||
|
} else {
|
||||||
|
System.err.println("Missing argument for -XP"); //"Missing argument for);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printInvalidXalanOption("-XP");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Enable template inlining.
|
||||||
|
else if ("-XN".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
tfactory.setAttribute("enable-inlining", "true");
|
||||||
|
} else {
|
||||||
|
printInvalidXalanOption("-XN");
|
||||||
|
}
|
||||||
|
} // Turns on additional debugging message output
|
||||||
|
else if ("-XX".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
tfactory.setAttribute("debug", "true");
|
||||||
|
} else {
|
||||||
|
printInvalidXalanOption("-XX");
|
||||||
|
}
|
||||||
|
} // Create the Transformer from the translet if the translet class is newer
|
||||||
|
// than the stylesheet.
|
||||||
|
else if ("-XT".equalsIgnoreCase(argv[i])) {
|
||||||
|
if (useXSLTC) {
|
||||||
|
tfactory.setAttribute("auto-translet", "true");
|
||||||
|
} else {
|
||||||
|
printInvalidXalanOption("-XT");
|
||||||
|
}
|
||||||
|
} else if ("-SECURE".equalsIgnoreCase(argv[i])) {
|
||||||
|
isSecureProcessing = true;
|
||||||
|
try {
|
||||||
|
tfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
} catch (TransformerConfigurationException e) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.err.println("Invalid argument: " + argv[i]); //"Invalid argument:);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print usage instructions if no xml and xsl file is specified in the command line
|
||||||
|
if (inFileName == null && xslFileName == null) {
|
||||||
|
msg = "Error: No stylesheet or input xml is specified. Run this command without any option for usage instructions.";
|
||||||
|
System.err.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that there are usage cases for calling us without a -IN arg
|
||||||
|
// The main XSL transformation occurs here!
|
||||||
|
try {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (null != dumpFileName) {
|
||||||
|
dumpWriter = new PrintWriter(new FileWriter(dumpFileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
Templates stylesheet = null;
|
||||||
|
|
||||||
|
if (null != xslFileName) {
|
||||||
|
if (flavor.equals("d2d")) {
|
||||||
|
|
||||||
|
// Parse in the xml data into a DOM
|
||||||
|
DocumentBuilderFactory dfactory
|
||||||
|
= DocumentBuilderFactory.newInstance();
|
||||||
|
|
||||||
|
dfactory.setNamespaceAware(true);
|
||||||
|
|
||||||
|
if (isSecureProcessing) {
|
||||||
|
try {
|
||||||
|
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
} catch (ParserConfigurationException pce) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
|
||||||
|
Node xslDOM = docBuilder.parse(new InputSource(xslFileName));
|
||||||
|
|
||||||
|
stylesheet = tfactory.newTemplates(new DOMSource(xslDOM,
|
||||||
|
xslFileName));
|
||||||
|
} else {
|
||||||
|
// System.out.println("Calling newTemplates: "+xslFileName);
|
||||||
|
stylesheet = tfactory.newTemplates(new StreamSource(xslFileName));
|
||||||
|
// System.out.println("Done calling newTemplates: "+xslFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintWriter resultWriter;
|
||||||
|
StreamResult strResult;
|
||||||
|
|
||||||
|
if (null != outFileName) {
|
||||||
|
strResult = new StreamResult(new FileOutputStream(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
|
||||||
|
strResult.setSystemId(outFileName);
|
||||||
|
} else {
|
||||||
|
strResult = new StreamResult(System.out);
|
||||||
|
// 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.
|
||||||
|
}
|
||||||
|
|
||||||
|
SAXTransformerFactory stf = (SAXTransformerFactory) tfactory;
|
||||||
|
|
||||||
|
// Did they pass in a stylesheet, or should we get it from the
|
||||||
|
// document?
|
||||||
|
if (null == stylesheet) {
|
||||||
|
Source source
|
||||||
|
= stf.getAssociatedStylesheet(new StreamSource(inFileName), media,
|
||||||
|
null, null);
|
||||||
|
|
||||||
|
if (null != source) {
|
||||||
|
stylesheet = tfactory.newTemplates(source);
|
||||||
|
} else {
|
||||||
|
if (null != media) {
|
||||||
|
throw new TransformerException("No stylesheet found in: "
|
||||||
|
+ inFileName + ", media=" + media); //"No stylesheet found in: "
|
||||||
|
} // + inFileName + ", media="
|
||||||
|
// + media);
|
||||||
|
else {
|
||||||
|
throw new TransformerException("No xml-stylesheet PI found in: " + inFileName); //"No xml-stylesheet PI found in: "
|
||||||
|
} //+ inFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != stylesheet) {
|
||||||
|
Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer();
|
||||||
|
transformer.setErrorListener(createDefaultErrorListener());
|
||||||
|
|
||||||
|
// Override the output format?
|
||||||
|
if (null != outputType) {
|
||||||
|
transformer.setOutputProperty(OutputKeys.METHOD, outputType);
|
||||||
|
}
|
||||||
|
|
||||||
|
int nParams = params.size();
|
||||||
|
|
||||||
|
for (int i = 0; i < nParams; i += 2) {
|
||||||
|
transformer.setParameter((String) params.get(i),
|
||||||
|
(String) params.get(i + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uriResolver != null) {
|
||||||
|
transformer.setURIResolver(uriResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != inFileName) {
|
||||||
|
if (flavor.equals("d2d")) {
|
||||||
|
|
||||||
|
// Parse in the xml data into a DOM
|
||||||
|
DocumentBuilderFactory dfactory
|
||||||
|
= DocumentBuilderFactory.newInstance();
|
||||||
|
|
||||||
|
dfactory.setCoalescing(true);
|
||||||
|
dfactory.setNamespaceAware(true);
|
||||||
|
|
||||||
|
if (isSecureProcessing) {
|
||||||
|
try {
|
||||||
|
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
} catch (ParserConfigurationException pce) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
|
||||||
|
|
||||||
|
if (entityResolver != null) {
|
||||||
|
docBuilder.setEntityResolver(entityResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
Node xmlDoc = docBuilder.parse(new InputSource(inFileName));
|
||||||
|
Document doc = docBuilder.newDocument();
|
||||||
|
org.w3c.dom.DocumentFragment outNode
|
||||||
|
= doc.createDocumentFragment();
|
||||||
|
|
||||||
|
transformer.transform(new DOMSource(xmlDoc, inFileName),
|
||||||
|
new DOMResult(outNode));
|
||||||
|
|
||||||
|
// Now serialize output to disk with identity transformer
|
||||||
|
Transformer serializer = stf.newTransformer();
|
||||||
|
serializer.setErrorListener(createDefaultErrorListener());
|
||||||
|
|
||||||
|
Properties serializationProps
|
||||||
|
= stylesheet.getOutputProperties();
|
||||||
|
|
||||||
|
serializer.setOutputProperties(serializationProps);
|
||||||
|
|
||||||
|
if (contentHandler != null) {
|
||||||
|
SAXResult result = new SAXResult(contentHandler);
|
||||||
|
|
||||||
|
serializer.transform(new DOMSource(outNode), result);
|
||||||
|
} else {
|
||||||
|
serializer.transform(new DOMSource(outNode), strResult);
|
||||||
|
}
|
||||||
|
} else if (flavor.equals("th")) {
|
||||||
|
for (int i = 0; i < 1; i++) // Loop for diagnosing bugs with inconsistent behavior
|
||||||
|
{
|
||||||
|
// System.out.println("Testing the TransformerHandler...");
|
||||||
|
|
||||||
|
XMLReader reader = null;
|
||||||
|
|
||||||
|
// Use JAXP1.1 ( if possible )
|
||||||
|
try {
|
||||||
|
javax.xml.parsers.SAXParserFactory factory
|
||||||
|
= javax.xml.parsers.SAXParserFactory.newInstance();
|
||||||
|
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
|
||||||
|
if (isSecureProcessing) {
|
||||||
|
try {
|
||||||
|
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
} catch (org.xml.sax.SAXException se) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
javax.xml.parsers.SAXParser jaxpParser
|
||||||
|
= factory.newSAXParser();
|
||||||
|
|
||||||
|
reader = jaxpParser.getXMLReader();
|
||||||
|
} catch (javax.xml.parsers.ParserConfigurationException ex) {
|
||||||
|
throw new org.xml.sax.SAXException(ex);
|
||||||
|
} catch (javax.xml.parsers.FactoryConfigurationError ex1) {
|
||||||
|
throw new org.xml.sax.SAXException(ex1.toString());
|
||||||
|
} catch (NoSuchMethodError ex2) {
|
||||||
|
} catch (AbstractMethodError ame) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == reader) {
|
||||||
|
reader = XMLReaderFactory.createXMLReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformerHandler th = stf.newTransformerHandler(stylesheet);
|
||||||
|
|
||||||
|
reader.setContentHandler(th);
|
||||||
|
reader.setDTDHandler(th);
|
||||||
|
|
||||||
|
if (th instanceof org.xml.sax.ErrorHandler) {
|
||||||
|
reader.setErrorHandler((org.xml.sax.ErrorHandler) th);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
reader.setProperty(
|
||||||
|
"http://xml.org/sax/properties/lexical-handler", th);
|
||||||
|
} catch (org.xml.sax.SAXNotRecognizedException e) {
|
||||||
|
} catch (org.xml.sax.SAXNotSupportedException e) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
|
||||||
|
true);
|
||||||
|
} catch (org.xml.sax.SAXException se) {
|
||||||
|
}
|
||||||
|
|
||||||
|
th.setResult(strResult);
|
||||||
|
|
||||||
|
reader.parse(new InputSource(inFileName));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (entityResolver != null) {
|
||||||
|
XMLReader reader = null;
|
||||||
|
|
||||||
|
// Use JAXP1.1 ( if possible )
|
||||||
|
try {
|
||||||
|
javax.xml.parsers.SAXParserFactory factory
|
||||||
|
= javax.xml.parsers.SAXParserFactory.newInstance();
|
||||||
|
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
|
||||||
|
if (isSecureProcessing) {
|
||||||
|
try {
|
||||||
|
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
} catch (org.xml.sax.SAXException se) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
javax.xml.parsers.SAXParser jaxpParser
|
||||||
|
= factory.newSAXParser();
|
||||||
|
|
||||||
|
reader = jaxpParser.getXMLReader();
|
||||||
|
} catch (javax.xml.parsers.ParserConfigurationException ex) {
|
||||||
|
throw new org.xml.sax.SAXException(ex);
|
||||||
|
} catch (javax.xml.parsers.FactoryConfigurationError ex1) {
|
||||||
|
throw new org.xml.sax.SAXException(ex1.toString());
|
||||||
|
} catch (NoSuchMethodError ex2) {
|
||||||
|
} catch (AbstractMethodError ame) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == reader) {
|
||||||
|
reader = XMLReaderFactory.createXMLReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.setEntityResolver(entityResolver);
|
||||||
|
|
||||||
|
if (contentHandler != null) {
|
||||||
|
SAXResult result = new SAXResult(contentHandler);
|
||||||
|
|
||||||
|
transformer.transform(
|
||||||
|
new SAXSource(reader, new InputSource(inFileName)),
|
||||||
|
result);
|
||||||
|
} else {
|
||||||
|
transformer.transform(
|
||||||
|
new SAXSource(reader, new InputSource(inFileName)),
|
||||||
|
strResult);
|
||||||
|
}
|
||||||
|
} else if (contentHandler != null) {
|
||||||
|
SAXResult result = new SAXResult(contentHandler);
|
||||||
|
|
||||||
|
transformer.transform(new StreamSource(inFileName), result);
|
||||||
|
} else {
|
||||||
|
// System.out.println("Starting transform");
|
||||||
|
transformer.transform(new StreamSource(inFileName),
|
||||||
|
strResult);
|
||||||
|
// System.out.println("Done with transform");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
StringReader reader
|
||||||
|
= new StringReader("<?xml version=\"1.0\"?> <doc/>");
|
||||||
|
|
||||||
|
transformer.transform(new StreamSource(reader), strResult);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// "XSL Process was not successful.");
|
||||||
|
msg = "XSL Process was not successful.";
|
||||||
|
diagnosticsWriter.println(msg);
|
||||||
|
doExit(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// close output streams
|
||||||
|
if (null != outFileName && strResult != null) {
|
||||||
|
java.io.OutputStream out = strResult.getOutputStream();
|
||||||
|
java.io.Writer writer = strResult.getWriter();
|
||||||
|
try {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
if (writer != null) {
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
} catch (java.io.IOException ie) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long stop = System.currentTimeMillis();
|
||||||
|
long millisecondsDuration = stop - start;
|
||||||
|
|
||||||
|
if (doDiag) {
|
||||||
|
msg = " --------- Transform of " + inFileName + " via "
|
||||||
|
+ xslFileName + " took " + millisecondsDuration + " ms";
|
||||||
|
diagnosticsWriter.println('\n');
|
||||||
|
diagnosticsWriter.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
doStackDumpOnError = true;
|
||||||
|
|
||||||
|
diagnosticsWriter.println();
|
||||||
|
|
||||||
|
if (doStackDumpOnError) {
|
||||||
|
throwable.printStackTrace(dumpWriter);
|
||||||
|
} else {
|
||||||
|
printLocation(diagnosticsWriter, throwable);
|
||||||
|
diagnosticsWriter.println("Unexpected exception: " + throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// diagnosticsWriter.println(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUCCESSFUL, null)); //"XSL Process was not successful.");
|
||||||
|
if (null != dumpFileName) {
|
||||||
|
dumpWriter.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
doExit(throwable.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
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!)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void doExit(String msg) {
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for a return key to continue
|
||||||
|
*
|
||||||
|
* @param resbundle The resource bundle
|
||||||
|
*/
|
||||||
|
private static void waitForReturnKey() {
|
||||||
|
System.out.println("(press <return> to continue)");
|
||||||
|
try {
|
||||||
|
while (System.in.read() != '\n');
|
||||||
|
} catch (java.io.IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a message if an option cannot be used with -XSLTC.
|
||||||
|
*
|
||||||
|
* @param option The option String
|
||||||
|
*/
|
||||||
|
private static void printInvalidXSLTCOption(String option) {
|
||||||
|
System.err.println("The option " + option + " is not supported in XSLTC mode.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a message if an option can only be used with -XSLTC.
|
||||||
|
*
|
||||||
|
* @param option The option String
|
||||||
|
*/
|
||||||
|
private static void printInvalidXalanOption(String option) {
|
||||||
|
System.err.println("The option " + option + " can only be used with -XSLTC.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static class DummyErrorListenerHandler implements ErrorHandler, ErrorListener {
|
||||||
|
@Override
|
||||||
|
public void warning(SAXParseException exception) throws SAXException {
|
||||||
|
System.err.println("WARNING: " + exception);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void error(SAXParseException exception) throws SAXException {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void fatalError(SAXParseException exception) throws SAXException {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void warning(TransformerException exception) throws TransformerException {
|
||||||
|
System.err.println("WARNING: " + exception);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void error(TransformerException exception) throws TransformerException {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void fatalError(TransformerException exception) throws TransformerException {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static ErrorListener createDefaultErrorListener() {
|
||||||
|
try {
|
||||||
|
Class<?> errorHandler =
|
||||||
|
Class.forName("com.sun.org.apache.xml.internal.utils.DefaultErrorHandler");
|
||||||
|
Constructor<?> ctor = errorHandler.getConstructor();
|
||||||
|
return (ErrorListener) ctor.newInstance();
|
||||||
|
} catch (Throwable r) {
|
||||||
|
return new DummyErrorListenerHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printLocation(PrintWriter diagnosticsWriter, Throwable throwable) {
|
||||||
|
try {
|
||||||
|
Class<?> errorHandler =
|
||||||
|
Class.forName("com.sun.org.apache.xml.internal.utils.DefaultErrorHandler");
|
||||||
|
Method m = errorHandler.getMethod("printLocation", PrintWriter.class, Throwable.class);
|
||||||
|
m.invoke(null, diagnosticsWriter, throwable);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
SourceLocator locator = null;
|
||||||
|
Throwable cause = throwable;
|
||||||
|
|
||||||
|
// Try to find the locator closest to the cause.
|
||||||
|
do {
|
||||||
|
if (cause instanceof TransformerException) {
|
||||||
|
SourceLocator causeLocator = ((TransformerException) cause).getLocator();
|
||||||
|
if (null != causeLocator) {
|
||||||
|
locator = causeLocator;
|
||||||
|
}
|
||||||
|
cause = ((TransformerException) cause).getCause();
|
||||||
|
} else if (cause instanceof SAXException) {
|
||||||
|
cause = ((SAXException) cause).getException();
|
||||||
|
} else {
|
||||||
|
cause = cause.getCause();
|
||||||
|
}
|
||||||
|
} while (null != cause);
|
||||||
|
|
||||||
|
if (null != locator) {
|
||||||
|
// m_pw.println("Parser fatal error: "+exception.getMessage());
|
||||||
|
String id = (null != locator.getPublicId())
|
||||||
|
? locator.getPublicId()
|
||||||
|
: (null != locator.getSystemId())
|
||||||
|
? locator.getSystemId() : "SystemId Unknown"; //"SystemId Unknown";
|
||||||
|
|
||||||
|
diagnosticsWriter.print(id + "; " + "line: " + locator.getLineNumber()
|
||||||
|
+ "; column: " + locator.getColumnNumber() + "; ");
|
||||||
|
}
|
||||||
|
diagnosticsWriter.print("(" + throwable + ": unknown location)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user