Search in sources :

Example 6 with Parser

use of org.cybergarage.xml.Parser 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 Parser

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

the class Service method loadSCPD.

public boolean loadSCPD(File file) throws ParserException {
    Parser parser = UPnP.getXMLParser();
    Node scpdNode = parser.parse(file);
    if (scpdNode == null)
        return false;
    ServiceData data = getServiceData();
    data.setSCPDNode(scpdNode);
    return true;
}
Also used : Node(org.cybergarage.xml.Node) ServiceData(org.cybergarage.upnp.xml.ServiceData) Parser(org.cybergarage.xml.Parser)

Example 8 with Parser

use of org.cybergarage.xml.Parser 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 9 with Parser

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

the class UPnP method loadDefaultXMLParser.

/**
 * This method loads the default XML Parser using the following behavior:
 *  - First if present loads the parsers specified by the system property {@link UPnP#XML_CLASS_PROPERTTY}<br>
 *  - Second by a fall-back technique, it tries to load the XMLParser from one<br>
 *  of the following classes: {@link JaxpParser}, {@link kXML2Parser}, {@link XercesParser}
 *
 * @return {@link Parser} which has been loaded successuflly or null otherwise
 *
 * @since 1.8.0
 */
private static Parser loadDefaultXMLParser() {
    Parser parser = null;
    String[] parserClass = new String[] { System.getProperty(XML_CLASS_PROPERTTY), // "org.cybergarage.xml.parser.XmlPullParser",
    "org.cybergarage.xml.parser.JaxpParser" // "org.cybergarage.xml.parser.kXML2Parser",
    // "org.cybergarage.xml.parser.XercesParser"
    };
    for (int i = 0; i < parserClass.length; i++) {
        if (parserClass[i] == null)
            continue;
        try {
            parser = (Parser) Class.forName(parserClass[i]).getDeclaredConstructor().newInstance();
            return parser;
        } catch (Throwable e) {
            Debug.warning("Unable to load " + parserClass[i] + " as XMLParser due to " + e);
        }
    }
    return null;
}
Also used : Parser(org.cybergarage.xml.Parser)

Example 10 with Parser

use of org.cybergarage.xml.Parser 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)

Aggregations

Parser (org.cybergarage.xml.Parser)10 ParserException (org.cybergarage.xml.ParserException)7 Node (org.cybergarage.xml.Node)5 InvalidDescriptionException (org.cybergarage.upnp.device.InvalidDescriptionException)4 ServiceData (org.cybergarage.upnp.xml.ServiceData)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HTTPResponse (org.cybergarage.http.HTTPResponse)1