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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations