/** * Variant of {@link #createDefensiveInputFactory()} with a custom instance. * @param instanceSupplier supplier for the input factory instance * @return a new defensively initialized input factory instance to use * @since 5.0.12 */ public static <T extends XMLInputFactory> T createDefensiveInputFactory(Supplier<T> instanceSupplier) { T inputFactory = instanceSupplier.get(); inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); inputFactory.setXMLResolver(NO_OP_XML_RESOLVER); return inputFactory; }
@SuppressWarnings( { "UnnecessaryLocalVariable" }) private XMLInputFactory buildStaxFactory() { XMLInputFactory staxFactory = XMLInputFactory.newInstance(); staxFactory.setXMLResolver( xmlResourceResolver ); return staxFactory; }
@SuppressWarnings( { "UnnecessaryLocalVariable" }) private XMLInputFactory buildStaxFactory() { XMLInputFactory staxFactory = XMLInputFactory.newInstance(); staxFactory.setXMLResolver( xmlResourceResolver ); return staxFactory; }
/** * Variant of {@link #createDefensiveInputFactory()} with a custom instance. * @param instanceSupplier supplier for the input factory instance * @return a new defensively initialized input factory instance to use * @since 5.0.12 */ public static <T extends XMLInputFactory> T createDefensiveInputFactory(Supplier<T> instanceSupplier) { T inputFactory = instanceSupplier.get(); inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); inputFactory.setXMLResolver(NO_OP_XML_RESOLVER); return inputFactory; }
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 } } }
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 } } }
/** * Creates and returns a {@link XMLStreamReader} for the passed {@link VirtualFile ejb-jar.xml} * * @param stream The input stream * @param ejbJarXml * @return * @throws DeploymentUnitProcessingException * */ private static XMLStreamReader getXMLStreamReader(InputStream stream, VirtualFile ejbJarXml, XMLResolver resolver) throws DeploymentUnitProcessingException { try { final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(resolver); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(stream); return xmlReader; } catch (XMLStreamException xmlse) { throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + ejbJarXml.getPathName()); } }
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); } }
is = facesConfig.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader parser = inputFactory.createXMLStreamReader(is); StringBuilder className = null;
is = facesConfig.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader parser = inputFactory.createXMLStreamReader(is); StringBuilder phaseListenerName = null;
private EarMetaData handleSpecMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { final VirtualFile applicationXmlFile = deploymentFile.getChild(APPLICATION_XML); if (!applicationXmlFile.exists()) { return null; } InputStream inputStream = null; try { inputStream = applicationXmlFile.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream); return EarMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer); } catch (Exception e) { throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile); } finally { VFSUtils.safeClose(inputStream); } }
private JBossAppMetaData handleJbossMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { final VirtualFile applicationXmlFile = deploymentFile.getChild(JBOSS_APP_XML); if (!applicationXmlFile.exists()) { //may have been in jboss-all.xml return deploymentUnit.getAttachment(AppJBossAllParser.ATTACHMENT_KEY); } InputStream inputStream = null; try { inputStream = applicationXmlFile.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream); return JBossAppMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer); } catch (Exception e) { throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile); } finally { VFSUtils.safeClose(inputStream); } }
private TldMetaData parseTLD(VirtualFile tld) throws DeploymentUnitProcessingException { if (IMPLICIT_TLD.equals(tld.getName())) { // Implicit TLDs are different from regular TLDs return new TldMetaData(); } InputStream is = null; try { is = tld.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); return TldMetaDataParser.parse(xmlReader); } catch (XMLStreamException e) { throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e); } catch (IOException e) { throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.toString()), e); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // Ignore } } }
private TldMetaData parseTLD(Resource tld) throws DeploymentUnitProcessingException { if (IMPLICIT_TLD.equals(tld.getName())) { // Implicit TLDs are different from regular TLDs return new TldMetaData(); } InputStream is = null; try { is = tld.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); return TldMetaDataParser.parse(xmlReader); } catch (XMLStreamException e) { throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.getName(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e); } catch (IOException e) { throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.getName()), e); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // Ignore } } }
is = webFragment.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
inputFactory.setXMLResolver(dtdInfo); final XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
is = jbossWebXml.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
/** * Returns the StAX input factory specified in this parsing context. * If a factory is not explicitly specified, then a default factory * instance is created and returned. The default factory instance is * configured to be namespace-aware and to apply reasonable security * using the {@link #IGNORING_STAX_ENTITY_RESOLVER}. * * @return StAX input factory * @since Apache Tika 1.13 */ public static XMLInputFactory getXMLInputFactory() { XMLInputFactory factory = XMLInputFactory.newFactory(); tryToSetStaxProperty(factory, XMLInputFactory.IS_NAMESPACE_AWARE, true); tryToSetStaxProperty(factory, XMLInputFactory.IS_VALIDATING, false); factory.setXMLResolver(IGNORING_STAX_ENTITY_RESOLVER); trySetStaxSecurityManager(factory); return factory; }
/** Configures the given {@link XMLInputFactory} to not parse external entities. * No further configuration on is needed, all required entity resolvers are configured. */ public static void configureXMLInputFactory(XMLInputFactory inputFactory) { // don't enable validation of DTDs: trySetStAXProperty(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE); // enable this to *not* produce parsing failure on external entities: trySetStAXProperty(inputFactory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); inputFactory.setXMLResolver(EmptyEntityResolver.STAX_INSTANCE); }