use of org.apache.xerces.xni.grammars.Grammar 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.Grammar 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]));
}
Aggregations