Search in sources :

Example 1 with ParserException

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

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;
}
Also used : ParserException(org.cybergarage.xml.ParserException) InvalidDescriptionException(org.cybergarage.upnp.device.InvalidDescriptionException) Parser(org.cybergarage.xml.Parser)

Example 3 with ParserException

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;
}
Also used : ParserException(org.cybergarage.xml.ParserException) InvalidDescriptionException(org.cybergarage.upnp.device.InvalidDescriptionException) Parser(org.cybergarage.xml.Parser)

Example 4 with ParserException

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);
    }
}
Also used : ParserException(org.cybergarage.xml.ParserException) Node(org.cybergarage.xml.Node)

Example 5 with ParserException

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;
}
Also used : ParserException(org.cybergarage.xml.ParserException) Log(net.i2p.util.Log) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Node(org.cybergarage.xml.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) FileSuffixFilter(net.i2p.util.FileSuffixFilter) File(java.io.File)

Aggregations

ParserException (org.cybergarage.xml.ParserException)9 Parser (org.cybergarage.xml.Parser)6 Node (org.cybergarage.xml.Node)5 InvalidDescriptionException (org.cybergarage.upnp.device.InvalidDescriptionException)4 IOException (java.io.IOException)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FileSuffixFilter (net.i2p.util.FileSuffixFilter)1 Log (net.i2p.util.Log)1 ServiceData (org.cybergarage.upnp.xml.ServiceData)1