/** * @since 1.4 */ protected XMLInputFactory createInputFactory() { final XMLInputFactory instance = XMLInputFactory.newInstance(); instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); return instance; }
private void resetSheetReader() throws IOException, XMLStreamException, InvalidFormatException { sheetReader.close(); sheetStream.close(); sheetStream = xssfReader.getSheet( sheetId ); XMLInputFactory factory = XMLInputFactory.newInstance(); sheetReader = factory.createXMLStreamReader( sheetStream ); }
private String getJndiNameFromPersistenceXml() throws XMLStreamException { XMLInputFactory factory = XMLInputFactory.newInstance(); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/persistence.xml"); XMLStreamReader reader = factory.createXMLStreamReader(is); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.START_ELEMENT && "jta-data-source".equals(reader.getLocalName())) { return reader.getElementText(); } } return null; } }
public static void main(String[] args) throws Exception { // Result format Writer diffxResult = new StringWriter(); // Run the diff try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); // a DTD is merely ignored, its presence doesn't cause an exception //java.io.InputStream is = new java.io.ByteArrayInputStream(naive.getBytes("UTF-8")); String simplified = combineAdjacent( inputFactory.createXMLStreamReader(new FileInputStream(new File("tmp_adj.xml"))) ); System.out.println("Done"); } catch (Exception exc) { exc.printStackTrace(); diffxResult = null; } }
this.clazz = clazz; this.unmarshaller = JAXBContext.newInstance(clazz).createUnmarshaller(); this.reader = XMLInputFactory.newInstance().createXMLStreamReader(stream); eventType = reader.next();
@Test @Override @SuppressWarnings("unchecked") public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights streamReader.nextTag(); // skip to flight Source source = StaxUtils.createStaxSource(streamReader); JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source); FlightType flight = element.getValue(); testFlight(flight); }
try { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); // disable DTDs entirely for that factory factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); // disable external entities final XMLStreamReader xmlReader; if (charEncoding != null) { xmlReader = factory.createXMLStreamReader(stream, charEncoding); } else { xmlReader = factory.createXMLStreamReader(stream);
private void openXMLStream(InputStream in) throws XMLStreamException { XMLInputFactory factory = XMLInputFactory.newInstance(); parser = factory.createXMLStreamReader(in, "UTF-8"); int event = parser.next(); if (event != XMLStreamConstants.START_ELEMENT || !parser.getLocalName().equalsIgnoreCase("osm")) { throw new IllegalArgumentException("File is not a valid OSM stream"); } // See https://wiki.openstreetmap.org/wiki/PBF_Format#Definition_of_the_OSMHeader_fileblock String timestamp = parser.getAttributeValue(null, "osmosis_replication_timestamp"); if (timestamp == null) timestamp = parser.getAttributeValue(null, "timestamp"); if (timestamp != null) { try { fileheader = new OSMFileHeader(); fileheader.setTag("timestamp", timestamp); } catch (Exception ex) { } } eof = false; }
private Source readStAXSource(InputStream body, HttpInputMessage inputMessage) { try { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd()); inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities()); if (!isProcessExternalEntities()) { inputFactory.setXMLResolver(NO_OP_XML_RESOLVER); } XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body); return new StAXSource(streamReader); } catch (XMLStreamException ex) { throw new HttpMessageNotReadableException( "Could not parse document: " + ex.getMessage(), ex, inputMessage); } }
private TldMetaData parseTLD(InputStream is) throws Exception { try { final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); return TldMetaDataParser.parse(xmlReader ); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // Ignore } } }
/** * Disables certain dangerous features that attempt to automatically fetch DTDs * * See <a href="https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet">OWASP XXE Cheat Sheet</a> */ private static XMLInputFactory createXmlInputFactory() { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); return factory; }
XMLInputFactory inputFactory = XMLInputFactory.newInstance(); InputStream in = new FileInputStream("book.xml"); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(in); streamReader.next();
@Test public void partial() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT)); streamReader.nextTag(); // skip to root assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"), streamReader.getName()); streamReader.nextTag(); // skip to child assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"), streamReader.getName()); StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader); ContentHandler contentHandler = mock(ContentHandler.class); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource()); verify(contentHandler).setDocumentLocator(any(Locator.class)); verify(contentHandler).startDocument(); verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class)); verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child"); verify(contentHandler).endDocument(); }
protected void parse(String ormFile) throws XMLStreamException { String name = null; StringBuilder tagContent = new StringBuilder(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader( Thread.currentThread().getContextClassLoader().getResourceAsStream(ormFile)); int event = reader.next();
XMLInputFactory xif = XMLInputFactory.newInstance(); xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); // a DTD is merely ignored, its presence doesn't cause an exception XMLStreamReader xsr = xif.createXMLStreamReader(is);
private TldMetaData parseTLD(InputStream is) throws Exception { try { final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); return TldMetaDataParser.parse(xmlReader ); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // Ignore } } }
public static XMLInputFactory createXmlInputFactory() { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlInputFactory; } }
@Test public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"), streamReader.getName()); streamReader.nextTag(); // skip to flight assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"), streamReader.getName()); Source source = StaxUtils.createStaxSource(streamReader); Object flight = unmarshaller.unmarshal(source); testFlight(flight); }
protected void parse(String ormFile) throws XMLStreamException { String name = null; StringBuffer tagContent = new StringBuffer(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader( Thread.currentThread().getContextClassLoader().getResourceAsStream(ormFile)); int event = reader.next();
XMLInputFactory xif = XMLInputFactory.newInstance(); xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); // a DTD is merely ignored, its presence doesn't cause an exception XMLStreamReader xsr = xif.createXMLStreamReader(is);