/**
   * Report version info from DOM interfaces.
   *
   * <p>Currently distinguishes between pre-DOM level 2, the DOM level 2 working draft, the DOM
   * level 2 final draft, and not found.
   *
   * @param h Hashtable to put information in
   */
  protected void checkDOMVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    final String DOM_LEVEL2_CLASS = "org.w3c.dom.Document";
    final String DOM_LEVEL2_METHOD = "createElementNS"; // String, String
    final String DOM_LEVEL3_METHOD = "getDoctype"; // no parameter
    final String DOM_LEVEL2WD_CLASS = "org.w3c.dom.Node";
    final String DOM_LEVEL2WD_METHOD = "supported"; // String, String
    final String DOM_LEVEL2FD_CLASS = "org.w3c.dom.Node";
    final String DOM_LEVEL2FD_METHOD = "isSupported"; // String, String
    final Class twoStringArgs[] = {java.lang.String.class, java.lang.String.class};

    try {
      Class clazz = ObjectFactory.findProviderClass(DOM_LEVEL2_CLASS, true);

      Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);

      // If we succeeded, we have loaded interfaces from a
      //  level 2 DOM somewhere
      h.put(VERSION + "DOM", "2.0");

      try {
        // Check for the working draft version, which is
        //  commonly found, but won't work anymore
        clazz = ObjectFactory.findProviderClass(DOM_LEVEL2WD_CLASS, true);

        method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);

        h.put(ERROR + VERSION + "DOM.draftlevel", "2.0wd");
        h.put(ERROR, ERROR_FOUND);
      } catch (Exception e2) {
        try {
          // Check for the final draft version as well
          clazz = ObjectFactory.findProviderClass(DOM_LEVEL2FD_CLASS, true);

          method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);

          h.put(VERSION + "DOM.draftlevel", "2.0fd");
        } catch (Exception e3) {
          h.put(ERROR + VERSION + "DOM.draftlevel", "2.0unknown");
          h.put(ERROR, ERROR_FOUND);
        }
      }
    } catch (Exception e) {
      h.put(ERROR + VERSION + "DOM", "ERROR attempting to load DOM level 2 class: " + e.toString());
      h.put(ERROR, ERROR_FOUND);
    }

    // @todo load an actual DOM implmementation and query it as well
    // @todo load an actual DOM implmementation and check if
    //  isNamespaceAware() == true, which is needed to parse
    //  xsl stylesheet files into a DOM
  }
  /**
   * Report product version information from common parsers.
   *
   * <p>Looks for version info in xerces.jar/xercesImpl.jar/crimson.jar.
   *
   * <p>//@todo actually look up version info in crimson manifest
   *
   * @param h Hashtable to put information in
   */
  protected void checkParserVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    try {
      final String XERCES1_VERSION_CLASS = "com.sun.org.apache.xerces.internal.framework.Version";

      Class clazz = ObjectFactory.findProviderClass(XERCES1_VERSION_CLASS, true);

      // Found Xerces-J 1.x, grab it's version fields
      Field f = clazz.getField("fVersion");
      String parserVersion = (String) f.get(null);

      h.put(VERSION + "xerces1", parserVersion);
    } catch (Exception e) {
      h.put(VERSION + "xerces1", CLASS_NOTPRESENT);
    }

    // Look for xerces1 and xerces2 parsers separately
    try {
      final String XERCES2_VERSION_CLASS = "com.sun.org.apache.xerces.internal.impl.Version";

      Class clazz = ObjectFactory.findProviderClass(XERCES2_VERSION_CLASS, true);

      // Found Xerces-J 2.x, grab it's version fields
      Field f = clazz.getField("fVersion");
      String parserVersion = (String) f.get(null);

      h.put(VERSION + "xerces2", parserVersion);
    } catch (Exception e) {
      h.put(VERSION + "xerces2", CLASS_NOTPRESENT);
    }

    try {
      final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";

      Class clazz = ObjectFactory.findProviderClass(CRIMSON_CLASS, true);

      // @todo determine specific crimson version
      h.put(VERSION + "crimson", CLASS_PRESENT);
    } catch (Exception e) {
      h.put(VERSION + "crimson", CLASS_NOTPRESENT);
    }
  }
  /**
   * Report version information about JAXP interfaces.
   *
   * <p>Currently distinguishes between JAXP 1.0.1 and JAXP 1.1, and not found; only tests the
   * interfaces, and does not check for reference implementation versions.
   *
   * @param h Hashtable to put information in
   */
  protected void checkJAXPVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    Class clazz = null;

    try {
      final String JAXP1_CLASS = "javax.xml.stream.XMLStreamConstants";

      clazz = ObjectFactory.findProviderClass(JAXP1_CLASS, true);

      // If we succeeded, we have JAXP 1.4 available
      h.put(VERSION + "JAXP", "1.4");
    } catch (Exception e) {
      h.put(ERROR + VERSION + "JAXP", "1.3");
      h.put(ERROR, ERROR_FOUND);
    }
  }
  /**
   * Report product version information from Ant.
   *
   * @param h Hashtable to put information in
   */
  protected void checkAntVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    try {
      final String ANT_VERSION_CLASS = "org.apache.tools.ant.Main";
      final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
      final Class noArgs[] = new Class[0];

      Class clazz = ObjectFactory.findProviderClass(ANT_VERSION_CLASS, true);

      Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
      Object returnValue = method.invoke(null, new Object[0]);

      h.put(VERSION + "ant", (String) returnValue);
    } catch (Exception e) {
      h.put(VERSION + "ant", CLASS_NOTPRESENT);
    }
  }
  /**
   * Report version info from DOM interfaces.
   *
   * @param h Hashtable to put information in
   */
  protected boolean checkDOML3(Hashtable h) {

    if (null == h) h = new Hashtable();

    final String DOM_CLASS = "org.w3c.dom.Document";
    final String DOM_LEVEL3_METHOD = "getDoctype"; // no parameter

    try {
      Class clazz = ObjectFactory.findProviderClass(DOM_CLASS, true);

      Method method = clazz.getMethod(DOM_LEVEL3_METHOD, (Class<?>[]) null);

      // If we succeeded, we have loaded interfaces from a
      //  level 3 DOM somewhere
      h.put(VERSION + "DOM", "3.0");
      return true;
    } catch (Exception e) {
      return false;
    }
  }
 /*     */ public final void initialize(int node, int last, DOM dom, SortSettings settings)
     /*     */ throws TransletException
       /*     */ {
   /* 104 */ this._dom = dom;
   /* 105 */ this._node = node;
   /* 106 */ this._last = last;
   /* 107 */ this._settings = settings;
   /*     */
   /* 109 */ int levels = settings.getSortOrders().length;
   /* 110 */ this._values = new Object[levels];
   /*     */
   /* 112 */ String colFactClassname = null;
   /*     */ try
   /*     */ {
     /* 115 */ colFactClassname =
         SecuritySupport.getSystemProperty(
             "com.sun.org.apache.xalan.internal.xsltc.COLLATOR_FACTORY");
     /*     */ }
   /*     */ catch (SecurityException e)
   /*     */ {
     /*     */ }
   /*     */
   /* 122 */ if (colFactClassname != null) {
     /*     */ try {
       /* 124 */ Object candObj = ObjectFactory.findProviderClass(colFactClassname, true);
       /* 125 */ this._collatorFactory = ((CollatorFactory) candObj);
       /*     */ } catch (ClassNotFoundException e) {
       /* 127 */ throw new TransletException(e);
       /*     */ }
     /* 129 */ Locale[] locales = settings.getLocales();
     /* 130 */ this._collators = new Collator[levels];
     /* 131 */ for (int i = 0; i < levels; i++) {
       /* 132 */ this._collators[i] = this._collatorFactory.getCollator(locales[i]);
       /*     */ }
     /* 134 */ this._collator = this._collators[0];
     /*     */ } else {
     /* 136 */ this._collators = settings.getCollators();
     /* 137 */ this._collator = this._collators[0];
     /*     */ }
   /*     */ }
  /**
   * Returns a serializer for the specified output method. The output method is specified by the
   * value of the property associated with the "method" key. If no implementation exists that
   * supports the specified output method an exception of some type will be thrown. For a list of
   * the output "method" key values see {@link Method}.
   *
   * @param format The output format, minimally the "method" property must be set.
   * @return A suitable serializer.
   * @throws IllegalArgumentException if method is null or an appropriate serializer can't be found
   * @throws Exception if the class for the serializer is found but does not implement
   *     ContentHandler.
   * @throws WrappedRuntimeException if an exception is thrown while trying to find serializer
   */
  public static Serializer getSerializer(Properties format) {
    Serializer ser;

    try {
      String method = format.getProperty(OutputKeys.METHOD);

      if (method == null) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_FACTORY_PROPERTY_MISSING, new Object[] {OutputKeys.METHOD});
        throw new IllegalArgumentException(msg);
      }

      String className = format.getProperty(OutputPropertiesFactory.S_KEY_CONTENT_HANDLER);

      if (null == className) {
        // Missing Content Handler property, load default using OutputPropertiesFactory
        Properties methodDefaults = OutputPropertiesFactory.getDefaultMethodProperties(method);
        className = methodDefaults.getProperty(OutputPropertiesFactory.S_KEY_CONTENT_HANDLER);
        if (null == className) {
          String msg =
              Utils.messages.createMessage(
                  MsgKey.ER_FACTORY_PROPERTY_MISSING,
                  new Object[] {OutputPropertiesFactory.S_KEY_CONTENT_HANDLER});
          throw new IllegalArgumentException(msg);
        }
      }

      Class cls = ObjectFactory.findProviderClass(className, true);

      // _serializers.put(method, cls);

      Object obj = cls.newInstance();

      if (obj instanceof SerializationHandler) {
        // this is one of the supplied serializers
        ser = (Serializer) cls.newInstance();
        ser.setOutputFormat(format);
      } else {
        /*
         *  This  must be a user defined Serializer.
         *  It had better implement ContentHandler.
         */
        if (obj instanceof ContentHandler) {

          /*
           * The user defined serializer defines ContentHandler,
           * but we need to wrap it with ToXMLSAXHandler which
           * will collect SAX-like events and emit true
           * SAX ContentHandler events to the users handler.
           */
          className = SerializerConstants.DEFAULT_SAX_SERIALIZER;
          cls = ObjectFactory.findProviderClass(className, true);
          SerializationHandler sh = (SerializationHandler) cls.newInstance();
          sh.setContentHandler((ContentHandler) obj);
          sh.setOutputFormat(format);

          ser = sh;
        } else {
          // user defined serializer does not implement
          // ContentHandler, ... very bad
          throw new Exception(
              Utils.messages.createMessage(
                  MsgKey.ER_SERIALIZER_NOT_CONTENTHANDLER, new Object[] {className}));
        }
      }
    } catch (Exception e) {
      throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(e);
    }

    // If we make it to here ser is not null.
    return ser;
  }
  /**
   * Report version info from SAX interfaces.
   *
   * <p>Currently distinguishes between SAX 2, SAX 2.0beta2, SAX1, and not found.
   *
   * @param h Hashtable to put information in
   */
  protected void checkSAXVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    final String SAX_VERSION1_CLASS = "org.xml.sax.Parser";
    final String SAX_VERSION1_METHOD = "parse"; // String
    final String SAX_VERSION2_CLASS = "org.xml.sax.XMLReader";
    final String SAX_VERSION2_METHOD = "parse"; // String
    final String SAX_VERSION2BETA_CLASSNF = "org.xml.sax.helpers.AttributesImpl";
    final String SAX_VERSION2BETA_METHODNF = "setAttributes"; // Attributes
    final Class oneStringArg[] = {java.lang.String.class};
    // Note this introduces a minor compile dependency on SAX...
    final Class attributesArg[] = {org.xml.sax.Attributes.class};

    try {
      // This method was only added in the final SAX 2.0 release;
      //  see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease"
      Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2BETA_CLASSNF, true);

      Method method = clazz.getMethod(SAX_VERSION2BETA_METHODNF, attributesArg);

      // If we succeeded, we have loaded interfaces from a
      //  real, final SAX version 2.0 somewhere
      h.put(VERSION + "SAX", "2.0");
    } catch (Exception e) {
      // If we didn't find the SAX 2.0 class, look for a 2.0beta2
      h.put(
          ERROR + VERSION + "SAX", "ERROR attempting to load SAX version 2 class: " + e.toString());
      h.put(ERROR, ERROR_FOUND);

      try {
        Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2_CLASS, true);

        Method method = clazz.getMethod(SAX_VERSION2_METHOD, oneStringArg);

        // If we succeeded, we have loaded interfaces from a
        //  SAX version 2.0beta2 or earlier; these might work but
        //  you should really have the final SAX 2.0
        h.put(VERSION + "SAX-backlevel", "2.0beta2-or-earlier");
      } catch (Exception e2) {
        // If we didn't find the SAX 2.0beta2 class, look for a 1.0 one
        h.put(
            ERROR + VERSION + "SAX",
            "ERROR attempting to load SAX version 2 class: " + e.toString());
        h.put(ERROR, ERROR_FOUND);

        try {
          Class clazz = ObjectFactory.findProviderClass(SAX_VERSION1_CLASS, true);

          Method method = clazz.getMethod(SAX_VERSION1_METHOD, oneStringArg);

          // If we succeeded, we have loaded interfaces from a
          //  SAX version 1.0 somewhere; which won't work very
          //  well for JAXP 1.1 or beyond!
          h.put(VERSION + "SAX-backlevel", "1.0");
        } catch (Exception e3) {
          // If we didn't find the SAX 2.0 class, look for a 1.0 one
          // Note that either 1.0 or no SAX are both errors
          h.put(
              ERROR + VERSION + "SAX-backlevel",
              "ERROR attempting to load SAX version 1 class: " + e3.toString());
        }
      }
    }
  }
  /**
   * Report product version information from Xalan-J.
   *
   * <p>Looks for version info in xalan.jar from Xalan-J products.
   *
   * @param h Hashtable to put information in
   */
  protected void checkProcessorVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    try {
      final String XALAN1_VERSION_CLASS =
          "com.sun.org.apache.xalan.internal.xslt.XSLProcessorVersion";

      Class clazz = ObjectFactory.findProviderClass(XALAN1_VERSION_CLASS, true);

      // Found Xalan-J 1.x, grab it's version fields
      StringBuffer buf = new StringBuffer();
      Field f = clazz.getField("PRODUCT");

      buf.append(f.get(null));
      buf.append(';');

      f = clazz.getField("LANGUAGE");

      buf.append(f.get(null));
      buf.append(';');

      f = clazz.getField("S_VERSION");

      buf.append(f.get(null));
      buf.append(';');
      h.put(VERSION + "xalan1", buf.toString());
    } catch (Exception e1) {
      h.put(VERSION + "xalan1", CLASS_NOTPRESENT);
    }

    try {
      // NOTE: This is the old Xalan 2.0, 2.1, 2.2 version class,
      //    is being replaced by class below
      final String XALAN2_VERSION_CLASS =
          "com.sun.org.apache.xalan.internal.processor.XSLProcessorVersion";

      Class clazz = ObjectFactory.findProviderClass(XALAN2_VERSION_CLASS, true);

      // Found Xalan-J 2.x, grab it's version fields
      StringBuffer buf = new StringBuffer();
      Field f = clazz.getField("S_VERSION");
      buf.append(f.get(null));

      h.put(VERSION + "xalan2x", buf.toString());
    } catch (Exception e2) {
      h.put(VERSION + "xalan2x", CLASS_NOTPRESENT);
    }
    try {
      // NOTE: This is the new Xalan 2.2+ version class
      final String XALAN2_2_VERSION_CLASS = "com.sun.org.apache.xalan.internal.Version";
      final String XALAN2_2_VERSION_METHOD = "getVersion";
      final Class noArgs[] = new Class[0];

      Class clazz = ObjectFactory.findProviderClass(XALAN2_2_VERSION_CLASS, true);

      Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);
      Object returnValue = method.invoke(null, new Object[0]);

      h.put(VERSION + "xalan2_2", (String) returnValue);
    } catch (Exception e2) {
      h.put(VERSION + "xalan2_2", CLASS_NOTPRESENT);
    }
  }
Exemplo n.º 10
0
 /*     */ private void doTransform() {
   /*     */ try {
     /* 101 */ Class clazz = ObjectFactory.findProviderClass(this._className, true);
     /* 102 */ AbstractTranslet translet = (AbstractTranslet) clazz.newInstance();
     /* 103 */ translet.postInitialization();
     /*     */
     /* 106 */ SAXParserFactory factory = SAXParserFactory.newInstance();
     /*     */ try {
       /* 108 */ factory.setFeature("http://xml.org/sax/features/namespaces", true);
       /*     */ }
     /*     */ catch (Exception e) {
       /* 111 */ factory.setNamespaceAware(true);
       /*     */ }
     /* 113 */ SAXParser parser = factory.newSAXParser();
     /* 114 */ XMLReader reader = parser.getXMLReader();
     /*     */
     /* 117 */ XSLTCDTMManager dtmManager =
         (XSLTCDTMManager) XSLTCDTMManager.getDTMManagerClass().newInstance();
     /*     */ DTMWSFilter wsfilter;
     /*     */ DTMWSFilter wsfilter;
     /* 122 */ if ((translet != null) && ((translet instanceof StripFilter)))
       /* 123 */ wsfilter = new DOMWSFilter(translet);
     /*     */ else {
       /* 125 */ wsfilter = null;
       /*     */ }
     /*     */
     /* 128 */ DOMEnhancedForDTM dom =
         (DOMEnhancedForDTM)
             dtmManager.getDTM(
                 new SAXSource(reader, new InputSource(this._fileName)),
                 false,
                 wsfilter,
                 true,
                 false,
                 translet.hasIdCall());
     /*     */
     /* 133 */ dom.setDocumentURI(this._fileName);
     /* 134 */ translet.prepassDocument(dom);
     /*     */
     /* 137 */ int n = this._params.size();
     /* 138 */ for (int i = 0; i < n; i++) {
       /* 139 */ Parameter param = (Parameter) this._params.elementAt(i);
       /* 140 */ translet.addParameter(param._name, param._value);
       /*     */ }
     /*     */
     /* 144 */ TransletOutputHandlerFactory tohFactory =
         TransletOutputHandlerFactory.newInstance();
     /*     */
     /* 146 */ tohFactory.setOutputType(0);
     /* 147 */ tohFactory.setEncoding(translet._encoding);
     /* 148 */ tohFactory.setOutputMethod(translet._method);
     /*     */
     /* 150 */ if (this._iterations == -1) {
       /* 151 */ translet.transform(dom, tohFactory.getSerializationHandler());
       /*     */ }
     /* 153 */ else if (this._iterations > 0) {
       /* 154 */ long mm = System.currentTimeMillis();
       /* 155 */ for (int i = 0; i < this._iterations; i++) {
         /* 156 */ translet.transform(dom, tohFactory.getSerializationHandler());
         /*     */ }
       /*     */
       /* 159 */ mm = System.currentTimeMillis() - mm;
       /*     */
       /* 161 */ System.err.println("\n<!--");
       /* 162 */ System.err.println("  transform  = " + mm / this._iterations + " ms");
       /*     */
       /* 165 */ System.err.println(
           "  throughput = " + 1000.0D / (mm / this._iterations) + " tps");
       /*     */
       /* 169 */ System.err.println("-->");
       /*     */ }
     /*     */ }
   /*     */ catch (TransletException e) {
     /* 173 */ if (this._debug) e.printStackTrace();
     /* 174 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + e.getMessage());
     /*     */ }
   /*     */ catch (RuntimeException e)
   /*     */ {
     /* 178 */ if (this._debug) e.printStackTrace();
     /* 179 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + e.getMessage());
     /*     */ }
   /*     */ catch (FileNotFoundException e)
   /*     */ {
     /* 183 */ if (this._debug) e.printStackTrace();
     /* 184 */ ErrorMsg err = new ErrorMsg("FILE_NOT_FOUND_ERR", this._fileName);
     /* 185 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (MalformedURLException e)
   /*     */ {
     /* 189 */ if (this._debug) e.printStackTrace();
     /* 190 */ ErrorMsg err = new ErrorMsg("INVALID_URI_ERR", this._fileName);
     /* 191 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (ClassNotFoundException e)
   /*     */ {
     /* 195 */ if (this._debug) e.printStackTrace();
     /* 196 */ ErrorMsg err = new ErrorMsg("CLASS_NOT_FOUND_ERR", this._className);
     /* 197 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (UnknownHostException e)
   /*     */ {
     /* 201 */ if (this._debug) e.printStackTrace();
     /* 202 */ ErrorMsg err = new ErrorMsg("INVALID_URI_ERR", this._fileName);
     /* 203 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (SAXException e)
   /*     */ {
     /* 207 */ Exception ex = e.getException();
     /* 208 */ if (this._debug) {
       /* 209 */ if (ex != null) ex.printStackTrace();
       /* 210 */ e.printStackTrace();
       /*     */ }
     /* 212 */ System.err.print(new ErrorMsg("RUNTIME_ERROR_KEY"));
     /* 213 */ if (ex != null) /* 214 */ System.err.println(ex.getMessage());
     /*     */ else /* 216 */ System.err.println(e.getMessage());
     /*     */ }
   /*     */ catch (Exception e) {
     /* 219 */ if (this._debug) e.printStackTrace();
     /* 220 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + e.getMessage());
     /*     */ }
   /*     */ }
Exemplo n.º 11
0
  // J2SE does not support Xalan interpretive
  // main -> _main
  public static void _main(String argv[]) {

    // Runtime.getRuntime().traceMethodCalls(false); // turns Java tracing off
    boolean doStackDumpOnError = false;
    boolean setQuietMode = false;
    boolean doDiag = 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;
    ResourceBundle resbundle =
        (SecuritySupport.getResourceBundle(
            com.sun.org.apache.xml.internal.utils.res.XResourceBundle.ERROR_RESOURCES));
    String flavor = "s2s";

    if (argv.length < 1) {
      printArgOptions(resbundle);
    } 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(new DefaultErrorHandler());
      } catch (TransformerFactoryConfigurationError pfe) {
        pfe.printStackTrace(dumpWriter);
        //      "XSL Process was not successful.");
        msg = XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUCCESSFUL, null);
        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;
      // J2SE does not support Xalan interpretive
      /*
      PrintTraceListener tracer = null;
      */
      String outputType = null;
      String media = null;
      Vector params = new Vector();
      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 ("-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);
        }
        */
        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;
          }

          // TBD:
          // xmlProcessorLiaison.setIndent(indentAmount);
        } else if ("-IN".equalsIgnoreCase(argv[i])) {
          if (i + 1 < argv.length && argv[i + 1].charAt(0) != '-') inFileName = argv[++i];
          else
            System.err.println(
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-IN"})); // "Missing argument for);
        } else if ("-MEDIA".equalsIgnoreCase(argv[i])) {
          if (i + 1 < argv.length) media = argv[++i];
          else
            System.err.println(
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-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(
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-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(
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-XSL"})); // "Missing argument for);
        } else if ("-FLAVOR".equalsIgnoreCase(argv[i])) {
          if (i + 1 < argv.length) {
            flavor = argv[++i];
          } else
            System.err.println(
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-FLAVOR"})); // "Missing argument for);
        } else if ("-PARAM".equalsIgnoreCase(argv[i])) {
          if (i + 2 < argv.length) {
            String name = argv[++i];

            params.addElement(name);

            String expression = argv[++i];

            params.addElement(expression);
          } else
            System.err.println(
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-PARAM"})); // "Missing argument for);
        } else if ("-E".equalsIgnoreCase(argv[i])) {

          // TBD:
          // xmlProcessorLiaison.setShouldExpandEntityRefs(false);
        } else if ("-V".equalsIgnoreCase(argv[i])) {
          diagnosticsWriter.println(
              resbundle.getString("version") // ">>>>>>> Xalan Version "
                  + Version.getVersion()
                  + ", "
                  +

                  /* xmlProcessorLiaison.getParserDescription()+ */
                  resbundle.getString("version2")); // "<<<<<<<");
        }
        // 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 {
              uriResolver = (URIResolver) ObjectFactory.newInstance(argv[++i], true);

              tfactory.setURIResolver(uriResolver);
            } catch (ConfigurationError cnfe) {
              msg =
                  XSLMessages.createMessage(
                      XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
                      new Object[] {"-URIResolver"});
              System.err.println(msg);
              doExit(msg);
            }
          } else {
            msg =
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                    new Object[] {"-URIResolver"}); // "Missing argument for);
            System.err.println(msg);
            doExit(msg);
          }
        } else if ("-ENTITYRESOLVER".equalsIgnoreCase(argv[i])) {
          if (i + 1 < argv.length) {
            try {
              entityResolver = (EntityResolver) ObjectFactory.newInstance(argv[++i], true);
            } catch (ConfigurationError cnfe) {
              msg =
                  XSLMessages.createMessage(
                      XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
                      new Object[] {"-EntityResolver"});
              System.err.println(msg);
              doExit(msg);
            }
          } else {
            //            "Missing argument for);
            msg =
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION, new Object[] {"-EntityResolver"});
            System.err.println(msg);
            doExit(msg);
          }
        } else if ("-CONTENTHANDLER".equalsIgnoreCase(argv[i])) {
          if (i + 1 < argv.length) {
            try {
              contentHandler = (ContentHandler) ObjectFactory.newInstance(argv[++i], true);
            } catch (ConfigurationError cnfe) {
              msg =
                  XSLMessages.createMessage(
                      XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
                      new Object[] {"-ContentHandler"});
              System.err.println(msg);
              doExit(msg);
            }
          } else {
            //            "Missing argument for);
            msg =
                XSLMessages.createMessage(
                    XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION, new Object[] {"-ContentHandler"});
            System.err.println(msg);
            doExit(msg);
          }
        }
        // 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
              ("http://xml.apache.org/xalan/features/incremental",
               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
              ("http://xml.apache.org/xalan/features/optimize",
               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.
        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(
                  XSLMessages.createMessage(
                      XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                      new Object[] {"-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(
                  XSLMessages.createMessage(
                      XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                      new Object[] {"-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(
                  XSLMessages.createMessage(
                      XSLTErrorResources.ER_MISSING_ARG_FOR_OPTION,
                      new Object[] {"-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(
              XSLMessages.createMessage(
                  XSLTErrorResources.ER_INVALID_OPTION,
                  new Object[] {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 = resbundle.getString("xslProc_no_input");
        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;

        // 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) {
          Source source =
              stf.getAssociatedStylesheet(new StreamSource(inFileName), media, null, null);

          if (null != source) stylesheet = tfactory.newTemplates(source);
          else {
            if (null != media)
              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) {
          Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer();
          transformer.setErrorListener(new DefaultErrorHandler());

          // Override the output format?
          if (null != outputType) {
            transformer.setOutputProperty(OutputKeys.METHOD, 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 );
          }
          */

          int nParams = params.size();

          for (int i = 0; i < nParams; i += 2) {
            transformer.setParameter(
                (String) params.elementAt(i), (String) params.elementAt(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(new DefaultErrorHandler());

              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();
                }

                // J2SE does not support Xalan interpretive
                /*
                if (!useXSLTC)
                  stf.setAttribute(com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl.FEATURE_INCREMENTAL,
                     Boolean.TRUE);
                */

                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 = XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUCCESSFUL, null);
          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) {
          Object[] msgArgs = new Object[] {inFileName, xslFileName, new Long(millisecondsDuration)};
          msg = XSLMessages.createMessage("diagTiming", msgArgs);
          diagnosticsWriter.println('\n');
          diagnosticsWriter.println(msg);
        }

      } catch (Throwable throwable) {
        while (throwable instanceof com.sun.org.apache.xml.internal.utils.WrappedRuntimeException) {
          throwable =
              ((com.sun.org.apache.xml.internal.utils.WrappedRuntimeException) throwable)
                  .getException();
        }

        if ((throwable instanceof NullPointerException)
            || (throwable instanceof ClassCastException)) doStackDumpOnError = true;

        diagnosticsWriter.println();

        if (doStackDumpOnError) throwable.printStackTrace(dumpWriter);
        else {
          DefaultErrorHandler.printLocation(diagnosticsWriter, throwable);
          diagnosticsWriter.println(
              XSLMessages.createMessage(XSLTErrorResources.ER_XSLT_ERROR, null)
                  + " ("
                  + throwable.getClass().getName()
                  + "): "
                  + throwable.getMessage());
        }

        // 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");
    }
  }