Search in sources :

Example 6 with ParserException

use of org.cybergarage.xml.ParserException in project i2p.i2p by i2p.

the class Device method loadDescription.

public boolean loadDescription(String descString) throws InvalidDescriptionException {
    try {
        Parser parser = UPnP.getXMLParser();
        rootNode = parser.parse(descString);
        if (rootNode == null)
            throw new InvalidDescriptionException(Description.NOROOT_EXCEPTION);
        deviceNode = rootNode.getNode(Device.ELEM_NAME);
        if (deviceNode == null)
            throw new InvalidDescriptionException(Description.NOROOTDEVICE_EXCEPTION);
    } catch (ParserException e) {
        throw new InvalidDescriptionException(e);
    }
    if (initializeLoadedDescription() == false)
        return false;
    setDescriptionFile(null);
    return true;
}
Also used : ParserException(org.cybergarage.xml.ParserException) InvalidDescriptionException(org.cybergarage.upnp.device.InvalidDescriptionException) Parser(org.cybergarage.xml.Parser)

Example 7 with ParserException

use of org.cybergarage.xml.ParserException in project i2p.i2p by i2p.

the class Service method loadSCPD.

// //////////////////////////////////////////////
// SCPD node
// //////////////////////////////////////////////
public boolean loadSCPD(String scpdStr) throws InvalidDescriptionException {
    try {
        Parser parser = UPnP.getXMLParser();
        Node scpdNode = parser.parse(scpdStr);
        if (scpdNode == null)
            return false;
        ServiceData data = getServiceData();
        data.setSCPDNode(scpdNode);
    } catch (ParserException e) {
        throw new InvalidDescriptionException(e);
    }
    return true;
}
Also used : ParserException(org.cybergarage.xml.ParserException) Node(org.cybergarage.xml.Node) InvalidDescriptionException(org.cybergarage.upnp.device.InvalidDescriptionException) ServiceData(org.cybergarage.upnp.xml.ServiceData) Parser(org.cybergarage.xml.Parser)

Example 8 with ParserException

use of org.cybergarage.xml.ParserException in project i2p.i2p by i2p.

the class SOAPRequest method getRootNode.

private synchronized Node getRootNode() {
    if (rootNode != null)
        return rootNode;
    try {
        byte[] content = getContent();
        ByteArrayInputStream contentIn = new ByteArrayInputStream(content);
        Parser parser = SOAP.getXMLParser();
        rootNode = parser.parse(contentIn);
    } catch (ParserException e) {
        Debug.warning(e);
    }
    return rootNode;
}
Also used : ParserException(org.cybergarage.xml.ParserException) ByteArrayInputStream(java.io.ByteArrayInputStream) Parser(org.cybergarage.xml.Parser)

Example 9 with ParserException

use of org.cybergarage.xml.ParserException in project i2p.i2p by i2p.

the class JaxpParser method parse.

/* (non-Javadoc)
	 * @see org.cybergarage.xml.Parser#parse(java.io.InputStream)
	 */
public Node parse(InputStream inStream) throws ParserException {
    org.cybergarage.xml.Node root = null;
    try {
        // https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        factory.setNamespaceAware(true);
        factory.setExpandEntityReferences(false);
        try {
            try {
                factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
            } catch (ParserConfigurationException pce) {
            }
            try {
                factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            } catch (ParserConfigurationException pce) {
            }
            try {
                factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (ParserConfigurationException pce) {
            }
            try {
                factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            } catch (ParserConfigurationException pce) {
            }
        }// FreeBSD
         catch (AbstractMethodError ame) {
        }
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(new BlankingResolver());
        InputSource inSrc = new InputSource(new NullFilterInputStream(inStream));
        Document doc = builder.parse(inSrc);
        org.w3c.dom.Element docElem = doc.getDocumentElement();
        if (docElem != null)
            root = parse(root, docElem);
    /*
			NodeList rootList = doc.getElementsByTagName("root");
			Debug.message("rootList = " + rootList.getLength());
			
			if (0 < rootList.getLength())
				root = parse(root, rootList.item(0));
*/
    } catch (Exception e) {
        throw new ParserException(e);
    }
    return root;
}
Also used : ParserException(org.cybergarage.xml.ParserException) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) ParserException(org.cybergarage.xml.ParserException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Node(org.cybergarage.xml.Node)

Aggregations

ParserException (org.cybergarage.xml.ParserException)9 Parser (org.cybergarage.xml.Parser)6 Node (org.cybergarage.xml.Node)5 InvalidDescriptionException (org.cybergarage.upnp.device.InvalidDescriptionException)4 IOException (java.io.IOException)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FileSuffixFilter (net.i2p.util.FileSuffixFilter)1 Log (net.i2p.util.Log)1 ServiceData (org.cybergarage.upnp.xml.ServiceData)1