List of usage examples for javax.xml.stream XMLInputFactory IS_SUPPORTING_EXTERNAL_ENTITIES
String IS_SUPPORTING_EXTERNAL_ENTITIES
To view the source code for javax.xml.stream XMLInputFactory IS_SUPPORTING_EXTERNAL_ENTITIES.
Click Source Link
From source file:com.predic8.membrane.core.interceptor.schemavalidation.SchematronValidator.java
public SchematronValidator(ResolverMap resourceResolver, String schematron, ValidatorInterceptor.FailureHandler failureHandler, Router router, BeanFactory beanFactory) throws Exception { this.failureHandler = failureHandler; //works as standalone "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl" TransformerFactory fac;/* w w w . j a v a2s. c o m*/ try { fac = beanFactory.getBean("transformerFactory", TransformerFactory.class); } catch (NoSuchBeanDefinitionException e) { throw new RuntimeException( "Please define a bean called 'transformerFactory' in monitor-beans.xml, e.g. with " + "<spring:bean id=\"transformerFactory\" class=\"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl\" />", e); } fac.setURIResolver(new URIResolver() { @Override public Source resolve(String href, String base) throws TransformerException { return new StreamSource(SchematronValidator.class.getResourceAsStream(href)); } }); Transformer t = fac.newTransformer( new StreamSource(SchematronValidator.class.getResourceAsStream("conformance1-5.xsl"))); // transform schematron-XML into XSLT DOMResult r = new DOMResult(); t.transform(new StreamSource(router.getResolverMap().resolve(schematron)), r); // build XSLT transformers fac.setURIResolver(null); int concurrency = Runtime.getRuntime().availableProcessors() * 2; transformers = new ArrayBlockingQueue<Transformer>(concurrency); for (int i = 0; i < concurrency; i++) { Transformer transformer = fac.newTransformer(new DOMSource(r.getNode())); transformer.setErrorListener(new NullErrorListener()); // silence console logging transformers.put(transformer); } xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * This constructor gets a new {@link XMLInputFactory} instance that is reused every time * {@link #process(com.autonomy.aci.client.transport.AciResponseInputStream)} is called, this * should be faster than creating a new instance every time this method is called. * <p>/*from w ww . j a v a2 s . c o m*/ * The properties are set to the following defaults if they are not specified as system properties: * <table summary=""> * <tr><th>Property</th><th>Default</th></tr> * <tr><td>XMLInputFactory.IS_NAMESPACE_AWARE</td><td><tt>false</tt></td></tr> * <tr><td>XMLInputFactory.IS_VALIDATING<tt>false</tt></td></tr> * <tr><td>XMLInputFactory.IS_COALESCING<tt>false</tt></td></tr> * <tr><td>XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES<tt>true</tt></td></tr> * <tr><td>XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES<tt>false</tt></td></tr> * <tr><td>XMLInputFactory.SUPPORT_DTD<tt>true</tt></td></tr> * </table> */ protected AbstractStAXProcessor() { // See if the various XMLInputFactory properties are set as system properties... namespaceAware = BooleanUtils.toBoolean( StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE), "false")); validating = BooleanUtils .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_VALIDATING), "false")); coalescing = BooleanUtils .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_COALESCING), "false")); replacingEntityReferences = BooleanUtils.toBoolean(StringUtils .defaultString(System.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES), "true")); supportingExternalEntities = BooleanUtils.toBoolean(StringUtils .defaultString(System.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES), "false")); supportDtd = BooleanUtils .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.SUPPORT_DTD), "true")); // Create the XMLStreamReader factory... xmlInputFactory = XMLInputFactory.newInstance(); }
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); }
From source file:com.streamsets.pipeline.stage.origin.salesforce.ForceSource.java
public ForceSource(ForceSourceConfigBean conf) { this.conf = conf; xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); }
From source file:ddf.catalog.source.opensearch.OpenSearchSource.java
private void configureXmlInputFactory() { xmlInputFactory = XMLInputFactory2.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java
/** * This method firstly checks that the content type of the response is text based and can be parsed. If so, it * converts the <tt>AciResponseInputStream</tt> into a StAX <tt>XMLStreamReader</tt> and calls the the {@link * #process(javax.xml.stream.XMLStreamReader)} method that should be implemented in a subclass to do all the work. * @param aciResponseInputStream The ACI response to process * @return An object of type <tt>T</tt> * @throws AciErrorException If the ACI response was an error response * @throws ProcessorException If an error occurred during the processing of the IDOL response */// w w w . j a va 2s .c o m public T process(final AciResponseInputStream aciResponseInputStream) { LOGGER.trace("process() called..."); if (!"text/xml".equalsIgnoreCase(aciResponseInputStream.getContentType())) { throw new ProcessorException( "This processor is unable to process non-text ACI responses. The content type for this response is " + aciResponseInputStream.getContentType()); } // Define this here so we can make sure it's closed when the processor is finished... XMLStreamReader xmlStreamReader = null; try { // Update the factory with the various properties as they might have changed since the last run... xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, namespaceAware); xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, validating); xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, coalescing); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, replacingEntityReferences); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, supportingExternalEntities); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, supportDtd); // Convert the input stream.. xmlStreamReader = xmlInputFactory.createXMLStreamReader(aciResponseInputStream); return process(xmlStreamReader); } catch (final XMLStreamException xmlse) { throw new ProcessorException("Unable to convert the InputStream to a XMLStreamReader", xmlse); } finally { if (xmlStreamReader != null) { try { // This does NOT close the underlying AciResponseInputStream xmlStreamReader.close(); } catch (final XMLStreamException xmlse) { LOGGER.error("Unable to close the XMLStreamReader.", xmlse); } } } }
From source file:demo.SourceHttpMessageConverter.java
private Source readStAXSource(InputStream body) { try {/*from ww w.j a va 2 s . co m*/ 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); } }
From source file:ddf.catalog.source.opensearch.impl.OpenSearchSource.java
private void configureXmlInputFactory() { xmlInputFactory = XMLInputFactory2.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); // This disables DTDs entirely for that factory xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java
@Test public void testXMLInputFactorySystemProperties() throws NoSuchFieldException, IllegalAccessException { AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class); final XMLInputFactory mockXmlInputFactory = mock(XMLInputFactory.class); final Field field = ReflectionTestUtils.getAccessibleField(AbstractStAXProcessor.class, "xmlInputFactory"); field.set(abstractStAXProcessor, mockXmlInputFactory); // Check the defaults... abstractStAXProcessor.process(when(mock(AciResponseInputStream.class).getContentType()) .thenReturn("text/xml").<AciResponseInputStream>getMock()); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_VALIDATING, false); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_COALESCING, false); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); verify(mockXmlInputFactory).setProperty(XMLInputFactory.SUPPORT_DTD, true); // Set different values via system properties... System.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, "true"); System.setProperty(XMLInputFactory.IS_VALIDATING, "true"); System.setProperty(XMLInputFactory.IS_COALESCING, "true"); System.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, "false"); System.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, "true"); System.setProperty(XMLInputFactory.SUPPORT_DTD, "false"); // Create a new spy... abstractStAXProcessor = spy(AbstractStAXProcessor.class); field.set(abstractStAXProcessor, mockXmlInputFactory); // Check the values have changed when set... abstractStAXProcessor.process(when(mock(AciResponseInputStream.class).getContentType()) .thenReturn("text/xml").<AciResponseInputStream>getMock()); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_VALIDATING, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_COALESCING, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.SUPPORT_DTD, false); }
From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java
@Test public void testXMLInputFactoryPropertyAccessors() throws NoSuchFieldException, IllegalAccessException { // Check for the default values... final AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class); assertThat(abstractStAXProcessor.isNamespaceAware(), is(false)); assertThat(abstractStAXProcessor.isValidating(), is(false)); assertThat(abstractStAXProcessor.isCoalescing(), is(false)); assertThat(abstractStAXProcessor.isReplacingEntityReferences(), is(true)); assertThat(abstractStAXProcessor.isSupportingExternalEntities(), is(false)); assertThat(abstractStAXProcessor.isSupportDtd(), is(true)); // Set new values via the property accessors... abstractStAXProcessor.setNamespaceAware(true); abstractStAXProcessor.setValidating(true); abstractStAXProcessor.setCoalescing(true); abstractStAXProcessor.setReplacingEntityReferences(false); abstractStAXProcessor.setSupportingExternalEntities(true); abstractStAXProcessor.setSupportDtd(false); final XMLInputFactory mockXmlInputFactory = mock(XMLInputFactory.class); final Field field = ReflectionTestUtils.getAccessibleField(AbstractStAXProcessor.class, "xmlInputFactory"); field.set(abstractStAXProcessor, mockXmlInputFactory); // Check the values have changed... abstractStAXProcessor.process(when(mock(AciResponseInputStream.class).getContentType()) .thenReturn("text/xml").<AciResponseInputStream>getMock()); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_VALIDATING, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_COALESCING, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true); verify(mockXmlInputFactory).setProperty(XMLInputFactory.SUPPORT_DTD, false); }