List of usage examples for javax.xml.parsers SAXParserFactory newInstance
public static SAXParserFactory newInstance()
From source file:com.tupilabs.pbs.parser.NodeXmlParser.java
@Override public List<Node> parse(String xml) throws ParseException { try {/*w w w . j av a 2s . co m*/ final SAXParserFactory factory = SAXParserFactory.newInstance(); final SAXParser saxParser = factory.newSAXParser(); final NodeXmlHandler handler = new NodeXmlHandler(); saxParser.parse(new CharSequenceInputStream(xml, Charset.defaultCharset()), handler); return handler.getNodes(); } catch (IOException ioe) { throw new ParseException(ioe); } catch (SAXException e) { throw new ParseException(e); } catch (ParserConfigurationException e) { throw new ParseException(e); } }
From source file:com.knowledgebooks.info_spiders.DBpediaLookupClient.java
public DBpediaLookupClient(String query) throws Exception { this.query = query; //System.out.println("\n query: " + query); HttpClient client = new HttpClient(); String query2 = query.replaceAll(" ", "+"); // URLEncoder.encode(query, "utf-8"); //System.out.println("\n query2: " + query2); HttpMethod method = new GetMethod( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + query2); try {//w w w . j a va2 s . c om System.out.println("\n method: " + method.getURI()); client.executeMethod(method); System.out.println(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.err.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.err.println("Unable to connect to lookup.dbpedia.org"); } method.releaseConnection(); }
From source file:com.aurel.track.exchange.track.importer.ImporterFieldParser.java
public List<ISerializableLabelBean> parse(File xml) { //get a factory SAXParserFactory spf = SAXParserFactory.newInstance(); try {//from w w w . ja va 2s .c om //get a new instance of parser SAXParser sp = spf.newSAXParser(); //parse the file and also register this class for call backs LOGGER.debug("Field parser started..."); sp.parse(xml, this); LOGGER.debug("Field parser done..."); return fieldBeans; } catch (SAXException se) { LOGGER.error(ExceptionUtils.getStackTrace(se)); } catch (ParserConfigurationException pce) { LOGGER.error(ExceptionUtils.getStackTrace(pce)); } catch (IOException ie) { LOGGER.error(ExceptionUtils.getStackTrace(ie)); } return null; }
From source file:de.l3s.souza.search.DBpediaLookupClient.java
public DBpediaLookupClient(String query) throws Exception { this.query = query; //System.out.println("\n query: " + query); HttpClient client = new HttpClient(); String query2 = query.replaceAll(" ", "+"); // URLEncoder.encode(query, "utf-8"); //System.out.println("\n query2: " + query2); HttpMethod method = new GetMethod( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + query2); try {/*from w w w .ja v a2 s. co m*/ // System.out.println("\n method: " + method.getURI()); client.executeMethod(method); // System.out.println(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.err.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.err.println("Unable to connect to lookup.dbpedia.org"); } method.releaseConnection(); }
From source file:net.cpollet.jixture.fixtures.transformers.XmlFileFixtureTransformer.java
private SAXParser createSaxParser() { SAXParserFactory parserFactor = SAXParserFactory.newInstance(); try {//from w w w . j av a 2 s . c om return parserFactor.newSAXParser(); } catch (Exception e) { throw ExceptionUtils.wrapInRuntimeException(e); } }
From source file:com.florianmski.tracktoid.image.Fanart.java
private Fanart() { http = new DefaultHttpClient(); spf = SAXParserFactory.newInstance(); try {/*from w w w . j a va 2s . com*/ sp = spf.newSAXParser(); xr = sp.getXMLReader(); } catch (Exception e) { e.printStackTrace(); } xr.setContentHandler(this); }
From source file:net.sf.jasperreports.renderers.util.XmlDataSniffer.java
public static XmlSniffResult sniffXml(byte[] data) { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false);//from ww w . j a va2 s.c o m factory.setNamespaceAware(false); factory.setXIncludeAware(false); setParserFeature(factory, FEATURE_EXTERNAL_GENERAL_ENTITIES, false); setParserFeature(factory, FEATURE_EXTERNAL_PARAMETER_ENTITIES, false); setParserFeature(factory, FEATURE_LOAD_EXTERNAL_DTD, false); SaxHandler handler = new SaxHandler(); ByteArrayInputStream bais = new ByteArrayInputStream(data); try { SAXParser saxParser = factory.newSAXParser(); saxParser.parse(bais, handler); return new XmlSniffResult(handler.rootElementName); } catch (ValidXmlSAXException e) { return new XmlSniffResult(handler.rootElementName); } catch (SAXException | ParserConfigurationException | IOException e) { return null; } }
From source file:org.sansdemeure.zenindex.indexer.odt.TestHTMLConverter.java
@Test public void test() throws ParserConfigurationException, SAXException, IOException { TestAppender testAppender = new TestAppender(); File testDir = FileUtil.prepareEmptyDirectory(TestHTMLConverter.class); FileUtil.copyFromResources("docs/1992/Sandokai_with_2comments.odt", testDir, "Sandokai.odt"); File odt = new File(testDir, "Sandokai.odt"); try (ODTResource odtRessource = new ODTResource(odt)) { InputStream in = odtRessource.openContentXML(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); OdtHTMLConverterHandler htmlConverter = new OdtHTMLConverterHandler(); saxParser.parse(in, htmlConverter); testAppender.verify("paragraphs were created"); testAppender.verify("spans were created"); testAppender.verify("2 annotations were created"); testAppender.verify("All paragraphs were closed"); testAppender.verify("All spans were closed"); }/*from ww w. java 2 s . c o m*/ }
From source file:fitnesse.maven.io.ParentPomParser.java
private Digester createDigester() { try {/*from w w w.j a v a 2 s . co m*/ Digester digester = new Digester(SAXParserFactory.newInstance().newSAXParser()); digester.addObjectCreate("project/parent", ParentPomBean.class.getName()); digester.addBeanPropertySetter("project/parent/groupId", "groupId"); digester.addBeanPropertySetter("project/parent/artifactId", "artifactId"); digester.addBeanPropertySetter("project/parent/version", "version"); return digester; } catch (ParserConfigurationException e) { throw new MavenException(e); } catch (SAXException e) { throw new MavenException(e); } }
From source file:com.pnf.plugin.pdf.XFAParser.java
public void parse(byte[] xmlContent) throws ParserConfigurationException, SAXException, IOException { CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPLACE); decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); CharBuffer parsed = decoder.decode(ByteBuffer.wrap(xmlContent)); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); try (@SuppressWarnings("deprecation") InputStream is = new ReaderInputStream(new CharArrayReader(parsed.array()))) { parser.parse(is, xfa);/*from w w w. j ava 2 s .c o m*/ } catch (Exception e) { logger.catching(e); logger.error("Error while parsing XFA content"); } }