List of usage examples for javax.xml.parsers SAXParserFactory setNamespaceAware
public void setNamespaceAware(boolean awareness)
From source file:com.epam.wilma.test.client.HttpRequestSender.java
private InputStream compress(final InputStream source) { try {//from ww w .j ava 2 s. co m OutputStream fis = new ByteArrayOutputStream(); SAXDocumentSerializer saxDocumentSerializer = new SAXDocumentSerializer(); saxDocumentSerializer.setOutputStream(fis); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setNamespaceAware(true); SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(source, saxDocumentSerializer); return new ByteArrayInputStream(((ByteArrayOutputStream) fis).toByteArray()); } catch (ParserConfigurationException e) { throw new SystemException("error", e); } catch (SAXException e) { throw new SystemException("error", e); } catch (IOException e) { throw new SystemException("error", e); } }
From source file:ca.nines.ise.util.XMLDriver.java
/** * Construct a driver./*from www. j a v a 2 s . co m*/ * * @throws ParserConfigurationException * @throws TransformerConfigurationException * @throws SAXException * @throws TransformerException */ public XMLDriver() throws ParserConfigurationException, TransformerConfigurationException, SAXException, TransformerException { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); nullTransformer = TransformerFactory.newInstance().newTransformer(); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setNamespaceAware(true); SAXParser saxParser = saxParserFactory.newSAXParser(); xmlReader = saxParser.getXMLReader(); }
From source file:es.mityc.firmaJava.libreria.utilidades.AnalizadorFicheroFirma.java
public void analizar(File fichero) { SAXParserFactory factoria = SAXParserFactory.newInstance(); factoria.setNamespaceAware(true); factoria.setValidating(false);// www. ja v a 2 s . c o m FileInputStream fis = null; try { fis = new FileInputStream(fichero); SAXParser parser = factoria.newSAXParser(); parser.parse(fis, this); } catch (ParserConfigurationException e) { log.error(e); } catch (SAXException e) { log.error(e); } catch (FileNotFoundException e) { log.error(e); } catch (IOException e) { log.error(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } }
From source file:io.onedecision.engine.decisions.model.dmn.validators.SchemaValidator.java
public void validate(InputStream obj, Errors errors) { InputStream is = (InputStream) obj; SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new LocalResourceResolver()); try {//from w w w. j a va2s.c om schemaFactory.newSchema(new StreamSource(getResourceAsStreamWrapper("schema/dmn.xsd"))); } catch (SAXException e1) { errors.reject("Cannot find / read schema", "Exception: " + e1.getMessage()); } SAXParserFactory parserFactory = SAXParserFactory.newInstance(); // parserFactory.setValidating(true); parserFactory.setNamespaceAware(true); // parserFactory.setSchema(schema); SAXParser parser = null; try { parser = parserFactory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(this); try { parser.parse(new InputSource(is), (DefaultHandler) null); } catch (Exception e) { String msg = "Schema validation failed"; LOGGER.error(msg, e); errors.reject(msg, "Exception: " + e.getMessage()); } if (this.errors.size() > 0) { errors.reject("Schema validation failed", this.errors.toString()); } } catch (ParserConfigurationException e1) { errors.reject("Cannot create parser", "Exception: " + e1.getMessage()); } catch (SAXException e1) { errors.reject("Parser cannot be created", "Exception: " + e1.getMessage()); } }
From source file:importer.handler.post.annotate.HTMLConverter.java
/** * Turn XML note content for Harpur to HTML * @param xml the xml note// ww w. j a v a2 s. c om * @param config the JSON config to control the conversion * @return a HTML string */ String convert(String xml) throws HTMLException { try { SAXParserFactory spf = SAXParserFactory.newInstance(); HTMLConverter conv = new HTMLConverter(patterns); spf.setNamespaceAware(true); SAXParser parser = spf.newSAXParser(); XMLReader xmlReader = parser.getXMLReader(); xmlReader.setContentHandler(conv); xmlReader.setErrorHandler(new MyErrorHandler(System.err)); CharArrayReader car = new CharArrayReader(xml.toCharArray()); InputSource input = new InputSource(car); xmlReader.parse(input); return conv.body.toString(); } catch (Exception e) { throw new HTMLException(e); } }
From source file:com.sparsity.dex.etl.config.impl.XMLConfigurationProvider.java
public void load() throws DexUtilsException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true);/* ww w .j a va 2 s.co m*/ factory.setNamespaceAware(true); try { SAXParser parser = factory.newSAXParser(); DexUtilsHandler handler = new DexUtilsHandler(config); parser.parse(xml.getAbsolutePath(), handler); } catch (Exception e) { String msg = new String("Parsing error."); log.error(msg, e); throw new DexUtilsException(msg, e); } log.info("Loaded configuration from " + xml.getAbsolutePath()); }
From source file:com.opensymphony.xwork.util.DomHelper.java
/** * Creates a W3C Document that remembers the location of each element in * the source file. The location of element nodes can then be retrieved * using the {@link #getLocationObject(Element)} method. * * @param inputSource the inputSource to read the document from * @param dtdMappings a map of DTD names and public ids *///from www .j av a 2 s. c o m public static Document parse(InputSource inputSource, Map dtdMappings) { SAXParserFactory factory = null; String parserProp = System.getProperty("xwork.saxParserFactory"); if (parserProp != null) { try { Class clazz = ObjectFactory.getObjectFactory().getClassInstance(parserProp); factory = (SAXParserFactory) clazz.newInstance(); } catch (ClassNotFoundException e) { LOG.error("Unable to load saxParserFactory set by system property 'xwork.saxParserFactory': " + parserProp, e); } catch (Exception e) { LOG.error("Unable to load saxParserFactory set by system property 'xwork.saxParserFactory': " + parserProp, e); } } if (factory == null) { factory = SAXParserFactory.newInstance(); } factory.setValidating((dtdMappings != null)); factory.setNamespaceAware(true); SAXParser parser = null; try { parser = factory.newSAXParser(); } catch (Exception ex) { throw new XworkException("Unable to create SAX parser", ex); } DOMBuilder builder = new DOMBuilder(); // Enhance the sax stream with location information ContentHandler locationHandler = new LocationAttributes.Pipe(builder); try { parser.parse(inputSource, new StartHandler(locationHandler, dtdMappings)); } catch (Exception ex) { throw new XworkException(ex); } return builder.getDocument(); }
From source file:org.apache.commons.rdf.impl.sparql.SparqlClient.java
List<Map<String, RdfTerm>> queryResultSet(final String query) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(endpoint); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("query", query)); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try {//from www . j a v a 2 s.c o m HttpEntity entity2 = response2.getEntity(); InputStream in = entity2.getContent(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser saxParser = spf.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); final SparqlsResultsHandler sparqlsResultsHandler = new SparqlsResultsHandler(); xmlReader.setContentHandler(sparqlsResultsHandler); xmlReader.parse(new InputSource(in)); /* for (int ch = in.read(); ch != -1; ch = in.read()) { System.out.print((char)ch); } */ // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); return sparqlsResultsHandler.getResults(); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException ex) { throw new RuntimeException(ex); } finally { response2.close(); } }
From source file:com.zazuko.blv.outbreak.tools.SparqlClient.java
List<Map<String, RDFTerm>> queryResultSet(final String query) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(endpoint); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("query", query)); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try {/* w w w . j a v a 2s . c o m*/ HttpEntity entity2 = response2.getEntity(); InputStream in = entity2.getContent(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser saxParser = spf.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); final SparqlsResultsHandler sparqlsResultsHandler = new SparqlsResultsHandler(); xmlReader.setContentHandler(sparqlsResultsHandler); xmlReader.parse(new InputSource(in)); /* for (int ch = in.read(); ch != -1; ch = in.read()) { System.out.print((char)ch); } */ // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); return sparqlsResultsHandler.getResults(); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException ex) { throw new RuntimeException(ex); } finally { response2.close(); } }
From source file:com.gc.iotools.fmt.detect.droid.DroidDetectorImpl.java
private XMLReader getXMLReader(final SAXModelBuilder mb) throws Exception { final SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); // factory.setValidating(true); final SAXParser saxParser = factory.newSAXParser(); final XMLReader parser = saxParser.getXMLReader(); // URL url = DroidDetectorImpl.class // .getResource("DROID_SignatureFile.xsd"); // parser.setProperty( // "http://java.sun.com/xml/jaxp/properties/schemaSource", url); mb.setupNamespace(SIGNATURE_FILE_NS, true); parser.setContentHandler(mb);/*from w ww. j av a2 s. c o m*/ return parser; }