use of org.apache.xerces.xni.grammars.XMLGrammarPool in project intellij-community by JetBrains.
the class XmlConstraintsTest method getXSModel.
private XSModel getXSModel(String... files) {
myFixture.configureByFiles(files);
XmlFile file = (XmlFile) myFixture.getFile();
ValidateXmlActionHandler handler = new ValidateXmlActionHandler(false) {
@Override
protected SAXParser createParser() throws SAXException, ParserConfigurationException {
SAXParser parser = super.createParser();
parser.getXMLReader().setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, true);
return parser;
}
};
handler.setErrorReporter(new TestErrorReporter(handler));
handler.doValidate(file);
XMLGrammarPool grammarPool = ValidateXmlActionHandler.getGrammarPool(file);
assert grammarPool != null;
Grammar[] grammars = grammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
XSGrammar grammar = (XSGrammar) grammars[0];
return grammar.toXSModel();
}
use of org.apache.xerces.xni.grammars.XMLGrammarPool 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;
}
use of org.apache.xerces.xni.grammars.XMLGrammarPool in project intellij-community by JetBrains.
the class XsContentDFA method getXSModel.
@Nullable
private static XSModel getXSModel(XmlFile file) {
ValidateXmlActionHandler handler = new ValidateXmlActionHandler(false) {
@Override
protected SAXParser createParser() throws SAXException, ParserConfigurationException {
SAXParser parser = super.createParser();
parser.getXMLReader().setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE, true);
return parser;
}
};
handler.setErrorReporter(new ErrorReporter(handler) {
int count;
@Override
public void processError(SAXParseException ex, ValidateXmlActionHandler.ProblemType warning) throws SAXException {
if (warning != ValidateXmlActionHandler.ProblemType.WARNING && count++ > 100) {
throw new SAXException(ex);
}
}
@Override
public boolean isUniqueProblem(SAXParseException e) {
return true;
}
});
handler.doValidate(file);
XMLGrammarPool grammarPool = ValidateXmlActionHandler.getGrammarPool(file);
if (grammarPool == null) {
return null;
}
Grammar[] grammars = grammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
return grammars.length == 0 ? null : ((XSGrammar) grammars[0]).toXSModel(ContainerUtil.map(grammars, grammar -> (XSGrammar) grammar, new XSGrammar[0]));
}
use of org.apache.xerces.xni.grammars.XMLGrammarPool in project intellij-community by JetBrains.
the class ValidateXmlActionHandler method getGrammarPool.
public static XMLGrammarPool getGrammarPool(XmlFile file, boolean forceChecking) {
final XMLGrammarPool previousGrammarPool = getGrammarPool(file);
XMLGrammarPool grammarPool = null;
// check if the pool is valid
if (!forceChecking && !isValidationDependentFilesOutOfDate(file)) {
grammarPool = previousGrammarPool;
}
if (grammarPool == null) {
invalidateEntityManager(file);
grammarPool = new XMLGrammarPoolImpl();
file.putUserData(GRAMMAR_POOL_KEY, grammarPool);
}
return grammarPool;
}
Aggregations