static { if (!Boolean.getBoolean(GridSystemProperties.GG_JETTY_LOG_NO_OVERRIDE)) { String ctgrJetty = "org.eclipse.jetty"; // WARN for this category. String ctgrJettyUtil = "org.eclipse.jetty.util.log"; // ERROR for this... String ctgrJettyUtilComp = "org.eclipse.jetty.util.component"; // ...and this. try { Class<?> logCls = Class.forName("org.apache.log4j.Logger"); Object logJetty = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJetty); Object logJettyUtil = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJettyUtil); Object logJettyUtilComp = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJettyUtilComp); Class<?> lvlCls = Class.forName("org.apache.log4j.Level"); Object warnLvl = lvlCls.getField("WARN").get(null); Object errLvl = lvlCls.getField("ERROR").get(null); logJetty.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, warnLvl); logJettyUtil.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl); logJettyUtilComp.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl); } catch (Exception ignored) { // No-op. } } }
/** * This creates a new <code>{@link Document}</code> from an existing <code>InputStream</code> by * letting a DOM parser handle parsing using the supplied stream. * * @param in <code>InputStream</code> to parse. * @param validate <code>boolean</code> to indicate if validation should occur. * @return <code>Document</code> - instance ready for use. * @throws IOException when I/O error occurs. * @throws JDOMException when errors occur in parsing. */ public Document getDocument(InputStream in, boolean validate) throws IOException, JDOMException { try { // Load the parser class Class parserClass = Class.forName("org.apache.xerces.parsers.DOMParser"); Object parser = parserClass.newInstance(); // Set validation Method setFeature = parserClass.getMethod("setFeature", new Class[] {java.lang.String.class, boolean.class}); setFeature.invoke( parser, new Object[] {"http://xml.org/sax/features/validation", new Boolean(validate)}); // Set namespaces true setFeature.invoke( parser, new Object[] {"http://xml.org/sax/features/namespaces", new Boolean(true)}); // Set the error handler if (validate) { Method setErrorHandler = parserClass.getMethod("setErrorHandler", new Class[] {ErrorHandler.class}); setErrorHandler.invoke(parser, new Object[] {new BuilderErrorHandler()}); } // Parse the document Method parse = parserClass.getMethod("parse", new Class[] {org.xml.sax.InputSource.class}); parse.invoke(parser, new Object[] {new InputSource(in)}); // Get the Document object Method getDocument = parserClass.getMethod("getDocument", null); Document doc = (Document) getDocument.invoke(parser, null); return doc; } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof org.xml.sax.SAXParseException) { SAXParseException parseException = (SAXParseException) targetException; throw new JDOMException( "Error on line " + parseException.getLineNumber() + " of XML document: " + parseException.getMessage(), e); } else if (targetException instanceof IOException) { IOException ioException = (IOException) targetException; throw ioException; } else { throw new JDOMException(targetException.getMessage(), e); } } catch (Exception e) { throw new JDOMException(e.getClass().getName() + ": " + e.getMessage(), e); } }
/** * Creates a SAX XMLReader. * * @return <code>XMLReader</code> a SAX2 parser. * @throws Exception if no parser can be created. */ protected XMLReader createParser() throws Exception { XMLReader parser = null; // Try using JAXP... // Note we need JAXP 1.1, and if JAXP 1.0 is all that's // available then the getXMLReader call fails and we skip // to the hard coded default parser try { Class factoryClass = Class.forName("javax.xml.parsers.SAXParserFactory"); // MODIFIED: Added (Class[]) and (Object[]) cast sentences in "null" parameters // to avoid warnings during compilation // factory = SAXParserFactory.newInstance(); Method newParserInstance = factoryClass.getMethod("newInstance", (Class[]) null); Object factory = newParserInstance.invoke(null, (Object[]) null); // jaxpParser = factory.newSAXParser(); Method newSAXParser = factoryClass.getMethod("newSAXParser", (Class[]) null); Object jaxpParser = newSAXParser.invoke(factory, (Object[]) null); // parser = jaxpParser.getXMLReader(); Class parserClass = jaxpParser.getClass(); Method getXMLReader = parserClass.getMethod("getXMLReader", (Class[]) null); parser = (XMLReader) getXMLReader.invoke(jaxpParser, (Object[]) null); } catch (ClassNotFoundException e) { // e.printStackTrace(); } catch (InvocationTargetException e) { // e.printStackTrace(); } catch (NoSuchMethodException e) { // e.printStackTrace(); } catch (IllegalAccessException e) { // e.printStackTrace(); } // Check to see if we got a parser yet, if not, try to use a // hard coded default if (parser == null) { parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); } return parser; }