removing tricks related to JDK 1.4 logging_35067_root
authorrkubacki@netbeans.org
Mon, 20 Mar 2006 15:44:27 +0000
changeset 1316e8c01adc7c1
parent 130 99bf3b6ecd3f
child 132 771a1692b59b
removing tricks related to JDK 1.4
openide.util/src/org/openide/xml/XMLUtil.java
     1.1 --- a/openide.util/src/org/openide/xml/XMLUtil.java	Thu Mar 09 07:20:46 2006 +0000
     1.2 +++ b/openide.util/src/org/openide/xml/XMLUtil.java	Mon Mar 20 15:44:27 2006 +0000
     1.3 @@ -131,8 +131,6 @@
     1.4   * @author  Petr Kuzel
     1.5   * @since release 3.2 */
     1.6  public final class XMLUtil extends Object {
     1.7 -    /** Use fast SAX parser factory until someone asks for validating parser. */
     1.8 -    private static boolean useFastSAXParserFactory = true;
     1.9  
    1.10      /*
    1.11          public static String toCDATA(String val) throws IOException {
    1.12 @@ -183,19 +181,7 @@
    1.13      public static XMLReader createXMLReader(boolean validate, boolean namespaceAware)
    1.14      throws SAXException {
    1.15          SAXParserFactory factory;
    1.16 -
    1.17 -        if (!validate && useFastSAXParserFactory) {
    1.18 -            try {
    1.19 -                factory = createFastSAXParserFactory();
    1.20 -            } catch (ParserConfigurationException ex) {
    1.21 -                factory = SAXParserFactory.newInstance();
    1.22 -            } catch (SAXException ex) {
    1.23 -                factory = SAXParserFactory.newInstance();
    1.24 -            }
    1.25 -        } else {
    1.26 -            useFastSAXParserFactory = false;
    1.27 -            factory = SAXParserFactory.newInstance();
    1.28 -        }
    1.29 +        factory = SAXParserFactory.newInstance();
    1.30  
    1.31          factory.setValidating(validate);
    1.32          factory.setNamespaceAware(namespaceAware);
    1.33 @@ -363,18 +349,6 @@
    1.34              throw new NullPointerException("You must set an encoding; use \"UTF-8\" unless you have a good reason not to!"); // NOI18N
    1.35          }
    1.36          Document doc2 = normalize(doc);
    1.37 -        if (System.getProperty("java.specification.version").startsWith("1.4")) { // NOI18N
    1.38 -            // Hack for JDK 1.4. Using JAXP won't work; e.g. JDK bug #6308026.
    1.39 -            // Try using Xerces instead - let's hope it's loadable...
    1.40 -            try {
    1.41 -                writeXerces(doc2, out, enc);
    1.42 -                return;
    1.43 -            } catch (ClassNotFoundException e) {
    1.44 -                throw (IOException) new IOException("You need to have xerces.jar available to use XMLUtil.write under JDK 1.4: " + e).initCause(e); // NOI18N
    1.45 -            } catch (Exception e) {
    1.46 -                throw (IOException) new IOException(e.toString()).initCause(e);
    1.47 -            }
    1.48 -        }
    1.49          // XXX should try to use org.w3c.dom.ls.LSSerializer if it exists...
    1.50          // XXX #66563 workaround
    1.51          ClassLoader orig = Thread.currentThread().getContextClassLoader();
    1.52 @@ -413,38 +387,6 @@
    1.53              Thread.currentThread().setContextClassLoader(orig);
    1.54          }
    1.55      }
    1.56 -    /**
    1.57 -     * Serialize a document using Xerces' library.
    1.58 -     * This library is available in the JDK starting with version 1.5 (where we do not need it anyway),
    1.59 -     * but in 1.4 you need to have Xerces loaded in the system somewhere.
    1.60 -     */
    1.61 -    private static void writeXerces(Document doc, OutputStream out, String encoding) throws ClassNotFoundException, Exception {
    1.62 -        ClassLoader cl = Thread.currentThread().getContextClassLoader();
    1.63 -        Class xmlSerializerClazz = Class.forName("org.apache.xml.serialize.XMLSerializer", true, cl); // NOI18N
    1.64 -        Class outputFormatClazz = Class.forName("org.apache.xml.serialize.OutputFormat", true, cl); // NOI18N
    1.65 -        Object xmlSerializer = xmlSerializerClazz.newInstance();
    1.66 -        Object outputFormat = outputFormatClazz.newInstance();
    1.67 -        Method setMethod = outputFormatClazz.getMethod("setMethod", new Class[] {String.class}); // NOI18N
    1.68 -        setMethod.invoke(outputFormat, new Object[] {"xml"}); // NOI18N
    1.69 -        Method setIndenting = outputFormatClazz.getMethod("setIndenting", new Class[] {Boolean.TYPE}); // NOI18N
    1.70 -        setIndenting.invoke(outputFormat, new Object[] {Boolean.TRUE}); // NOI18N
    1.71 -        Method setLineWidth = outputFormatClazz.getMethod("setLineWidth", new Class[] {Integer.TYPE}); // NOI18N
    1.72 -        setLineWidth.invoke(outputFormat, new Object[] {new Integer(0)});
    1.73 -        Method setLineSeparator = outputFormatClazz.getMethod("setLineSeparator", new Class[] {String.class}); // NOI18N
    1.74 -        setLineSeparator.invoke(outputFormat, new String[] {System.getProperty("line.separator")}); // NOI18N
    1.75 -        Method setOutputByteStream = xmlSerializerClazz.getMethod("setOutputByteStream", new Class[] {OutputStream.class}); // NOI18N
    1.76 -        setOutputByteStream.invoke(xmlSerializer, new Object[] {out});
    1.77 -        Method setEncoding = outputFormatClazz.getMethod("setEncoding", new Class[] {String.class}); // NOI18N
    1.78 -        setEncoding.invoke(outputFormat, new Object[] {encoding});
    1.79 -        Method setOutputFormat = xmlSerializerClazz.getMethod("setOutputFormat", new Class[] {outputFormatClazz}); // NOI18N
    1.80 -        setOutputFormat.invoke(xmlSerializer, new Object[] {outputFormat});
    1.81 -        Method setNamespaces = xmlSerializerClazz.getMethod("setNamespaces", new Class[] {Boolean.TYPE}); // NOI18N
    1.82 -        setNamespaces.invoke(xmlSerializer, new Object[] {Boolean.TRUE});
    1.83 -        Method asDOMSerializer = xmlSerializerClazz.getMethod("asDOMSerializer", new Class[0]); // NOI18N
    1.84 -        Object impl = asDOMSerializer.invoke(xmlSerializer, null);
    1.85 -        Method serialize = impl.getClass().getMethod("serialize", new Class[] {Document.class}); // NOI18N
    1.86 -        serialize.invoke(impl, new Object[] {doc});
    1.87 -    }
    1.88  
    1.89      /**
    1.90       * Escape passed string as XML attibute value
    1.91 @@ -517,7 +459,7 @@
    1.92              return val;
    1.93          }
    1.94  
    1.95 -        StringBuffer buf = new StringBuffer();
    1.96 +        StringBuilder buf = new StringBuilder();
    1.97  
    1.98          for (int i = 0; i < val.length(); i++) {
    1.99              char ch = val.charAt(i);
   1.100 @@ -692,34 +634,6 @@
   1.101          return escape == false;
   1.102      }
   1.103  
   1.104 -    private static SAXParserFactory createFastSAXParserFactory()
   1.105 -    throws ParserConfigurationException, SAXException {
   1.106 -        if (fastParserFactoryClass == null) {
   1.107 -            try {
   1.108 -                fastParserFactoryClass = Class.forName("org.apache.crimson.jaxp.SAXParserFactoryImpl"); // NOI18N
   1.109 -            } catch (Exception ex) {
   1.110 -                useFastSAXParserFactory = false;
   1.111 -
   1.112 -                if (System.getProperty("java.version").startsWith("1.4")) { // NOI18N
   1.113 -                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
   1.114 -                }
   1.115 -            }
   1.116 -        }
   1.117 -
   1.118 -        if (fastParserFactoryClass != null) {
   1.119 -            try {
   1.120 -                SAXParserFactory factory = (SAXParserFactory) fastParserFactoryClass.newInstance();
   1.121 -
   1.122 -                return factory;
   1.123 -            } catch (Exception ex) {
   1.124 -                useFastSAXParserFactory = false;
   1.125 -                throw new ParserConfigurationException(ex.getMessage());
   1.126 -            }
   1.127 -        }
   1.128 -
   1.129 -        return SAXParserFactory.newInstance();
   1.130 -    }
   1.131 -
   1.132      /**
   1.133       * Try to normalize a document by removing nonsignificant whitespace.
   1.134       * @see "#62006"