Example usage for org.xml.sax.helpers XMLReaderFactory createXMLReader

List of usage examples for org.xml.sax.helpers XMLReaderFactory createXMLReader

Introduction

In this page you can find the example usage for org.xml.sax.helpers XMLReaderFactory createXMLReader.

Prototype

public static XMLReader createXMLReader() throws SAXException 

Source Link

Document

Obtains a new instance of a org.xml.sax.XMLReader .

Usage

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

/**
 * @param xml//from   ww w  .java2s  . c o  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 a v  a  2 s .  co  m
 *
 * @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/*from  w  w  w. jav a 2 s. com*/
 * @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  www. j ava2s  .  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 {/*from   w  w w .ja  v  a 2s . 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 {//from   w  w w. jav  a  2  s  . c o 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 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 {//from  www  .j  av a  2s  .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 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   www  . j  ava 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 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  a2 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  w w w.j a  v  a 2s  . 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();
}