Search in sources :

Example 6 with XSGrammar

use of org.apache.xerces.xni.grammars.XSGrammar in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathWTPTest 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);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) XMLGrammarPool(org.apache.xerces.xni.grammars.XMLGrammarPool) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XSGrammarPoolContainer(org.apache.xerces.jaxp.validation.XSGrammarPoolContainer) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) Grammar(org.apache.xerces.xni.grammars.Grammar)

Example 7 with XSGrammar

use of org.apache.xerces.xni.grammars.XSGrammar in project iaf by ibissource.

the class JavaxValidationContext method createValidationContext.

@Override
public JavaxValidationContext createValidationContext(IPipeLineSession session, Set<List<String>> 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;
    init();
    schemasId = schemasProvider.getSchemasId();
    if (schemasId == null) {
        schemasId = schemasProvider.getSchemasId(session);
        getSchemaObject(schemasId, schemasProvider.getSchemas(session));
    }
    schema = javaxSchemas.get(schemasId);
    String mainFailureMessage = "Validation using " + schemasProvider.getClass().getSimpleName() + " with '" + schemasId + "' failed";
    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;
}
Also used : StringList(org.apache.xerces.xs.StringList) Schema(javax.xml.validation.Schema) Grammar(org.apache.xerces.xni.grammars.Grammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSGrammar(org.apache.xerces.xni.grammars.XSGrammar) XSModel(org.apache.xerces.xs.XSModel) HashSet(java.util.HashSet)

Aggregations

XSGrammar (org.apache.xerces.xni.grammars.XSGrammar)7 Grammar (org.apache.xerces.xni.grammars.Grammar)6 XMLGrammarPool (org.apache.xerces.xni.grammars.XMLGrammarPool)5 Schema (javax.xml.validation.Schema)4 InputStream (java.io.InputStream)3 StreamSource (javax.xml.transform.stream.StreamSource)3 SchemaFactory (javax.xml.validation.SchemaFactory)3 XSGrammarPoolContainer (org.apache.xerces.jaxp.validation.XSGrammarPoolContainer)3 ValidateXmlActionHandler (com.intellij.xml.actions.validate.ValidateXmlActionHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SAXParser (javax.xml.parsers.SAXParser)2 XmlFile (com.intellij.psi.xml.XmlFile)1 ErrorReporter (com.intellij.xml.actions.validate.ErrorReporter)1 TestErrorReporter (com.intellij.xml.actions.validate.TestErrorReporter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)1 XMLGrammarPreparser (org.apache.xerces.parsers.XMLGrammarPreparser)1 StringList (org.apache.xerces.xs.StringList)1 XSModel (org.apache.xerces.xs.XSModel)1