Search in sources :

Example 1 with Parser

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

the class ControlPoint method addDevice.

private synchronized void addDevice(SSDPPacket ssdpPacket) {
    if (ssdpPacket.isRootDevice() == false)
        return;
    String usn = ssdpPacket.getUSN();
    String udn = USN.getUDN(usn);
    Device dev = getDevice(udn);
    if (dev != null) {
        dev.setSSDPPacket(ssdpPacket);
        return;
    }
    String location = ssdpPacket.getLocation();
    try {
        URL locationUrl = new URL(location);
        Parser parser = UPnP.getXMLParser();
        Node rootNode = parser.parse(locationUrl);
        Device rootDev = getDevice(rootNode);
        if (rootDev == null)
            return;
        rootDev.setSSDPPacket(ssdpPacket);
        Debug.warning("Add root device", new Exception("received on " + ssdpPacket.getLocalAddress()));
        addDevice(rootNode);
        // Thanks for Oliver Newell (2004/10/16)
        // After node is added, invoke the AddDeviceListener to notify high-level
        // control point application that a new device has been added. (The
        // control point application must implement the DeviceChangeListener interface
        // to receive the notifications)
        performAddDeviceListener(rootDev);
    } catch (MalformedURLException me) {
        Debug.warning(ssdpPacket.toString());
        Debug.warning(me);
    } catch (ParserException pe) {
        Debug.warning(ssdpPacket.toString());
        Debug.warning(pe);
    }
}
Also used : ParserException(org.cybergarage.xml.ParserException) MalformedURLException(java.net.MalformedURLException) Node(org.cybergarage.xml.Node) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) ParserException(org.cybergarage.xml.ParserException) Parser(org.cybergarage.xml.Parser)

Example 2 with Parser

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

the class Device method loadDescription.

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

Example 3 with Parser

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

the class Device method loadDescription.

/**
 * @since 1.8.0
 */
public boolean loadDescription(InputStream input) throws InvalidDescriptionException {
    try {
        Parser parser = UPnP.getXMLParser();
        rootNode = parser.parse(input);
        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 4 with Parser

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

the class Service method loadSCPD.

/**
 * @since 1.8.0
 */
public boolean loadSCPD(InputStream input) throws ParserException {
    Parser parser = UPnP.getXMLParser();
    Node scpdNode = parser.parse(input);
    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 5 with Parser

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

the class SOAPRequest method postMessage.

// //////////////////////////////////////////////
// post
// //////////////////////////////////////////////
public SOAPResponse postMessage(String host, int port) {
    HTTPResponse httpRes = post(host, port);
    SOAPResponse soapRes = new SOAPResponse(httpRes);
    byte[] content = soapRes.getContent();
    if (content.length <= 0)
        return soapRes;
    try {
        ByteArrayInputStream byteIn = new ByteArrayInputStream(content);
        Parser xmlParser = SOAP.getXMLParser();
        Node rootNode = xmlParser.parse(byteIn);
        soapRes.setEnvelopeNode(rootNode);
    } catch (Exception e) {
        Debug.warning(e);
    }
    return soapRes;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HTTPResponse(org.cybergarage.http.HTTPResponse) Node(org.cybergarage.xml.Node) ParserException(org.cybergarage.xml.ParserException) 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