List of usage examples for javax.xml.stream XMLInputFactory isPropertySupported
public abstract boolean isPropertySupported(String name);
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); }//from www. j av a 2 s.c o m XMLStreamReader reader = factory.createXMLStreamReader(new FileReader(file)); return reader; }
From source file:Main.java
/** * 'safe' is here reflecting://from w ww . j av a 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: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 ww w . j a v a 2 s .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); } 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); }// w w w. j a v a 2s.co 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); } 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.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); }/* ww w .j a va 2 s. 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); } 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); }// www .java 2 s . 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.gephi.io.importer.api.ImportUtils.java
public static XMLStreamReader getXMLReader(Reader reader) { try {//from w w w. j a va 2 s .c o m XMLInputFactory inputFactory = XMLInputFactory.newInstance(); if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) { inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE); } inputFactory.setXMLReporter(new XMLReporter() { @Override public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException { throw new RuntimeException("Error:" + errorType + ", message : " + message); //System.out.println("Error:" + errorType + ", message : " + message); } }); return inputFactory.createXMLStreamReader(reader); } catch (XMLStreamException ex) { throw new RuntimeException(NbBundle.getMessage(ImportUtils.class, "ImportUtils.error_io")); } }
From source file:org.wso2.carbon.mediation.configadmin.ConfigAdmin.java
/** * Get the current Synapse configuration serialized as an string * * @return return XML configuration serialized in to a string * @throws org.apache.axis2.AxisFault if an error occurs *//* w w w . ja v a 2 s . c o m*/ public String getConfiguration() throws AxisFault { final Lock lock = getLock(); try { lock.lock(); // ConfigurationFactoryAndSerializerFinder might not have been initialized // and hence we need to call the getInstance to load the factories and serializers ConfigurationFactoryAndSerializerFinder.getInstance(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); XMLConfigurationSerializer.serializeConfiguration(getSynapseConfiguration(), stream); XMLInputFactory factory = XMLInputFactory.newInstance(); if (factory.isPropertySupported(PROP_REPORT_CDATA)) { factory.setProperty(PROP_REPORT_CDATA, Boolean.TRUE); } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(stream.toByteArray()); org.wso2.carbon.mediation.configadmin.util.XMLPrettyPrinter xmlPrettyPrinter = new org.wso2.carbon.mediation.configadmin.util.XMLPrettyPrinter( byteArrayInputStream); return xmlPrettyPrinter.xmlFormatWithComments(); } catch (XMLStreamException e) { handleException("Error serializing the Synapse configuration : Error " + e.getMessage(), e); } catch (Exception e) { handleException("Error serializing the Synapse configuration : Error " + e.getMessage(), e); } finally { lock.unlock(); } return ""; }