List of usage examples for org.xml.sax InputSource InputSource
public InputSource(Reader characterStream)
From source file:com.latticeware.xecute.Engine.java
public Object execute(String script, Map<String, Object> env) throws UnsupportedEncodingException, JellyException { ByteArrayOutputStream baos = new ByteArrayOutputStream(5120); ByteArrayInputStream bais = new ByteArrayInputStream(script.getBytes()); XMLOutput xo = XMLOutput.createXMLOutput(baos); InputSource is = new InputSource(bais); JellyContext context = new JellyContext(); env.keySet().forEach((key) -> {//from w w w .j a v a 2 s .com context.setVariable(key, env.get(key)); }); context.runScript(is, xo); return baos.toString(); }
From source file:Main.java
public static Document parseDoc(final InputStream is) throws ParserConfigurationException, SAXException, IOException { try {/*www. j a v a2 s.c om*/ BufferedInputStream in = new BufferedInputStream(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature("http://xml.org/sax/features/external-general-entities", false); factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource source = new InputSource(in); return builder.parse(source); } finally { is.close(); } }
From source file:Main.java
public static Element loadDocument(String value, String type) { Document doc = null;//from w ww .ja va2 s. co m InputSource xmlInp = null; try { if (type.equals("location")) { URL url = new URL(value); xmlInp = new InputSource(url.openStream()); } else { xmlInp = new InputSource(new StringReader(value)); } DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(xmlInp); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error, line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:Main.java
public static Document parse(InputStream input, Properties props) throws SAXException, ParserConfigurationException { return parse(new InputSource(input), props); }
From source file:Main.java
/** * Liefert das {@link Document} aus dem String. * /*from ww w .j a v a2 s . c om*/ * @param string String * @return {@link Document} * @throws Exception Falls was schief geht. */ public static Document getDocument(final String string) throws Exception { return getDocument(new InputSource(new StringReader(string))); }
From source file:Main.java
public static Document toXMLDocument(InputStream in) { return toXMLDocument(new InputSource(in)); }
From source file:org.blanco.techmun.android.misc.XmlParser.java
public static synchronized Document parseHttpEntity(HttpEntity entity) throws Exception { Document doc = null;/*from w ww .ja v a 2 s. c om*/ String xmlString = null; try { xmlString = EntityUtils.toString(entity); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = docBuilder.parse(new InputSource(new StringReader(xmlString))); return doc; } catch (ParseException e1) { throw new Exception("Error parsing the entity.", e1); } catch (IOException e1) { throw new Exception("Error while reading the entity.", e1); } catch (ParserConfigurationException e) { throw new Exception("Error in the parser configuration.", e); } catch (SAXException e) { throw new Exception("Error parsing the entity.", e); } }
From source file:Main.java
/** * Transforms a xml String in a Document * /* w w w . j a v a 2s . com*/ * @param xmlString * the xml Stirng * @return The Document resulted from xmlString */ private static Document parseXml(String xmlString) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xmlString)); return db.parse(is); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Element loadDocument(String location) { Document doc = null;/*w w w.j ava2 s. c o m*/ try { URL url = new URL(location); InputSource xmlInp = new InputSource(url.openStream()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(xmlInp); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (java.net.MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (java.io.IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:de.nava.informa.utils.NoOpEntityResolver.java
public InputSource resolveEntity(String publicId, String systemId) { if (logger.isDebugEnabled()) { logger.debug("publicId: " + publicId + ", systemId: " + systemId); }//from w w w . ja va2 s . c o m return new InputSource(new StringReader("")); }