List of usage examples for org.xml.sax XMLReader setContentHandler
public void setContentHandler(ContentHandler handler);
From source file:org.nuxeo.ecm.core.convert.plugins.text.extractors.PPTX2TextConverter.java
protected void readXmlZipContent(ZipInputStream zis, XMLReader reader, StringBuilder sb) throws IOException, SAXException { Set<PresentationSlide> slides = new TreeSet<PresentationSlide>(); ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { String zipEntryName = zipEntry.getName(); if (zipEntryName.startsWith(PRESENTATION_SLIDE_ZIP_ENTRY_NAME_PREFIX) && zipEntryName.length() > PRESENTATION_SLIDE_ZIP_ENTRY_NAME_PREFIX.length()) { char slideNumberChar = zipEntryName.charAt(PRESENTATION_SLIDE_ZIP_ENTRY_NAME_PREFIX.length()); int slideNumber = -1; try { slideNumber = Integer.parseInt(String.valueOf(slideNumberChar)); } catch (NumberFormatException nfe) { log.warn("Slide number is not an non integer, won't take this slide into account."); }/* w ww. j a va 2s . co m*/ if (slideNumber > -1) { OpenXmlContentHandler contentHandler = new OpenXmlContentHandler(); reader.setContentHandler(contentHandler); reader.parse(new InputSource(new ByteArrayInputStream(IOUtils.toByteArray(zis)))); slides.add(new PresentationSlide(contentHandler.getContent(), slideNumber)); } } zipEntry = zis.getNextEntry(); } if (!slides.isEmpty()) { Iterator<PresentationSlide> slidesIt = slides.iterator(); while (slidesIt.hasNext()) { PresentationSlide slide = slidesIt.next(); sb.append(slide.getContent()); sb.append("\n"); } } }
From source file:org.nuxeo.ecm.platform.xmlrpc.connector.NuxeoXmlRpcServletServer.java
/** * Same as base class method, but with an additionnal parameter * that contains component name extracted from request. * * @param pConfig//from w w w . java 2s . c o m * @param pStream * @param handlerPrefix componentName extracted from request * @return * @throws XmlRpcException */ protected XmlRpcRequest getRequest(final XmlRpcStreamRequestConfig pConfig, InputStream pStream, final String handlerPrefix) throws XmlRpcException { final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory()); final XMLReader xr = SAXParsers.newXMLReader(); xr.setContentHandler(parser); try { xr.parse(new InputSource(pStream)); } catch (SAXException e) { Exception ex = e.getException(); if (ex != null && ex instanceof XmlRpcException) { throw (XmlRpcException) ex; } throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e); } final List params = parser.getParams(); return new XmlRpcRequest() { public XmlRpcRequestConfig getConfig() { return pConfig; } public String getMethodName() { String mName = parser.getMethodName(); if (handlerPrefix == null || "".equals(handlerPrefix)) { return mName; } else { return handlerPrefix + '.' + mName; } } public int getParameterCount() { return params == null ? 0 : params.size(); } public Object getParameter(int pIndex) { return params.get(pIndex); } }; }
From source file:org.olat.ims.qti.qpool.ItemFileResourceValidator.java
private boolean validateDocument(Document in) { try {/*w ww . j a va 2 s . c om*/ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(true); SimpleErrorHandler errorHandler = new SimpleErrorHandler(); ItemContentHandler contentHandler = new ItemContentHandler(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setEntityResolver(new IMSEntityResolver()); reader.setErrorHandler(errorHandler); reader.setContentHandler(contentHandler); SAXValidator validator = new SAXValidator(reader); validator.validate(in); return errorHandler.isValid() && contentHandler.isItem(); } catch (ParserConfigurationException e) { return false; } catch (SAXException e) { return false; } catch (Exception e) { return false; } }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
/** * @param xml/* w w w . jav a 2 s . c o m*/ * @return a list of alarms from the given xml string. * @throws IOException * @throws SAXException */ public static List<SonosAlarm> getAlarmsFromStringResult(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); AlarmHandler handler = new AlarmHandler(); reader.setContentHandler(handler); try { reader.parse(new InputSource(new StringReader(xml))); } catch (IOException e) { logger.error("Could not parse Alarms from String {}", xml); } return handler.getAlarms(); }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
/** * @param xml//from www.j av a 2 s . c om * @return a list of Entrys from the given xml string. * @throws IOException * @throws SAXException */ public static List<SonosEntry> getEntriesFromString(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); EntryHandler handler = new EntryHandler(); reader.setContentHandler(handler); try { reader.parse(new InputSource(new StringReader(xml))); } catch (IOException e) { logger.error("Could not parse Entries from String {}", xml); } return handler.getArtists(); }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
/** * Returns the meta data which is needed to play Pandora * (and others?) favorites//from ww w.jav a 2 s . co m * @param xml * @return The value of the desc xml tag * @throws SAXException */ public static SonosResourceMetaData getEmbededMetaDataFromResource(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); EmbededMetaDataHandler handler = new EmbededMetaDataHandler(); reader.setContentHandler(handler); try { reader.parse(new InputSource(new StringReader(xml))); } catch (IOException e) { logger.error("Could not parse Entries from String {}", xml); } return handler.getMetaData(); }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
/** * @param controller/* www.j a v a2s. c o m*/ * @param xml * @return zone group from the given xml * @throws IOException * @throws SAXException */ public static List<SonosZoneGroup> getZoneGroupFromXML(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); ZoneGroupHandler handler = new ZoneGroupHandler(); reader.setContentHandler(handler); try { 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); } return handler.getGroups(); }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
public static List<String> getRadioTimeFromXML(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); OpmlHandler handler = new OpmlHandler(); reader.setContentHandler(handler); try {//from w ww . j ava2 s . c o m 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); } return handler.getTextFields(); }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
public static Map<String, StateVariableValue> getRenderingControlFromXML(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); RenderingControlEventHandler handler = new RenderingControlEventHandler(); reader.setContentHandler(handler); try {/*from ww w . ja va 2 s .com*/ reader.parse(new InputSource(new StringReader(xml))); } catch (IOException e) { // This should never happen - we're not performing I/O! logger.debug("Could not parse Rendering Control event: {}", e); } return handler.getChanges(); }
From source file:org.openhab.binding.sonos.internal.SonosXMLParser.java
public static Map<String, StateVariableValue> getAVTransportFromXML(String xml) throws SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); AVTransportEventHandler handler = new AVTransportEventHandler(); reader.setContentHandler(handler); try {/* w ww .j ava2s .c om*/ 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 Event: {}", e); } return handler.getChanges(); }