Example usage for org.xml.sax XMLReader parse

List of usage examples for org.xml.sax XMLReader parse

Introduction

In this page you can find the example usage for org.xml.sax XMLReader parse.

Prototype

public void parse(String systemId) throws IOException, SAXException;

Source Link

Document

Parse an XML document from a system identifier (URI).

Usage

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

/**
 * @param xml//w  w w .j a va2 s.  co  m
 * @return a list of Entries from the given xml string.
 * @throws IOException
 * @throws SAXException
 */
public static List<SonosEntry> getEntriesFromString(String xml) {
    EntryHandler handler = new EntryHandler();
    try {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        LOGGER.error("Could not parse Entries from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse Entries from string '{}'", xml);
    }

    return handler.getArtists();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

/**
 * Returns the meta data which is needed to play Pandora
 * (and others?) favorites/*from w  w  w  .j  av  a  2  s .  c om*/
 *
 * @param xml
 * @return The value of the desc xml tag
 * @throws SAXException
 */
public static SonosResourceMetaData getResourceMetaData(String xml) throws SAXException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    ResourceMetaDataHandler handler = new ResourceMetaDataHandler();
    reader.setContentHandler(handler);
    try {
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        LOGGER.error("Could not parse Resource MetaData from String '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse Resource MetaData from string '{}'", xml);
    }
    return handler.getMetaData();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

/**
 * @param controller/*w  w  w.  j  a va  2  s.c om*/
 * @param xml
 * @return zone group from the given xml
 * @throws IOException
 * @throws SAXException
 */
public static List<SonosZoneGroup> getZoneGroupFromXML(String xml) {
    ZoneGroupHandler handler = new ZoneGroupHandler();
    try {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOGGER.error("Could not parse ZoneGroup from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse ZoneGroup from string '{}'", xml);
    }

    return handler.getGroups();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static List<String> getRadioTimeFromXML(String xml) {
    OpmlHandler handler = new OpmlHandler();
    try {//from w ww  . ja  va2  s . c  om
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOGGER.error("Could not parse RadioTime from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse RadioTime from string '{}'", xml);
    }

    return handler.getTextFields();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static Map<String, String> getRenderingControlFromXML(String xml) {
    RenderingControlEventHandler handler = new RenderingControlEventHandler();
    try {//  ww w . j  ava 2  s.  co m
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOGGER.error("Could not parse Rendering Control from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse Rendering Control from string '{}'", xml);
    }
    return handler.getChanges();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static Map<String, String> getAVTransportFromXML(String xml) {
    AVTransportEventHandler handler = new AVTransportEventHandler();
    try {//www. jav a 2  s .c om
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOGGER.error("Could not parse AV Transport from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse AV Transport from string '{}'", xml);
    }
    return handler.getChanges();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static SonosMetaData getMetaDataFromXML(String xml) {
    MetaDataHandler handler = new MetaDataHandler();
    try {//  ww  w . ja v  a 2 s  . com
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOGGER.error("Could not parse MetaData from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse MetaData from string '{}'", xml);
    }

    return handler.getMetaData();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static List<SonosMusicService> getMusicServicesFromXML(String xml) {
    MusicServiceHandler handler = new MusicServiceHandler();
    try {//from  w  w  w.  j  ava 2s  . c om
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOGGER.error("Could not parse music services from string '{}'", xml);
    } catch (SAXException s) {
        LOGGER.error("Could not parse music services from string '{}'", xml);
    }
    return handler.getServices();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static String getRoomName(String descriptorXML) {
    RoomNameHandler roomNameHandler = new RoomNameHandler();
    try {/*from w  w  w . j a  v a  2  s  .  co m*/
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(roomNameHandler);
        URL url = new URL(descriptorXML);
        reader.parse(new InputSource(url.openStream()));
    } catch (IOException | SAXException e) {
        LOGGER.error("Could not parse Sonos room name from string '{}'", descriptorXML);
    }
    return roomNameHandler.getRoomName();
}

From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java

public static String parseModelDescription(URL descriptorURL) {
    ModelNameHandler modelNameHandler = new ModelNameHandler();
    try {/*from ww  w . j  a va 2 s  .  c  o m*/
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(modelNameHandler);
        URL url = new URL(descriptorURL.toString());
        reader.parse(new InputSource(url.openStream()));
    } catch (IOException | SAXException e) {
        LOGGER.error("Could not parse Sonos model name from string '{}'", descriptorURL.toString());
    }
    return modelNameHandler.getModelName();
}