List of usage examples for org.xml.sax XMLReader parse
public void parse(String systemId) throws IOException, SAXException;
From source file:com.entertailion.android.slideshow.rss.RssHandler.java
public RssFeed getFeed(String data) throws Exception { feed = null;//from w w w . j a v a 2s.c o m SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); InputSource inStream = new org.xml.sax.InputSource(); inStream.setCharacterStream(new StringReader(data)); xr.setContentHandler(this); feed = new RssFeed(); xr.parse(inStream); xr = null; sp = null; spf = null; return feed; }
From source file:com.gc.iotools.fmt.detect.droid.DroidDetectorImpl.java
private FFSignatureFile parseSigFile(final URL signatureFileURL) { final SAXModelBuilder mb = new SAXModelBuilder(); try {/*from w ww.j av a 2s . c o m*/ final XMLReader parser = getXMLReader(mb); final InputStream signatureFileStream = signatureFileURL.openStream(); parser.parse(new InputSource(signatureFileStream)); signatureFileStream.close(); } catch (final Exception e) { throw new IllegalStateException("Error reading configuration file " + "[" + signatureFileURL + "]", e); } final FFSignatureFile fsgf = (FFSignatureFile) mb.getModel(); fsgf.prepareForUse(); return fsgf; }
From source file:com.amytech.android.library.utils.asynchttp.SaxAsyncHttpResponseHandler.java
/** * Deconstructs response into given content handler * * @param entity// w ww .j a va2 s .co m * returned HttpEntity * @return deconstructed response * @throws java.io.IOException * if there is problem assembling SAX response from stream * @see org.apache.http.HttpEntity */ @Override protected byte[] getResponseData(HttpEntity entity) throws IOException { if (entity != null) { InputStream instream = entity.getContent(); InputStreamReader inputStreamReader = null; if (instream != null) { try { SAXParserFactory sfactory = SAXParserFactory.newInstance(); SAXParser sparser = sfactory.newSAXParser(); XMLReader rssReader = sparser.getXMLReader(); rssReader.setContentHandler(handler); inputStreamReader = new InputStreamReader(instream, DEFAULT_CHARSET); rssReader.parse(new InputSource(inputStreamReader)); } catch (SAXException e) { Log.e(LOG_TAG, "getResponseData exception", e); } catch (ParserConfigurationException e) { Log.e(LOG_TAG, "getResponseData exception", e); } finally { AsyncHttpClient.silentCloseInputStream(instream); if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (IOException e) { /* ignore */ } } } } } return null; }
From source file:org.energyos.espi.datacustodian.integration.utils.ATOMContentHandlerTests.java
@Test @Ignore//w ww . j a va 2s .c om public void processEnty() throws Exception { JAXBContext context = marshaller.getJaxbContext(); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); XMLReader reader = factory.newSAXParser().getXMLReader(); // EntryProcessorServiceImpl procssor = // mock(EntryProcessorServiceImpl.class); ATOMContentHandler atomContentHandler = new ATOMContentHandler(context, entryProcessorService); reader.setContentHandler(atomContentHandler); reader.parse(new InputSource(FixtureFactory.newUsagePointInputStream(UUID.randomUUID()))); // verify(procssor).process(any(EntryType.class)); }
From source file:com.entertailion.android.overlaynews.rss.RssHandler.java
public RssFeed getFeed(String data) { feed = null;/*from ww w . j a v a2 s .c om*/ try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); InputSource inStream = new org.xml.sax.InputSource(); inStream.setCharacterStream(new StringReader(data)); xr.setContentHandler(this); feed = new RssFeed(); xr.parse(inStream); xr = null; sp = null; spf = null; } catch (Exception e) { Log.e(LOG_CAT, "getFeed", e); } return feed; }
From source file:com.bdaum.juploadr.uploadapi.locrrest.LocrMethod.java
/** * @param responseBodyAsString// www . ja v a2 s . co m * @return * @throws AuthException */ public boolean parseResponse(String response) throws ProtocolException { try { XMLReader reader = XMLReaderFactory.createXMLReader(); handler = getResponseHandler(); reader.setContentHandler(handler); reader.parse(new InputSource(new StringReader(response))); if (!handler.isSuccessful()) { throw defaultExceptionFor(handler.getErrorCode()); } return handler.isSuccessful(); } catch (SAXException e) { throw new AuthException(Messages.getString("juploadr.ui.error.response.unreadable.noreason"), //$NON-NLS-1$ e); } catch (IOException e) { // this can't happen } return false; }
From source file:edu.ucsd.xmlrpc.xmlrpc.server.XmlRpcStreamServer.java
protected XmlRpcRequest getRequest(final XmlRpcStreamRequestConfig pConfig, InputStream pStream) throws XmlRpcException { final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory()); final XMLReader xr = SAXParsers.newXMLReader(); xr.setContentHandler(parser);//from w ww. j a va 2s . c o m 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(); // Ucsd modified code return new XmlRpcClientRequestImpl(pConfig, parser.getMethodName(), parser.getParams(), parser.getJobID()); // end }
From source file:com.test.demo.ccbpay.XLSX2CSV.java
/** * Parses and shows the content of one sheet * using the specified styles and shared-strings tables. * * @param styles/*ww w. j a v a 2 s . c om*/ * @param strings * @param sheetInputStream */ public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler, InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException { DataFormatter formatter = new DataFormatter(); InputSource sheetSource = new InputSource(sheetInputStream); try { XMLReader sheetParser = SAXHelper.newXMLReader(); ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false); sheetParser.setContentHandler(handler); sheetParser.parse(sheetSource); } catch (ParserConfigurationException e) { throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage()); } }
From source file:io.milton.http.webdav.DefaultPropFindRequestFieldParser.java
@Override public PropertiesRequest getRequestedFields(InputStream in) { final Set<QName> set = new LinkedHashSet<QName>(); try {/*from w w w. j a va 2 s . co m*/ ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.readTo(in, bout, false, true); byte[] arr = bout.toByteArray(); if (arr.length > 1) { ByteArrayInputStream bin = new ByteArrayInputStream(arr); XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); PropFindSaxHandler handler = new PropFindSaxHandler(); reader.setContentHandler(handler); try { reader.parse(new InputSource(bin)); if (handler.isAllProp()) { return new PropertiesRequest(); } else { set.addAll(handler.getAttributes().keySet()); } } catch (IOException e) { log.warn("exception parsing request body", e); // ignore } catch (SAXException e) { log.warn("exception parsing request body", e); // ignore } } } catch (Exception ex) { // There's a report of an exception being thrown here by IT Hit Webdav client // Perhaps we can just log the error and return an empty set. Usually this // class is wrapped by the MsPropFindRequestFieldParser which will use a default // set of properties if this returns an empty set log.warn("Exception parsing PROPFIND request fields. Returning empty property set", ex); //throw new RuntimeException( ex ); } return PropertiesRequest.toProperties(set); }
From source file:net.ontopia.persistence.proxy.QueryDeclarations.java
protected void loadQueries(InputSource isource) { // Read queries file. ContentHandler handler = new QueriesHandler(); try {/* w w w . ja va 2 s . c o m*/ XMLReader parser = DefaultXMLReaderFactory.createXMLReader(); parser.setContentHandler(handler); parser.setErrorHandler(new Slf4jSaxErrorHandler(log)); parser.parse(isource); } catch (Exception e) { throw new OntopiaRuntimeException(e); } }