List of usage examples for org.xml.sax XMLReader getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:net.sf.joost.stx.Processor.java
/** * Create an <code>XMLReader</code> object (a SAX Parser) * @throws SAXException if a SAX Parser couldn't be created *//*from w ww .ja v a 2 s . co m*/ public static XMLReader createXMLReader() throws SAXException { // Using pure SAX2, not JAXP XMLReader reader = null; try { // try default parser implementation reader = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { String prop = System.getProperty("org.xml.sax.driver"); if (prop != null) { // property set, but still failed throw new SAXException("Can't create XMLReader for class " + prop); // leave the method here } // try another SAX implementation String PARSER_IMPLS[] = { "org.apache.xerces.parsers.SAXParser", // Xerces "org.apache.crimson.parser.XMLReaderImpl", // Crimson "gnu.xml.aelfred2.SAXDriver" // Aelfred nonvalidating }; for (int i = 0; i < PARSER_IMPLS.length; i++) { try { reader = XMLReaderFactory.createXMLReader(PARSER_IMPLS[i]); break; // for (...) } catch (SAXException e1) { } // continuing } if (reader == null) { throw new SAXException("Can't find SAX parser implementation.\n" + "Please specify a parser class via the system property " + "'org.xml.sax.driver'"); } } // set features and properties that have been put // into the system properties (e.g. via command line) Properties sysProps = System.getProperties(); for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements();) { String propKey = (String) e.nextElement(); if (propKey.startsWith(EXTERN_SAX_FEATURE_PREFIX)) { reader.setFeature(propKey.substring(EXTERN_SAX_FEATURE_PREFIX.length()), Boolean.parseBoolean(sysProps.getProperty(propKey))); continue; } if (propKey.startsWith(EXTERN_SAX_PROPERTY_PREFIX)) { reader.setProperty(propKey.substring(EXTERN_SAX_PROPERTY_PREFIX.length()), sysProps.getProperty(propKey)); continue; } } if (DEBUG) log.debug("Using " + reader.getClass().getName()); return reader; }
From source file:org.dhatim.delivery.AbstractParser.java
protected void configureReader(XMLReader reader, DefaultHandler2 handler, ExecutionContext execContext, Source source) throws SAXException { if (reader instanceof SmooksXMLReader) { ((SmooksXMLReader) reader).setExecutionContext(execContext); }/* www . ja v a 2s . c om*/ if (reader instanceof JavaXMLReader) { if (!(source instanceof JavaSource)) { throw new SAXException("A " + JavaSource.class.getName() + " source must be supplied for " + JavaXMLReader.class.getName() + " implementations."); } ((JavaXMLReader) reader).setSourceObjects(((JavaSource) source).getSourceObjects()); } reader.setContentHandler(handler); try { reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); } catch (SAXNotRecognizedException e) { logger.debug( "XMLReader property 'http://xml.org/sax/properties/lexical-handler' not recognized by XMLReader '" + reader.getClass().getName() + "'."); } }