--- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java 2015-07-01 14:50:26.000000000 +0200 +++ /dev/null 2015-07-01 14:50:26.000000000 +0200 @@ -1,171 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2001-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: Compile.java,v 1.2.4.1 2005/08/31 11:24:13 pvedula Exp $ - */ - -package com.sun.org.apache.xalan.internal.xsltc.cmdline; - -import com.sun.org.apache.xalan.internal.utils.FeatureManager; -import java.io.File; -import java.net.URL; -import java.util.Vector; - -import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOpt; -import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOptsException; -import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; -import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; - -/** - * @author Jacek Ambroziak - * @author Santiago Pericas-Geertsen - * @author G. Todd Miller - * @author Morten Jorgensen - */ -public final class Compile { - - // Versioning numbers for the compiler -v option output - private static int VERSION_MAJOR = 1; - private static int VERSION_MINOR = 4; - private static int VERSION_DELTA = 0; - - - - // This variable should be set to false to prevent any methods in this - // class from calling System.exit(). As this is a command-line tool, - // calling System.exit() is normally OK, but we also want to allow for - // this class being used in other ways as well. - private static boolean _allowExit = true; - - - public static void printUsage() { - System.err.println("XSLTC version " + - VERSION_MAJOR + "." + VERSION_MINOR + - ((VERSION_DELTA > 0) ? ("." + VERSION_DELTA) : ("")) + "\n" + - new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR)); - if (_allowExit) System.exit(-1); - } - - /** - * This method implements the command line compiler. See the USAGE_STRING - * constant for a description. It may make sense to move the command-line - * handling to a separate package (ie. make one xsltc.cmdline.Compiler - * class that contains this main() method and one xsltc.cmdline.Transform - * class that contains the DefaultRun stuff). - */ - public static void main(String[] args) { - try { - boolean inputIsURL = false; - boolean useStdIn = false; - boolean classNameSet = false; - final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv"); - if (args.length < 1) printUsage(); - - final XSLTC xsltc = new XSLTC(true, new FeatureManager()); - xsltc.init(); - - int c; - while ((c = getopt.getNextOption()) != -1) { - switch(c) { - case 'i': - useStdIn = true; - break; - case 'o': - xsltc.setClassName(getopt.getOptionArg()); - classNameSet = true; - break; - case 'd': - xsltc.setDestDirectory(getopt.getOptionArg()); - break; - case 'p': - xsltc.setPackageName(getopt.getOptionArg()); - break; - case 'j': - xsltc.setJarFileName(getopt.getOptionArg()); - break; - case 'x': - xsltc.setDebug(true); - break; - case 'u': - inputIsURL = true; - break; - case 's': - _allowExit = false; - break; - case 'n': - xsltc.setTemplateInlining(true); // used to be 'false' - break; - case 'v': - // fall through to case h - case 'h': - default: - printUsage(); - break; - } - } - - boolean compileOK; - - if (useStdIn) { - if (!classNameSet) { - System.err.println(new ErrorMsg(ErrorMsg.COMPILE_STDIN_ERR)); - if (_allowExit) System.exit(-1); - } - compileOK = xsltc.compile(System.in, xsltc.getClassName()); - } - else { - // Generate a vector containg URLs for all stylesheets specified - final String[] stylesheetNames = getopt.getCmdArgs(); - final Vector stylesheetVector = new Vector(); - for (int i = 0; i < stylesheetNames.length; i++) { - final String name = stylesheetNames[i]; - URL url; - if (inputIsURL) - url = new URL(name); - else - url = (new File(name)).toURI().toURL(); - stylesheetVector.addElement(url); - } - compileOK = xsltc.compile(stylesheetVector); - } - - // Compile the stylesheet and output class/jar file(s) - if (compileOK) { - xsltc.printWarnings(); - if (xsltc.getJarFileName() != null) xsltc.outputToJar(); - if (_allowExit) System.exit(0); - } - else { - xsltc.printWarnings(); - xsltc.printErrors(); - if (_allowExit) System.exit(-1); - } - } - catch (GetOptsException ex) { - System.err.println(ex); - printUsage(); // exits with code '-1' - } - catch (Exception e) { - e.printStackTrace(); - if (_allowExit) System.exit(-1); - } - } - -} --- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/cmdline/Transform.java 2015-07-01 14:50:26.000000000 +0200 +++ /dev/null 2015-07-01 14:50:26.000000000 +0200 @@ -1,292 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2001-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: Transform.java,v 1.2.4.1 2005/09/12 09:07:33 pvedula Exp $ - */ - -package com.sun.org.apache.xalan.internal.xsltc.cmdline; - -import com.sun.org.apache.xalan.internal.utils.ObjectFactory; -import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM; -import com.sun.org.apache.xalan.internal.xsltc.StripFilter; -import com.sun.org.apache.xalan.internal.xsltc.TransletException; -import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; -import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter; -import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; -import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; -import com.sun.org.apache.xalan.internal.xsltc.runtime.Constants; -import com.sun.org.apache.xalan.internal.xsltc.runtime.Parameter; -import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory; -import com.sun.org.apache.xml.internal.dtm.DTMWSFilter; -import com.sun.org.apache.xml.internal.serializer.SerializationHandler; -import java.io.FileNotFoundException; -import java.net.MalformedURLException; -import java.net.UnknownHostException; -import java.util.Vector; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.sax.SAXSource; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -/** - * @author Jacek Ambroziak - * @author Santiago Pericas-Geertsen - * @author G. Todd Miller - * @author Morten Jorgensen - */ -final public class Transform { - - private SerializationHandler _handler; - - private String _fileName; - private String _className; - private String _jarFileSrc; - private boolean _isJarFileSpecified = false; - private Vector _params = null; - private boolean _uri, _debug; - private int _iterations; - - public Transform(String className, String fileName, - boolean uri, boolean debug, int iterations) { - _fileName = fileName; - _className = className; - _uri = uri; - _debug = debug; - _iterations = iterations; - } - - public String getFileName(){return _fileName;} - public String getClassName(){return _className;} - - public void setParameters(Vector params) { - _params = params; - } - - private void setJarFileInputSrc(boolean flag, String jarFile) { - // TODO: at this time we do not do anything with this - // information, attempts to add the jarfile to the CLASSPATH - // were successful via System.setProperty, but the effects - // were not visible to the running JVM. For now we add jarfile - // to CLASSPATH in the wrapper script that calls this program. - _isJarFileSpecified = flag; - // TODO verify jarFile exists... - _jarFileSrc = jarFile; - } - - private void doTransform() { - try { - final Class clazz = ObjectFactory.findProviderClass(_className, true); - final AbstractTranslet translet = (AbstractTranslet)clazz.newInstance(); - translet.postInitialization(); - - // Create a SAX parser and get the XMLReader object it uses - final SAXParserFactory factory = SAXParserFactory.newInstance(); - try { - factory.setFeature(Constants.NAMESPACE_FEATURE,true); - } - catch (Exception e) { - factory.setNamespaceAware(true); - } - final SAXParser parser = factory.newSAXParser(); - final XMLReader reader = parser.getXMLReader(); - - // Set the DOM's DOM builder as the XMLReader's SAX2 content handler - XSLTCDTMManager dtmManager = - XSLTCDTMManager.createNewDTMManagerInstance(); - - DTMWSFilter wsfilter; - if (translet != null && translet instanceof StripFilter) { - wsfilter = new DOMWSFilter(translet); - } else { - wsfilter = null; - } - - final DOMEnhancedForDTM dom = - (DOMEnhancedForDTM)dtmManager.getDTM( - new SAXSource(reader, new InputSource(_fileName)), - false, wsfilter, true, false, translet.hasIdCall()); - - dom.setDocumentURI(_fileName); - translet.prepassDocument(dom); - - // Pass global parameters - int n = _params.size(); - for (int i = 0; i < n; i++) { - Parameter param = (Parameter) _params.elementAt(i); - translet.addParameter(param._name, param._value); - } - - // Transform the document - TransletOutputHandlerFactory tohFactory = - TransletOutputHandlerFactory.newInstance(); - tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM); - tohFactory.setEncoding(translet._encoding); - tohFactory.setOutputMethod(translet._method); - - if (_iterations == -1) { - translet.transform(dom, tohFactory.getSerializationHandler()); - } - else if (_iterations > 0) { - long mm = System.currentTimeMillis(); - for (int i = 0; i < _iterations; i++) { - translet.transform(dom, - tohFactory.getSerializationHandler()); - } - mm = System.currentTimeMillis() - mm; - - System.err.println("\n"); - } - } - catch (TransletException e) { - if (_debug) e.printStackTrace(); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - e.getMessage()); - } - catch (RuntimeException e) { - if (_debug) e.printStackTrace(); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - e.getMessage()); - } - catch (FileNotFoundException e) { - if (_debug) e.printStackTrace(); - ErrorMsg err = new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, _fileName); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - err.toString()); - } - catch (MalformedURLException e) { - if (_debug) e.printStackTrace(); - ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, _fileName); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - err.toString()); - } - catch (ClassNotFoundException e) { - if (_debug) e.printStackTrace(); - ErrorMsg err= new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR,_className); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - err.toString()); - } - catch (UnknownHostException e) { - if (_debug) e.printStackTrace(); - ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, _fileName); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - err.toString()); - } - catch (SAXException e) { - Exception ex = e.getException(); - if (_debug) { - if (ex != null) ex.printStackTrace(); - e.printStackTrace(); - } - System.err.print(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)); - if (ex != null) - System.err.println(ex.getMessage()); - else - System.err.println(e.getMessage()); - } - catch (Exception e) { - if (_debug) e.printStackTrace(); - System.err.println(new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)+ - e.getMessage()); - } - } - - public static void printUsage() { - System.err.println(new ErrorMsg(ErrorMsg.TRANSFORM_USAGE_STR)); - } - - public static void main(String[] args) { - try { - if (args.length > 0) { - int i; - int iterations = -1; - boolean uri = false, debug = false; - boolean isJarFileSpecified = false; - String jarFile = null; - - // Parse options starting with '-' - for (i = 0; i < args.length && args[i].charAt(0) == '-'; i++) { - if (args[i].equals("-u")) { - uri = true; - } - else if (args[i].equals("-x")) { - debug = true; - } - else if (args[i].equals("-j")) { - isJarFileSpecified = true; - jarFile = args[++i]; - } - else if (args[i].equals("-n")) { - try { - iterations = Integer.parseInt(args[++i]); - } - catch (NumberFormatException e) { - // ignore - } - } - else { - printUsage(); - } - } - - // Enough arguments left ? - if (args.length - i < 2) printUsage(); - - // Get document file and class name - Transform handler = new Transform(args[i+1], args[i], uri, - debug, iterations); - handler.setJarFileInputSrc(isJarFileSpecified, jarFile); - - // Parse stylesheet parameters - Vector params = new Vector(); - for (i += 2; i < args.length; i++) { - final int equal = args[i].indexOf('='); - if (equal > 0) { - final String name = args[i].substring(0, equal); - final String value = args[i].substring(equal+1); - params.addElement(new Parameter(name, value)); - } - else { - printUsage(); - } - } - - if (i == args.length) { - handler.setParameters(params); - handler.doTransform(); - } - } else { - printUsage(); - } - } - catch (Exception e) { - e.printStackTrace(); - } - } -} --- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/cmdline/getopt/GetOpt.java 2015-07-01 14:50:26.000000000 +0200 +++ /dev/null 2015-07-01 14:50:26.000000000 +0200 @@ -1,258 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2001-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: GetOpt.java,v 1.2.4.1 2005/08/31 11:46:04 pvedula Exp $ - */ - -package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; - - -/** -* GetOpt is a Java equivalent to the C getopt() library function -* discussed in man page getopt(3C). It provides command line -* parsing for Java applications. It supports the most rules of the -* command line standard (see man page intro(1)) including stacked -* options such as '-sxm' (which is equivalent to -s -x -m); it -* handles special '--' option that signifies the end of options. -* Additionally this implementation of getopt will check for -* mandatory arguments to options such as in the case of -* '-d ' it will throw a MissingOptArgException if the -* option argument '' is not included on the commandline. -* getopt(3C) does not check for this. - * @author G Todd Miller -*/ -public class GetOpt{ - public GetOpt(String[] args, String optString){ - theOptions = new ArrayList(); - int currOptIndex = 0; - theCmdArgs = new ArrayList(); - theOptionMatcher = new OptionMatcher(optString); - // fill in the options list - for(int i=0; i 2){ - // stacked options found, such as '-shm' - // iterate thru the tokens after the dash and - // add them to theOptions list - for(int j=1; j', if current option parsed is 'd' then - * getOptionArg() would return ''. - * @return String - argument for current parsed option. - * @param none - */ - public String getOptionArg(){ - String retval = null; - String tmp = theCurrentOption.getArgument(); - char c = theCurrentOption.getArgLetter(); - if(theOptionMatcher.hasArg(c)){ - retval = tmp; - } - return retval; - } - - /** - * gets list of the commandline arguments. For example, in command - * such as 'cmd -s -d file file2 file3 file4' with the usage - * 'cmd [-s] [-d ] ...', getCmdArgs() would return - * the list {file2, file3, file4}. - * @return String[] - list of command arguments that may appear - * after options and option arguments. - * @params none - */ - public String[] getCmdArgs(){ - String[] retval = new String[theCmdArgs.size()]; - int i=0; - for(ListIterator it=theCmdArgs.listIterator(); it.hasNext();){ - retval[i++] = (String)it.next(); - } - return retval; - } - - - private Option theCurrentOption = null; - private ListIterator theOptionsIterator; - private List theOptions = null; - private List theCmdArgs = null; - private OptionMatcher theOptionMatcher = null; - - /////////////////////////////////////////////////////////// - // - // Inner Classes - // - /////////////////////////////////////////////////////////// - - // inner class to model an option - class Option{ - private char theArgLetter; - private String theArgument = null; - public Option(char argLetter) { theArgLetter = argLetter; } - public void setArg(String arg) { - theArgument = arg; - } - public boolean hasArg() { return (theArgument != null); } - public char getArgLetter() { return theArgLetter; } - public String getArgument() { return theArgument; } - } // end class Option - - - // inner class to query optString for a possible option match, - // and whether or not a given legal option takes an argument. - // - class OptionMatcher{ - public OptionMatcher(String optString){ - theOptString = optString; - } - public boolean match(char c){ - boolean retval = false; - if(theOptString.indexOf(c) != -1){ - retval = true; - } - return retval; - } - public boolean hasArg(char c){ - boolean retval = false; - int index = theOptString.indexOf(c)+1; - if (index == theOptString.length()){ - // reached end of theOptString - retval = false; - } - else if(theOptString.charAt(index) == ':'){ - retval = true; - } - return retval; - } - private String theOptString = null; - } // end class OptionMatcher -}// end class GetOpt --- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/cmdline/getopt/GetOptsException.java 2015-07-01 14:50:27.000000000 +0200 +++ /dev/null 2015-07-01 14:50:27.000000000 +0200 @@ -1,34 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2001-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: GetOptsException.java,v 1.2.4.1 2005/08/31 11:47:06 pvedula Exp $ - */ - -package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt; - -/** - * @author G Todd Miller - */ -public class GetOptsException extends Exception{ - static final long serialVersionUID = 8736874967183039804L; - public GetOptsException(String msg){ - super(msg); - } -} --- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/cmdline/getopt/IllegalArgumentException.java 2015-07-01 14:50:27.000000000 +0200 +++ /dev/null 2015-07-01 14:50:27.000000000 +0200 @@ -1,32 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2001-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: IllegalArgumentException.java,v 1.2.4.1 2005/08/31 11:47:56 pvedula Exp $ - */ - -package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt; - - -class IllegalArgumentException extends GetOptsException{ - static final long serialVersionUID = 8642122427294793651L; - public IllegalArgumentException(String msg){ - super(msg); - } -} --- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/cmdline/getopt/MissingOptArgException.java 2015-07-01 14:50:27.000000000 +0200 +++ /dev/null 2015-07-01 14:50:27.000000000 +0200 @@ -1,35 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2001-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: MissingOptArgException.java,v 1.2.4.1 2005/08/31 11:49:21 pvedula Exp $ - */ - -package com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt; - - -/** - * @author G Todd Miller - */ -class MissingOptArgException extends GetOptsException{ - static final long serialVersionUID = -1972471465394544822L; - public MissingOptArgException(String msg){ - super(msg); - } -}