use of org.cybergarage.xml.ParserException 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.ParserException 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;
}
use of org.cybergarage.xml.ParserException 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;
}
use of org.cybergarage.xml.ParserException in project i2p.i2p by i2p.
the class NewsXMLParser method parse.
/**
* Process the XML input stream.
*
* @param in XML content only. Any su3 or gunzip handling must have
* already happened.
* @return the root node
* @throws IOException on any parse error
*/
public Node parse(InputStream in) throws IOException {
_entries = null;
_metadata = null;
XMLParser parser = new XMLParser(_context);
try {
Node root = parser.parse(in);
extract(root);
return root;
} catch (ParserException pe) {
throw new I2PParserException(pe);
}
}
use of org.cybergarage.xml.ParserException in project i2p.i2p by i2p.
the class PersistNews method load.
/**
* 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, sorted by updated date, newest first
*/
public static List<NewsEntry> load(I2PAppContext ctx) {
Log log = ctx.logManager().getLog(PersistNews.class);
File dir = new File(ctx.getConfigDir(), DIR);
List<NewsEntry> rv = new ArrayList<NewsEntry>();
File[] files = dir.listFiles(new FileSuffixFilter(PFX, SFX));
if (files == null)
return rv;
for (File file : files) {
String name = file.getName();
XMLParser parser = new XMLParser(ctx);
InputStream in = null;
Node node;
boolean error = false;
try {
in = new GZIPInputStream(new FileInputStream(file));
node = parser.parse(in);
NewsEntry entry = extract(node);
if (entry != null) {
rv.add(entry);
} else {
if (log.shouldWarn())
log.warn("load error from " + file);
error = true;
}
} catch (ParserException pe) {
if (log.shouldWarn())
log.warn("load error from " + file, pe);
error = true;
} catch (IOException ioe) {
if (log.shouldWarn())
log.warn("load error from " + file, ioe);
error = true;
} finally {
if (in != null)
try {
in.close();
} catch (IOException ioe) {
}
}
if (error)
file.delete();
}
Collections.sort(rv);
return rv;
}
Aggregations