List of usage examples for javax.xml.stream XMLInputFactory setProperty
public abstract void setProperty(java.lang.String name, Object value) throws java.lang.IllegalArgumentException;
From source file:Main.java
private static XMLEventReader getXMLEventReader(String filename) throws Exception { XMLInputFactory xmlif = null; XMLEventReader xmlr = null;/*from w w w . j a va 2 s . c o m*/ xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); FileInputStream fis = new FileInputStream(filename); xmlr = xmlif.createXMLEventReader(filename, fis); return xmlr; }
From source file:com.hp.application.automation.tools.octane.tests.xml.AbstractXmlIterator.java
private static XMLInputFactory createXmlInputFactory() { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); xmlFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlFactory; }
From source file:com.adaptris.core.services.UseXmlCharsetAsEncodingService.java
private static XMLInputFactory createInputFactory() { XMLInputFactory factory = XMLInputFactory.newFactory(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); return factory; }
From source file:Main.java
public static XMLStreamReader createXMLStreamReader(File file) throws FileNotFoundException, XMLStreamException { XMLInputFactory factory = XMLInputFactory.newInstance(); if (factory.isPropertySupported("javax.xml.stream.isValidating")) { factory.setProperty("javax.xml.stream.isValidating", Boolean.TRUE); }/*w ww .j ava 2s .c o m*/ XMLStreamReader reader = factory.createXMLStreamReader(new FileReader(file)); return reader; }
From source file:com.lucidworks.hadoop.ingest.util.EmptyEntityResolver.java
private static void trySetStAXProperty(XMLInputFactory inputFactory, String key, Object value) { try {//w ww . j a va 2s.c o m inputFactory.setProperty(key, value); } catch (Exception ex) { // ignore } }
From source file:Main.java
/** * 'safe' is here reflecting://from www .j a va 2 s.c o m * http://www.jorambarrez.be/blog/2013/02/19/uploading * -a-funny-xml-can-bring-down-your-server/ and * http://activiti.org/userguide/index.html#advanced.safe.bpmn.xml */ public static XMLInputFactory createSafeXmlInputFactory() { XMLInputFactory xif = XMLInputFactory.newInstance(); if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) { xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); } if (xif.isPropertySupported(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)) { xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); } if (xif.isPropertySupported(XMLInputFactory.SUPPORT_DTD)) { xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); } return xif; }
From source file:Main.java
/** * Converts the XML file specified into the specified POJO type * @param <T> the object type of the POJO * @param xmlfile the XML file to convert * @param classOfT the class of the POJO * @return the POJO object if conversion was successful * @throws JAXBException/*from w w w . j a v a 2 s . c o m*/ * @throws XMLStreamException * @throws FileNotFoundException */ public static <T> T convertToPojo(File xmlfile, Class<T> classOfT) throws JAXBException, XMLStreamException, FileNotFoundException { JAXBContext jaxbContext = JAXBContext.newInstance(classOfT); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); XMLInputFactory xif = XMLInputFactory.newFactory(); // settings to prevent xxe // would be funny if this tool is itsef is vulnerable to xxe :D xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader(xmlfile)); T t = (T) jaxbUnmarshaller.unmarshal(xsr);//(xmlfile); return t; }
From source file:ValidateStax.java
private static XMLEventReader getXMLEventReader(String filename) { XMLInputFactory xmlif = null; XMLEventReader xmlr = null;//from w ww. ja v a 2 s . c o m try { xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); FileInputStream fis = new FileInputStream(filename); xmlr = xmlif.createXMLEventReader(filename, fis); } catch (Exception ex) { ex.printStackTrace(); } return xmlr; }
From source file:StreamSrcStAXRst.java
private static XMLEventReader getXMLEventReader(String filename) { XMLInputFactory xmlif = null; XMLEventReader xmlr = null;//from w w w. jav a2 s .c o m try { xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); FileInputStream fis = new FileInputStream(filename); xmlr = xmlif.createXMLEventReader(filename, fis); } catch (Exception ex) { ex.printStackTrace(); } return xmlr; }
From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java
private static JiriManifest parseManifest(Repository repo, String ref, String file) throws JAXBException, IOException, XMLStreamException { byte[] b = Utils.readBlob(repo, ref + ":" + file); JAXBContext jc = JAXBContext.newInstance(JiriManifest.class); XMLInputFactory inf = XMLInputFactory.newFactory(); inf.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); inf.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader sr = inf.createXMLStreamReader(new StreamSource(new ByteArrayInputStream(b))); return (JiriManifest) jc.createUnmarshaller().unmarshal(sr); }