Search in sources :

Example 16 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project j2objc by google.

the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_String.

public void test_ConstructorLjava_lang_String() {
    FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
    assertEquals("Oops!", fce.getMessage());
    assertEquals("Oops!", fce.getLocalizedMessage());
    assertNull(fce.getCause());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 17 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.

the class XMLReaderManager method getXMLReader.

/**
     * Retrieves a cached XMLReader for this thread, or creates a new
     * XMLReader, if the existing reader is in use.  When the caller no
     * longer needs the reader, it must release it with a call to
     * {@link #releaseXMLReader}.
     */
public synchronized XMLReader getXMLReader() throws SAXException {
    XMLReader reader;
    boolean readerInUse;
    if (m_readers == null) {
        // When the m_readers.get() method is called for the first time
        // on a thread, a new XMLReader will automatically be created.
        m_readers = new ThreadLocal();
    }
    if (m_inUse == null) {
        m_inUse = new Hashtable();
    }
    // If the cached reader for this thread is in use, construct a new
    // one; otherwise, return the cached reader.
    reader = (XMLReader) m_readers.get();
    boolean threadHasReader = (reader != null);
    if (!threadHasReader || m_inUse.get(reader) == Boolean.TRUE) {
        try {
            try {
                // According to JAXP 1.2 specification, if a SAXSource
                // is created using a SAX InputSource the Transformer or
                // TransformerFactory creates a reader via the
                // XMLReaderFactory if setXMLReader is not used
                reader = XMLReaderFactory.createXMLReader();
            } catch (Exception e) {
                try {
                    // the XMLReader from JAXP
                    if (m_parserFactory == null) {
                        m_parserFactory = SAXParserFactory.newInstance();
                        m_parserFactory.setNamespaceAware(true);
                    }
                    reader = m_parserFactory.newSAXParser().getXMLReader();
                } catch (ParserConfigurationException pce) {
                    // pass along pce
                    throw pce;
                }
            }
            try {
                reader.setFeature(NAMESPACES_FEATURE, true);
                reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
            } catch (SAXException se) {
            // Try to carry on if we've got a parser that
            // doesn't know about namespace prefixes.
            }
        } catch (ParserConfigurationException ex) {
            throw new SAXException(ex);
        } catch (FactoryConfigurationError ex1) {
            throw new SAXException(ex1.toString());
        } catch (NoSuchMethodError ex2) {
        } catch (AbstractMethodError ame) {
        }
        // a reader for this thread.
        if (!threadHasReader) {
            m_readers.set(reader);
            m_inUse.put(reader, Boolean.TRUE);
        }
    } else {
        m_inUse.put(reader, Boolean.TRUE);
    }
    return reader;
}
Also used : Hashtable(java.util.Hashtable) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) XMLReader(org.xml.sax.XMLReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Example 18 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.

the class SAXParserFactoryTest method test_newInstance.

@KnownFailure("Dalvik doesn't honor system properties when choosing a SAX implementation")
public void test_newInstance() {
    try {
        SAXParserFactory dtf = SAXParserFactory.newInstance();
        assertNotNull("New Instance of DatatypeFactory is null", dtf);
        System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.harmony.xml.parsers.SAXParserFactoryImpl");
        SAXParserFactory spf1 = SAXParserFactory.newInstance();
        assertTrue(spf1 instanceof org.apache.harmony.xml.parsers.SAXParserFactoryImpl);
        String key = "javax.xml.parsers.SAXParserFactory = org.apache.harmony.xml.parsers.SAXParserFactoryImpl";
        ByteArrayInputStream bis = new ByteArrayInputStream(key.getBytes());
        Properties prop = System.getProperties();
        prop.load(bis);
        SAXParserFactory spf2 = SAXParserFactory.newInstance();
        assertTrue(spf2 instanceof org.apache.harmony.xml.parsers.SAXParserFactoryImpl);
        System.setProperty("javax.xml.parsers.SAXParserFactory", "");
        try {
            SAXParserFactory.newInstance();
            fail("Expected FactoryConfigurationError was not thrown");
        } catch (FactoryConfigurationError e) {
        // expected
        }
    } catch (IOException ioe) {
        fail("Unexpected exception " + ioe.toString());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) SAXParserFactory(javax.xml.parsers.SAXParserFactory) KnownFailure(dalvik.annotation.KnownFailure)

Example 19 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.

the class DocumentBuilderFactoryTest method test_newInstance.

/**
     * javax.xml.parsers.DocumentBuilderFactory#newInstance().
     */
public void test_newInstance() {
    String className = null;
    try {
        // case 1: Try to obtain a new instance of factory by default.
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        assertNotNull(dbf);
        // case 2: Try to create a new instance of factory using
        // property DATATYPEFACTORY_PROPERTY
        className = System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl");
        dbf = DocumentBuilderFactory.newInstance();
        assertNotNull(dbf);
        assertTrue(dbf instanceof org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl);
        // case 3: Try to create a new instance of factory using Property
        String keyValuePair = "javax.xml.parsers.DocumentBuilderFactory" + "=" + "org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl";
        ByteArrayInputStream bis = new ByteArrayInputStream(keyValuePair.getBytes());
        Properties prop = System.getProperties();
        prop.load(bis);
        dbf = DocumentBuilderFactory.newInstance();
        assertNotNull(dbf);
        assertTrue(dbf instanceof org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl);
        // case 4: Check FactoryConfiguration error
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "");
        try {
            DocumentBuilderFactory.newInstance();
        } catch (FactoryConfigurationError fce) {
        // expected
        }
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    } finally {
        // because of this test modifies it.
        if (className == null) {
            System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
        } else {
            System.setProperty("javax.xml.parsers.DocumentBuilderFactory", className);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Properties(java.util.Properties) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 20 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.

the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_String.

public void test_ConstructorLjava_lang_String() {
    FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
    assertEquals("Oops!", fce.getMessage());
    assertEquals("Oops!", fce.getLocalizedMessage());
    assertNull(fce.getCause());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Aggregations

FactoryConfigurationError (javax.xml.parsers.FactoryConfigurationError)23 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 SAXException (org.xml.sax.SAXException)8 IOException (java.io.IOException)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Properties (java.util.Properties)3 Document (org.w3c.dom.Document)3 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Hashtable (java.util.Hashtable)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)2 Element (org.w3c.dom.Element)2 InputSource (org.xml.sax.InputSource)2 SAXParseException (org.xml.sax.SAXParseException)2 XMLReader (org.xml.sax.XMLReader)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1