Search in sources :

Example 6 with FactoryConfigurationError

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

the class DocumentBuilderFactoryTest method test_newInstance.

/*    public void test_isSetXIncludeAware() {
        dbf.setXIncludeAware(true);
        assertTrue(dbf.isXIncludeAware());

        dbf.setXIncludeAware(false);
        assertFalse(dbf.isXIncludeAware());
    }
*/
/**
     * 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 7 with FactoryConfigurationError

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

the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_ExceptionLjava_lang_String.

public void test_ConstructorLjava_lang_ExceptionLjava_lang_String() {
    Exception e = new Exception();
    // case 1: Try to create FactoryConfigurationError
    // which is based on Exception without parameters.
    FactoryConfigurationError fce = new FactoryConfigurationError(e, "msg");
    assertNotNull(fce.getMessage());
    assertNotNull(fce.getLocalizedMessage());
    assertEquals(e.getCause(), fce.getCause());
    // case 2: Try to create FactoryConfigurationError
    // which is based on Exception with String parameter.
    e = new Exception("test message");
    fce = new FactoryConfigurationError(e, "msg");
    assertEquals("msg", fce.getMessage());
    assertEquals("msg", fce.getLocalizedMessage());
    assertEquals(e.getCause(), fce.getCause());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 8 with FactoryConfigurationError

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

the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_Exception.

public void test_ConstructorLjava_lang_Exception() {
    Exception e = new Exception();
    // case 1: Try to create FactoryConfigurationError
    // which is based on Exception without parameters.
    FactoryConfigurationError fce = new FactoryConfigurationError(e);
    assertNotNull(fce.getMessage());
    assertNotNull(fce.getLocalizedMessage());
    assertEquals(e.getCause(), fce.getCause());
    // case 2: Try to create FactoryConfigurationError
    // which is based on Exception with String parameter.
    e = new Exception("test message");
    fce = new FactoryConfigurationError(e);
    assertEquals(e.toString(), fce.getMessage());
    assertEquals(e.toString(), fce.getLocalizedMessage());
    assertEquals(e.getCause(), fce.getCause());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 9 with FactoryConfigurationError

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

the class FactoryConfigurationErrorTest method test_getException.

public void test_getException() {
    FactoryConfigurationError fce = new FactoryConfigurationError();
    assertNull(fce.getException());
    fce = new FactoryConfigurationError("test");
    assertNull(fce.getException());
    Exception e = new Exception("msg");
    fce = new FactoryConfigurationError(e);
    assertEquals(e, fce.getException());
    NullPointerException npe = new NullPointerException();
    fce = new FactoryConfigurationError(npe);
    assertEquals(npe, fce.getException());
}
Also used : FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 10 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project XobotOS by xamarin.

the class XMLParser method importPrefs.

/***************************************************************************
     * utilities for Preferences import
     **************************************************************************/
static void importPrefs(InputStream in) throws IOException, InvalidPreferencesFormatException {
    try {
        // load XML document
        Document doc = builder.parse(new InputSource(in));
        // check preferences' export version
        Element preferences;
        preferences = doc.getDocumentElement();
        String version = preferences.getAttribute("EXTERNAL_XML_VERSION");
        if (version != null && Float.parseFloat(version) > XML_VERSION) {
            throw new InvalidPreferencesFormatException("Preferences version " + version + " is not supported");
        }
        // check preferences root's type
        Element root = (Element) preferences.getElementsByTagName("root").item(0);
        Preferences prefsRoot = null;
        String type = root.getAttribute("type");
        if (type.equals("user")) {
            prefsRoot = Preferences.userRoot();
        } else {
            prefsRoot = Preferences.systemRoot();
        }
        // load node
        loadNode(prefsRoot, root);
    } catch (FactoryConfigurationError e) {
        throw new InvalidPreferencesFormatException(e);
    } catch (SAXException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) SAXException(org.xml.sax.SAXException)

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