org.xml.sax.helpers.XMLReaderAdapter Java Examples

The following examples show how to use org.xml.sax.helpers.XMLReaderAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NbTheme.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void parseTheme(){
    try{
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setValidating(false);
        factory.setNamespaceAware(false);

        Parser p = new XMLReaderAdapter(factory.newSAXParser().getXMLReader());
        p.setDocumentHandler(this);
        String externalForm = themeURL.toExternalForm();
        InputSource is = new InputSource(externalForm);
        p.parse(is);
        activeThemes=null;  //dispose of now useless hashtable
        locator = null;
    }
    catch(java.io.IOException ie){
        System.err.println ("IO exception reading theme file"); //NOI18N
    } catch(org.xml.sax.SAXException se){
        System.err.println ("Error parsing theme file " + (locator != null ? "line " + locator.getLineNumber() : "")); //NOI18N
    } catch (ParserConfigurationException e) {
        System.err.println ("Couldn't create XML parser for theme file"); //NOI18N
    }
}
 
Example #2
Source File: XMLReaderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(expectedExceptions = SAXException.class)
public void testcreateXMLReader() throws SAXException, ParserConfigurationException {
    String className = SAXParserFactory.newInstance().newSAXParser()
                        .getXMLReader().getClass().getName();
    setSystemProperty(SAX_PROPNAME, className + "nosuch");
    XMLReaderAdapter adapter = new XMLReaderAdapter();
}
 
Example #3
Source File: XMLReaderAdapterTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testXMLReaderAdapter() {
    System.setProperty("org.xml.sax.driver",
            "org.apache.harmony.tests.org.xml.sax.support.DoNothingXMLReader");

    try {
        new XMLReaderAdapter();
    } catch (SAXException e) {
        throw new RuntimeException("Unexpected exception", e);
    }
}
 
Example #4
Source File: XMLReaderAdapterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * To test the parse method. The specification says that this method
 * will throw an exception if the embedded XMLReader does not support
 * the http://xml.org/sax/features/namespace-prefixes property.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void parse01() throws Exception {
    try (FileInputStream fis = new FileInputStream(XML_DIR + "namespace1.xml")) {
        XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
        if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) {
            xmlReader.setFeature(NM_PREFIXES_PROPERTY, true);
        }
        XMLReaderAdapter xmlRA = new XMLReaderAdapter(xmlReader);
        xmlRA.setDocumentHandler(new HandlerBase());
        xmlRA.parse(new InputSource(fis));
    }
}
 
Example #5
Source File: ParserAdapterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initiate ParserAdapter.
 * @throws Exception If any errors occur.
 */
ParserAdapterTest() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    XMLReaderAdapter xmlReaderAdapter = new XMLReaderAdapter(xmlReader);
    parserAdapter = new ParserAdapter(xmlReaderAdapter);
}
 
Example #6
Source File: MyDefaultHandler2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void skippedEntity(String name) {
    try {
        System.out.println("skippedEntity() is invoked for : " + name);
        new XMLReaderAdapter().skippedEntity(name);
    } catch (SAXException e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: MyDefaultHandler2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void endPrefixMapping(String prefix) {
    System.out.println("\nendPrefixMapping() is invoked for " + prefix);
    try {
        new XMLReaderAdapter().endPrefixMapping(prefix);
    } catch (SAXException e) {
        e.printStackTrace();
    }
}
 
Example #8
Source File: MyDefaultHandler2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void startPrefixMapping(String prefix, String uri) {
    System.out.println("startPrefixMapping() is invoked for " + prefix + " : " + uri);
    try {
        new XMLReaderAdapter().startPrefixMapping(prefix, uri);
    } catch (SAXException e) {
        e.printStackTrace();
    }
}
 
Example #9
Source File: Interpreter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void parse(){
    try{
        Parser p = new XMLReaderAdapter(XMLUtil.createXMLReader());
        p.setDocumentHandler(this);
        String externalForm = url.toExternalForm();
        InputSource is = new InputSource(externalForm);
        try {
            p.parse(is);
        } catch (NullPointerException npe) {
            npe.printStackTrace();
            if (npe.getCause() != null) {
                npe.getCause().printStackTrace();
            }
        }
    }
    catch(java.io.IOException ie){
        ie.printStackTrace();
    }
    catch(org.xml.sax.SAXException se){
        se.printStackTrace();
    }
}
 
Example #10
Source File: SAXParserFactoryAdaptor.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #11
Source File: SAXParserFactoryAdaptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #12
Source File: SAXParserFactoryAdaptor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #13
Source File: XMLReaderAdapterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * To test the constructor that uses XMLReader.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void constructor02() throws Exception {
    XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
    assertNotNull(new XMLReaderAdapter(xmlReader));
}
 
Example #14
Source File: SAXParserFactoryAdaptor.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #15
Source File: SAXParserFactoryAdaptor.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #16
Source File: SAXParserFactoryAdaptor.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #17
Source File: SAXParserFactoryAdaptor.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #18
Source File: SAXParserFactoryAdaptor.java    From jolie with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #19
Source File: SAXParserFactoryAdaptor.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated
 */
public org.xml.sax.Parser getParser() throws SAXException {
    return new XMLReaderAdapter(reader);
}
 
Example #20
Source File: XMLReaderAdapterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * To test the constructor that uses "org.xml.sax.driver" property
 * @throws org.xml.sax.SAXException If the embedded driver cannot be
 * instantiated or if the org.xml.sax.driver property is not specified.
 */
@Test
public void constructor01() throws SAXException {
    assertNotNull(new XMLReaderAdapter());
}