List of usage examples for javax.xml.parsers SAXParser setProperty
public abstract void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException;
Sets the particular property in the underlying implementation of org.xml.sax.XMLReader .
From source file:org.jbpm.jpdl.internal.convert.Jpdl3ConverterParser.java
public static XMLReader createXmlReader() throws Exception { SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); try {//from ww w . j a v a 2s .c om saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); } catch (SAXException e) { log.warn("couldn't set schema language property", e); } try { saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", getSchemaSource()); } catch (SAXException e) { log.warn("couldn't set schema source property", e); } try { xmlReader.setFeature("http://apache.org/xml/features/validation/dynamic", true); } catch (SAXException e) { log.warn("couldn't set dynamic validation feature", e); } return xmlReader; }
From source file:org.jbpm.jpdl.xml.JpdlParser.java
public static XMLReader createXmlReader() throws Exception { SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); try {/* www . j av a2 s . co m*/ saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); } catch (SAXException e) { log.warn( "couldn't set xml parser property 'http://java.sun.com/xml/jaxp/properties/schemaLanguage' to 'http://www.w3.org/2001/XMLSchema'", e); } try { saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "http://jbpm.org/3/jpdl http://jbpm.org/jpdl-3.0.xsd " + "urn:jbpm.org:jpdl-3.0 http://jbpm.org/jpdl-3.0.xsd " + "urn:jbpm.org:jpdl-3.1 http://jbpm.org/jpdl-3.1.xsd " + "urn:jbpm.org:jpdl-3.2 http://jbpm.org/jpdl-3.2.xsd"); } catch (SAXException e) { log.warn( "couldn't set xml parser property 'http://apache.org/xml/properties/schema/external-schemaLocation'", e); } try { xmlReader.setFeature("http://apache.org/xml/features/validation/dynamic", true); } catch (SAXException e) { log.warn("couldn't set xml parser feature 'http://apache.org/xml/features/validation/dynamic'", e); } return xmlReader; }
From source file:org.plasma.sdo.helper.PlasmaXMLHelper.java
private void validateSAX(InputStream inputStream, String locationURI, XMLOptions options) throws IOException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true);//from w ww. j av a 2 s. c o m factory.setNamespaceAware(true); SAXParser parser; try { factory.setFeature("http://xml.org/sax/features/validation", true); factory.setFeature("http://apache.org/xml/features/validation/schema", true); factory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); parser = factory.newSAXParser(); try { parser.setProperty(XMLConstants.JAXP_SCHEMA_LANGUAGE, SchemaConstants.XMLSCHEMA_NAMESPACE_URI); } catch (SAXNotRecognizedException e) { log.warn("parses does not support JAXP 1.2"); } if (locationURI != null) { parser.setProperty(XMLConstants.JAXP_NO_NAMESPACE_SCHEMA_SOURCE, locationURI); } XMLReader xmlReader = parser.getXMLReader(); //xmlReader.setEntityResolver(new SchemaLoader()); if (options.getErrorHandler() == null) xmlReader.setErrorHandler(new DefaultErrorHandler(options)); else xmlReader.setErrorHandler(options.getErrorHandler()); if (log.isDebugEnabled()) log.debug("validating..."); xmlReader.parse(new InputSource(inputStream)); } catch (SAXNotRecognizedException e) { throw new PlasmaDataObjectException(e); } catch (SAXNotSupportedException e) { throw new PlasmaDataObjectException(e); } catch (ParserConfigurationException e) { throw new PlasmaDataObjectException(e); } catch (SAXException e) { throw new PlasmaDataObjectException(e); } }