use of javax.xml.parsers.SAXParserFactory in project SmartAndroidSource by jaychou2012.
the class SaxAsyncHttpResponseHandler method getResponseData.
/**
* Deconstructs response into given content handler
*
* @param entity returned HttpEntity
* @return deconstructed response
* @throws java.io.IOException
* @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;
}
use of javax.xml.parsers.SAXParserFactory in project jersey by jersey.
the class AbstractJaxbProviderTest method abstractJaxbProviderDoesNotReadExternalDtds.
@Test
public void abstractJaxbProviderDoesNotReadExternalDtds() throws Exception {
SAXParserFactory spf = injectionManager.getInstance(SAXParserFactory.class);
String url = "file:///no-such-file";
String s = "<!DOCTYPE x SYSTEM '" + url + "'><x/>";
SAXSource saxSource = AbstractJaxbProvider.getSAXSource(spf, new ByteArrayInputStream(s.getBytes("us-ascii")));
TransformerFactory.newInstance().newTransformer().transform(saxSource, new StreamResult(new ByteArrayOutputStream()));
}
use of javax.xml.parsers.SAXParserFactory in project jersey by jersey.
the class SaxParserFactoryInjectionProvider method get.
@Override
public SAXParserFactory get() {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
if (!isXmlSecurityDisabled()) {
factory = new SecureSaxParserFactory(factory);
}
return factory;
}
use of javax.xml.parsers.SAXParserFactory in project languagetool by languagetool-org.
the class WikipediaQuickCheck method getRevisionContent.
private MediaWikiContent getRevisionContent(String completeWikiContent) {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser;
RevisionContentHandler handler = new RevisionContentHandler();
try {
saxParser = factory.newSAXParser();
saxParser.parse(new InputSource(new StringReader(completeWikiContent)), handler);
} catch (Exception e) {
throw new RuntimeException("Could not parse XML: " + completeWikiContent, e);
}
return new MediaWikiContent(handler.getRevisionContent(), handler.getTimestamp());
}
use of javax.xml.parsers.SAXParserFactory in project languagetool by languagetool-org.
the class DisambiguationRuleLoader method getRules.
public final List<DisambiguationPatternRule> getRules(InputStream stream) throws ParserConfigurationException, SAXException, IOException {
DisambiguationRuleHandler handler = new DisambiguationRuleHandler();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
Tools.setPasswordAuthenticator();
saxParser.parse(stream, handler);
return handler.getDisambRules();
}
Aggregations