use of org.apache.xerces.jaxp.SAXParserFactoryImpl in project intellij-community by JetBrains.
the class ValidateXmlActionHandler method createParser.
protected SAXParser createParser() throws SAXException, ParserConfigurationException {
if (!needsDtdChecking() && !needsSchemaChecking() && !myForceChecking) {
return null;
}
SAXParserFactory factory = new SAXParserFactoryImpl();
boolean schemaChecking = false;
if (hasDtdDeclaration()) {
factory.setValidating(true);
}
if (needsSchemaChecking()) {
factory.setValidating(true);
factory.setNamespaceAware(true);
//jdk 1.5 API
try {
factory.setXIncludeAware(true);
} catch (NoSuchMethodError ignore) {
}
schemaChecking = true;
}
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (Exception ignore) {
}
SAXParser parser = factory.newSAXParser();
parser.setProperty(ENTITY_RESOLVER_PROPERTY_NAME, myXmlResourceResolver);
try {
parser.getXMLReader().setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (Exception ignore) {
}
if (schemaChecking) {
// when dtd checking schema refs could not be validated @see http://marc.theaimsgroup.com/?l=xerces-j-user&m=112504202423704&w=2
XMLGrammarPool grammarPool = getGrammarPool(myFile, myForceChecking);
configureEntityManager(myFile, parser);
parser.getXMLReader().setProperty(GRAMMAR_FEATURE_ID, grammarPool);
}
try {
if (schemaChecking) {
parser.setProperty(JAXPConstants.JAXP_SCHEMA_LANGUAGE, JAXPConstants.W3C_XML_SCHEMA);
parser.getXMLReader().setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
if (Boolean.TRUE.equals(Boolean.getBoolean(XmlResourceResolver.HONOUR_ALL_SCHEMA_LOCATIONS_PROPERTY_KEY))) {
parser.getXMLReader().setFeature("http://apache.org/xml/features/honour-all-schemaLocations", true);
}
parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", Boolean.TRUE);
parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/warn-on-duplicate-attdef", Boolean.TRUE);
}
parser.getXMLReader().setFeature("http://apache.org/xml/features/warn-on-duplicate-entitydef", Boolean.TRUE);
parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/unparsed-entity-checking", Boolean.FALSE);
} catch (SAXNotRecognizedException ex) {
// it is possible to continue work with configured parser
LOG.info("Xml parser installation seems screwed", ex);
}
return parser;
}
Aggregations