Search in sources :

Example 6 with Node

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

the class PersistNews method extract.

/**
 *  This does not check for any missing values.
 *  Any fields in any NewsEntry may be null.
 *  Content is not sanitized by NewsXMLParser here, do that before storing.
 *
 *  @return non-null, throws on errors
 */
private static NewsEntry extract(Node entry) {
    NewsEntry e = new NewsEntry();
    Node n = entry.getNode("title");
    if (n != null) {
        e.title = n.getValue();
        if (e.title != null)
            e.title = e.title.trim();
    }
    n = entry.getNode("link");
    if (n != null) {
        String a = n.getAttributeValue("href");
        if (a.length() > 0)
            e.link = a.trim();
    }
    n = entry.getNode("id");
    if (n != null) {
        e.id = n.getValue();
        if (e.id != null)
            e.id = e.id.trim();
    }
    n = entry.getNode("updated");
    if (n != null) {
        String v = n.getValue();
        if (v != null) {
            long time = RFC3339Date.parse3339Date(v.trim());
            if (time > 0)
                e.updated = time;
        }
    }
    n = entry.getNode("summary");
    if (n != null) {
        e.summary = n.getValue();
        if (e.summary != null)
            e.summary = e.summary.trim();
    }
    n = entry.getNode("author");
    if (n != null) {
        n = n.getNode("name");
        if (n != null) {
            e.authorName = n.getValue();
            if (e.authorName != null)
                e.authorName = e.authorName.trim();
        }
    }
    n = entry.getNode("content");
    if (n != null) {
        String a = n.getAttributeValue("type");
        if (a.length() > 0)
            e.contentType = a;
        // now recursively sanitize
        // and convert everything in the content to string
        StringBuilder buf = new StringBuilder(256);
        for (int i = 0; i < n.getNNodes(); i++) {
            Node sn = n.getNode(i);
            XMLParser.toString(buf, sn);
        }
        e.content = buf.toString();
    }
    return e;
}
Also used : Node(org.cybergarage.xml.Node)

Example 7 with Node

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

the class Argument method getArgumentData.

// //////////////////////////////////////////////
// UserData
// //////////////////////////////////////////////
private ArgumentData getArgumentData() {
    Node node = getArgumentNode();
    ArgumentData userData = (ArgumentData) node.getUserData();
    if (userData == null) {
        userData = new ArgumentData();
        node.setUserData(userData);
        userData.setNode(node);
    }
    return userData;
}
Also used : ArgumentData(org.cybergarage.upnp.xml.ArgumentData) Node(org.cybergarage.xml.Node)

Example 8 with Node

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

the class Argument method getActionNode.

public Node getActionNode() {
    Node argumentLinstNode = getArgumentNode().getParentNode();
    if (argumentLinstNode == null)
        return null;
    Node actionNode = argumentLinstNode.getParentNode();
    if (actionNode == null)
        return null;
    if (Action.isActionNode(actionNode) == false)
        return null;
    return actionNode;
}
Also used : Node(org.cybergarage.xml.Node)

Example 9 with Node

use of org.cybergarage.xml.Node 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 10 with Node

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

the class ControlPoint method getDeviceList.

public DeviceList getDeviceList() {
    DeviceList devList = new DeviceList();
    int nRoots = devNodeList.size();
    for (int n = 0; n < nRoots; n++) {
        // AIOOB was thrown from here, maybe would be better to
        // copy the list before traversal?
        Node rootNode;
        try {
            rootNode = devNodeList.getNode(n);
        } catch (ArrayIndexOutOfBoundsException aioob) {
            break;
        }
        Device dev = getDevice(rootNode);
        if (dev == null)
            continue;
        devList.add(dev);
    }
    return devList;
}
Also used : Node(org.cybergarage.xml.Node)

Aggregations

Node (org.cybergarage.xml.Node)58 ParserException (org.cybergarage.xml.ParserException)7 ArrayList (java.util.ArrayList)5 ServiceData (org.cybergarage.upnp.xml.ServiceData)5 Parser (org.cybergarage.xml.Parser)5 IOException (java.io.IOException)4 File (java.io.File)3 Device (org.cybergarage.upnp.Device)3 DeviceData (org.cybergarage.upnp.xml.DeviceData)3 UPnPDevice (org.osgi.service.upnp.UPnPDevice)3 URL (java.net.URL)2 Log (net.i2p.util.Log)2 InvalidDescriptionException (org.cybergarage.upnp.device.InvalidDescriptionException)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1