List of usage examples for javax.xml.stream XMLInputFactory IS_REPLACING_ENTITY_REFERENCES
String IS_REPLACING_ENTITY_REFERENCES
To view the source code for javax.xml.stream XMLInputFactory IS_REPLACING_ENTITY_REFERENCES.
Click Source Link
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:ca.efendi.datafeeds.messaging.FtpSubscriptionMessageListener.java
private void parse(FtpSubscription ftpSubscription, final InputStream is) throws XMLStreamException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true); factory.setProperty(XMLInputFactory.IS_COALESCING, true); final XMLStreamReader reader = factory.createXMLStreamReader(is, "UTF-8"); CJProduct product = null;/*from w w w . j a v a 2s .co m*/ String tagContent = null; //final ServiceContext serviceContext = new ServiceContext(); //ServiceContext serviceContext = ServiceContextFactory.getInstance( // BlogsEntry.class.getName(), actionRequest); //serviceContext.setScopeGroupId(20159); while (reader.hasNext()) { final int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: //tagContent = ""; if ("product".equals(reader.getLocalName())) { product = _cjProductLocalService.createCJProduct(0); } break; case XMLStreamConstants.CHARACTERS: //tagContent += reader.getText().trim(); tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "product": try { _log.warn("refreshing document..."); _cjProductLocalService.refresh(ftpSubscription, product); } catch (final SystemException e) { _log.error(e); } catch (final PortalException e) { _log.error(e); } break; case "programname": product.setProgramName(tagContent); break; case "programurl": product.setProgramUrl(tagContent); break; case "catalogname": product.setCatalogName(tagContent); break; case "lastupdated": product.setLastUpdated(tagContent); break; case "name": product.setName(tagContent); break; case "keywords": product.setKeywords(tagContent); break; case "description": product.setDescription(tagContent); break; case "sku": product.setSku(tagContent); break; case "manufacturer": product.setManufacturer(tagContent); break; case "manufacturerid": product.setManufacturerId(tagContent); break; case "currency": product.setCurrency(tagContent); break; case "price": product.setPrice(tagContent); break; case "buyurl": product.setBuyUrl(tagContent); break; case "impressionurl": product.setImpressionUrl(tagContent); break; case "imageurl": product.setImageUrl(tagContent); break; case "instock": product.setInStock(tagContent); break; } break; case XMLStreamConstants.START_DOCUMENT: break; } } }
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); }
From source file:org.activiti.bpmn.converter.BpmnXMLConverter.java
public BpmnModel convertToBpmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml, String encoding) { XMLInputFactory xif = XMLInputFactory.newInstance(); if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) { xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); }/*from w ww .j a v a 2s. com*/ 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); } InputStreamReader in = null; try { in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding); XMLStreamReader xtr = xif.createXMLStreamReader(in); try { if (validateSchema) { if (!enableSafeBpmnXml) { validateModel(inputStreamProvider); } else { validateModel(xtr); } // The input stream is closed after schema validation in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding); xtr = xif.createXMLStreamReader(in); } } catch (Exception e) { throw new RuntimeException("Could not validate XML with BPMN 2.0 XSD", e); } // XML conversion return convertToBpmnModel(xtr); } catch (UnsupportedEncodingException e) { throw new RuntimeException("The bpmn 2.0 xml is not UTF8 encoded", e); } catch (XMLStreamException e) { throw new RuntimeException("Error while reading the BPMN 2.0 XML", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { LOGGER.debug("Problem closing BPMN input stream", e); } } } }
From source file:org.activiti.dmn.xml.converter.DmnXMLConverter.java
public DmnDefinition convertToDmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml, String encoding) { XMLInputFactory xif = XMLInputFactory.newInstance(); if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) { xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); }/*from w w w . j a v a 2 s. c om*/ 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); } InputStreamReader in = null; try { in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding); XMLStreamReader xtr = xif.createXMLStreamReader(in); try { if (validateSchema) { if (!enableSafeBpmnXml) { validateModel(inputStreamProvider); } else { validateModel(xtr); } // The input stream is closed after schema validation in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding); xtr = xif.createXMLStreamReader(in); } } catch (Exception e) { throw new DmnXMLException(e.getMessage(), e); } // XML conversion return convertToDmnModel(xtr); } catch (UnsupportedEncodingException e) { throw new DmnXMLException("The dmn xml is not UTF8 encoded", e); } catch (XMLStreamException e) { throw new DmnXMLException("Error while reading the BPMN 2.0 XML", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { LOGGER.debug("Problem closing DMN input stream", e); } } } }
From source file:org.commonjava.maven.galley.maven.parse.XMLInfrastructure.java
public XMLInfrastructure() { transformerFactory = TransformerFactory.newInstance(); if (!transformerFactory.getClass().getName().contains("redirected")) { safeInputFactory = XMLInputFactory.newInstance(); safeInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); safeInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false); } else {//ww w.ja va 2s. co m logger.warn("Somebody is playing games with the TransformerFactory...we cannot use it safely: {}", transformerFactory); safeInputFactory = null; } dbFactory = DocumentBuilderFactory.newInstance(); // TODO: Probably don't need these available, since it's unlikely Maven can do much with them. dbFactory.setValidating(false); dbFactory.setXIncludeAware(false); dbFactory.setNamespaceAware(false); // TODO: Are these wise?? We're mainly interested in harvesting POM information, not preserving fidelity... dbFactory.setIgnoringComments(true); dbFactory.setExpandEntityReferences(false); dbFactory.setCoalescing(true); }
From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java
public BpmnModel convertToBpmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml, String encoding) { XMLInputFactory xif = XMLInputFactory.newInstance(); if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) { xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); }/* www. j ava2s .c om*/ 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); } InputStreamReader in = null; try { in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding); XMLStreamReader xtr = xif.createXMLStreamReader(in); try { if (validateSchema) { if (!enableSafeBpmnXml) { validateModel(inputStreamProvider); } else { validateModel(xtr); } // The input stream is closed after schema validation in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding); xtr = xif.createXMLStreamReader(in); } } catch (Exception e) { throw new XMLException(e.getMessage(), e); } // XML conversion return convertToBpmnModel(xtr); } catch (UnsupportedEncodingException e) { throw new XMLException("The bpmn 2.0 xml is not UTF8 encoded", e); } catch (XMLStreamException e) { throw new XMLException("Error while reading the BPMN 2.0 XML", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { LOGGER.debug("Problem closing BPMN input stream", e); } } } }
From source file:org.flowable.cmmn.converter.CmmnXmlConverter.java
public CmmnModel convertToCmmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml, String encoding) { XMLInputFactory xif = XMLInputFactory.newInstance(); if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) { xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false); }/* w w w. jav a2s .c o m*/ 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); } if (encoding == null) { encoding = DEFAULT_ENCODING; } if (validateSchema) { try (InputStreamReader in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding)) { if (!enableSafeBpmnXml) { validateModel(inputStreamProvider); } else { validateModel(xif.createXMLStreamReader(in)); } } catch (UnsupportedEncodingException e) { throw new CmmnXMLException("The CMMN 1.1 xml is not properly encoded", e); } catch (XMLStreamException e) { throw new CmmnXMLException("Error while reading the CMMN 1.1 XML", e); } catch (Exception e) { throw new CmmnXMLException(e.getMessage(), e); } } // The input stream is closed after schema validation try (InputStreamReader in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding)) { // XML conversion return convertToCmmnModel(xif.createXMLStreamReader(in)); } catch (UnsupportedEncodingException e) { throw new CmmnXMLException("The CMMN 1.1 xml is not properly encoded", e); } catch (XMLStreamException e) { throw new CmmnXMLException("Error while reading the CMMN 1.1 XML", e); } catch (IOException e) { throw new CmmnXMLException(e.getMessage(), e); } }
From source file:org.plasma.sdo.xml.StreamUnmarshaller.java
private void setup() { this.factory = XMLInputFactory.newInstance(); factory.setXMLResolver(new XMLResolver() { public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException { log.debug("resolve: " + publicID + ":" + systemID + ":" + baseURI + ":" + namespace); return null; }/*from w w w. j av a 2 s.com*/ }); factory.setEventAllocator(new EventAllocator()); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); //set the IS_COALESCING property to true , if application desires to //get whole text data as one event. //factory.setProperty(XMLInputFactory.IS_COALESCING , Boolean.TRUE); allocator = factory.getEventAllocator(); }