Search in sources :

Example 96 with SAXException

use of org.xml.sax.SAXException in project zm-mailbox by Zimbra.

the class W3cDomUtil method getDom4jSAXParserWhichUsesSecureProcessing.

public static SAXParser getDom4jSAXParserWhichUsesSecureProcessing() throws XmlParseException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setXIncludeAware(false);
    factory.setValidating(false);
    try {
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    } catch (SAXNotRecognizedException | SAXNotSupportedException | ParserConfigurationException ex) {
        ZimbraLog.misc.error("Problem setting up SAXParser which supports secure XML processing", ex);
        throw XmlParseException.PARSE_ERROR();
    }
    try {
        return factory.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        ZimbraLog.misc.error("Problem setting up SAXParser", e);
        throw XmlParseException.PARSE_ERROR();
    }
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 97 with SAXException

use of org.xml.sax.SAXException in project robo4j by Robo4J.

the class XmlConfigurationFactory method fromXml.

public static Configuration fromXml(String xml) throws ConfigurationFactoryException {
    DefaultConfiguration config = new DefaultConfiguration();
    SAXParser saxParser;
    try {
        saxParser = SAXParserFactory.newInstance().newSAXParser();
        saxParser.parse(new ByteArrayInputStream(xml.getBytes(Constants.DEFAULT_ENCODING)), new ConfigurationHandler(config));
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new ConfigurationFactoryException("Could not parse the configuration", e);
    }
    return config;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 98 with SAXException

use of org.xml.sax.SAXException in project android_frameworks_base by ResurrectionRemix.

the class SafeSaxTest method testMissingRequiredChild.

@SmallTest
public void testMissingRequiredChild() throws Exception {
    String xml = "<feed></feed>";
    RootElement root = new RootElement("feed");
    root.requireChild("entry");
    try {
        Xml.parse(xml, root.getContentHandler());
        fail("expected exception not thrown");
    } catch (SAXException e) {
    // Expected.
    }
}
Also used : RootElement(android.sax.RootElement) SAXException(org.xml.sax.SAXException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 99 with SAXException

use of org.xml.sax.SAXException in project android_frameworks_base by ResurrectionRemix.

the class WifiNetworkAdapter method loadAllSps.

private void loadAllSps() {
    Log.d(OSUManager.TAG, "Loading all SPs");
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    for (WifiConfiguration config : wifiManager.getPrivilegedConfiguredNetworks()) {
        String moTree = config.getMoTree();
        if (moTree != null) {
            try {
                mPasspointConfigs.put(config.FQDN, new PasspointConfig(config));
            } catch (IOException | SAXException e) {
                Log.w(OSUManager.TAG, "Failed to parse MO: " + e);
            }
        }
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 100 with SAXException

use of org.xml.sax.SAXException in project android_frameworks_base by ResurrectionRemix.

the class DefaultDataHandler method startElement.

public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
    if (ROW.equals(localName)) {
        if (mValues != null) {
            // case 2, <Col> before <Row> insert last uri
            if (mUris.empty()) {
                throw new SAXException("uri is empty");
            }
            Uri nextUri = insertRow();
            if (nextUri == null) {
                throw new SAXException("insert to uri " + mUris.lastElement().toString() + " failure");
            } else {
                // make sure the stack lastElement save uri for more than one row
                mUris.pop();
                mUris.push(nextUri);
                parseRow(atts);
            }
        } else {
            int attrLen = atts.getLength();
            if (attrLen == 0) {
                // case 3, share same uri as last level
                mUris.push(mUris.lastElement());
            } else {
                parseRow(atts);
            }
        }
    } else if (COL.equals(localName)) {
        int attrLen = atts.getLength();
        if (attrLen != 2) {
            throw new SAXException("illegal attributes number " + attrLen);
        }
        String key = atts.getValue(0);
        String value = atts.getValue(1);
        if (key != null && key.length() > 0 && value != null && value.length() > 0) {
            if (mValues == null) {
                mValues = new ContentValues();
            }
            mValues.put(key, value);
        } else {
            throw new SAXException("illegal attributes value");
        }
    } else if (DEL.equals(localName)) {
        Uri u = Uri.parse(atts.getValue(URI_STR));
        if (u == null) {
            throw new SAXException("attribute " + atts.getValue(URI_STR) + " parsing failure");
        }
        int attrLen = atts.getLength() - 2;
        if (attrLen > 0) {
            String[] selectionArgs = new String[attrLen];
            for (int i = 0; i < attrLen; i++) {
                selectionArgs[i] = atts.getValue(i + 2);
            }
            mContentResolver.delete(u, atts.getValue(1), selectionArgs);
        } else if (attrLen == 0) {
            mContentResolver.delete(u, atts.getValue(1), null);
        } else {
            mContentResolver.delete(u, null, null);
        }
    } else {
        throw new SAXException("unknown element: " + localName);
    }
}
Also used : Uri(android.net.Uri) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151