use of org.apache.xerces.xni.grammars.XSGrammar 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.XSGrammar in project jena by apache.
the class XSDDatatype method loadUserDefined.
/**
* Internal implementation of loadUserDefined
*
* @param uri the absolute uri of the schema file to be loaded
* @param reader the Reader stream onto the file (useful if you wish to load a cached copy of the schema file)
* @param encoding the encoding of the source file (can be null)
* @param tm the type mapper into which to load the definitions
* @return a List of strings giving the uri's of the newly defined datatypes
* @throws DatatypeFormatException if there is a problem during load (not that we use Xerces
* in default mode for load which may provide diagnostic output direct to stderr)
*/
private static List<String> loadUserDefined(XMLInputSource source, TypeMapper tm) throws DatatypeFormatException {
XMLGrammarPreparser parser = new XMLGrammarPreparser();
parser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
try {
XSGrammar xsg = (XSGrammar) parser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, source);
org.apache.xerces.xs.XSModel xsm = xsg.toXSModel();
XSNamedMap map = xsm.getComponents(XSTypeDefinition.SIMPLE_TYPE);
int numDefs = map.getLength();
ArrayList<String> names = new ArrayList<>(numDefs);
for (int i = 0; i < numDefs; i++) {
XSSimpleType xstype = (XSSimpleType) map.item(i);
// Filter built in types - only needed for 2.6.0
if (!XSD.equals(xstype.getNamespace())) {
//xstype.derivedFrom()
XSDDatatype definedType = new XSDGenericType(xstype, source.getSystemId());
tm.registerDatatype(definedType);
names.add(definedType.getURI());
}
}
return names;
} catch (Exception e) {
// Temp
e.printStackTrace();
throw new DatatypeFormatException(e.toString());
}
}
use of org.apache.xerces.xni.grammars.XSGrammar in project webtools.sourceediting by eclipse.
the class CompleteNewApiTest method getGrammar.
// private Schema getSchema(InputStream schemaIs) throws SAXException {
// SchemaFactory sf = SchemaFactory
// .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Schema schema = sf.newSchema(new StreamSource(schemaIs));
// return schema;
// }
protected XSModel getGrammar(URL schemaURL) throws IOException, SAXException {
InputStream schemaIs = schemaURL.openStream();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new StreamSource(schemaIs));
XSGrammarPoolContainer poolContainer = (XSGrammarPoolContainer) schema;
XMLGrammarPool pool = poolContainer.getGrammarPool();
Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
XSGrammar[] xsGrammars = new XSGrammar[grammars.length];
System.arraycopy(grammars, 0, xsGrammars, 0, grammars.length);
return xsGrammars[0].toXSModel(xsGrammars);
}
use of org.apache.xerces.xni.grammars.XSGrammar in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathTest method getGrammar.
protected XSModel getGrammar(URL schemaURL) throws IOException, SAXException {
InputStream schemaIs = testResolve(schemaURL);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new StreamSource(schemaIs));
XSGrammarPoolContainer poolContainer = (XSGrammarPoolContainer) schema;
XMLGrammarPool pool = poolContainer.getGrammarPool();
Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
XSGrammar[] xsGrammars = new XSGrammar[grammars.length];
System.arraycopy(grammars, 0, xsGrammars, 0, grammars.length);
return xsGrammars[0].toXSModel(xsGrammars);
}
use of org.apache.xerces.xni.grammars.XSGrammar in project iaf by ibissource.
the class JavaxValidationContext method createValidationContext.
@Override
public JavaxValidationContext createValidationContext(PipeLineSession session, RootValidations rootValidations, Map<List<String>, List<String>> invalidRootNamespaces) throws ConfigurationException, PipeRunException {
// clear session variables
super.createValidationContext(session, rootValidations, invalidRootNamespaces);
String schemasId;
Schema schema;
Set<String> namespaceSet = new HashSet<String>();
List<XSModel> xsModels = null;
start();
schemasId = schemasProvider.getSchemasId();
if (schemasId == null) {
schemasId = schemasProvider.getSchemasId(session);
getSchemaObject(schemasId, schemasProvider.getSchemas(session));
}
schema = javaxSchemas.get(schemasId);
if (schema != null) {
org.apache.xerces.jaxp.validation.XSGrammarPoolContainer xercesSchema = (org.apache.xerces.jaxp.validation.XSGrammarPoolContainer) schema;
xercesSchema.getGrammarPool();
xsModels = new LinkedList<XSModel>();
Grammar[] grammars = xercesSchema.getGrammarPool().retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
for (int i = 0; i < grammars.length; i++) {
XSModel model = ((XSGrammar) grammars[i]).toXSModel();
xsModels.add(model);
StringList namespaces = model.getNamespaces();
for (int j = 0; j < namespaces.getLength(); j++) {
String namespace = namespaces.item(j);
namespaceSet.add(namespace);
}
}
}
JavaxValidationContext result = new JavaxValidationContext(schemasId, schema, namespaceSet, xsModels);
result.init(schemasProvider, schemasId, namespaceSet, rootValidations, invalidRootNamespaces, ignoreUnknownNamespaces);
return result;
}
Aggregations