Search in sources :

Example 1 with FactoryConfigurationError

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

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)

Example 2 with FactoryConfigurationError

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

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 3 with FactoryConfigurationError

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

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 4 with FactoryConfigurationError

use of javax.xml.parsers.FactoryConfigurationError in project bazel by bazelbuild.

the class DensitySpecificManifestProcessor method getSecureDocumentBuilder.

private static DocumentBuilder getSecureDocumentBuilder() throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null);
    factory.setValidating(false);
    factory.setXIncludeAware(false);
    for (Map.Entry<String, Boolean> featureAndValue : SECURE_XML_FEATURES.entrySet()) {
        try {
            factory.setFeature(featureAndValue.getKey(), featureAndValue.getValue());
        } catch (ParserConfigurationException e) {
            throw new FactoryConfigurationError(e, "Xerces DocumentBuilderFactory doesn't support the required security features: " + e.getMessage());
        }
    }
    return factory.newDocumentBuilder();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Map(java.util.Map) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 5 with FactoryConfigurationError

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

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)

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