List of usage examples for org.xml.sax XMLReader setContentHandler
public void setContentHandler(ContentHandler handler);
From source file:org.eclipse.smarthome.binding.sonos.internal.SonosXMLParser.java
/** * @param xml/* www. j a v a 2 s .c om*/ * @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// w w w . ja 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// w ww . ja v a 2s. c o m * @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 . j a v 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 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 {/*w ww . ja v a 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 {//from w ww .j a v a 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 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 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 {/*w w w. j a v 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 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 {/*w w w. jav a2s . com*/ 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 ww . j av a2 s. c om*/ 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(); }