Search in sources :

Example 1 with DOMInputSource

use of org.apache.xerces.util.DOMInputSource in project iaf by ibissource.

the class XMLSchemaFactory method newSchema.

public Schema newSchema(Source[] schemas) throws SAXException {
    // this will let the loader store parsed Grammars into the pool.
    XMLGrammarPoolImplExtension pool = new XMLGrammarPoolImplExtension();
    fXMLGrammarPoolWrapper.setGrammarPool(pool);
    XMLInputSource[] xmlInputSources = new XMLInputSource[schemas.length];
    InputStream inputStream;
    Reader reader;
    for (int i = 0; i < schemas.length; ++i) {
        Source source = schemas[i];
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            String publicId = streamSource.getPublicId();
            String systemId = streamSource.getSystemId();
            inputStream = streamSource.getInputStream();
            reader = streamSource.getReader();
            XMLInputSource xmlInputSource = new XMLInputSource(publicId, systemId, null);
            xmlInputSource.setByteStream(inputStream);
            xmlInputSource.setCharacterStream(reader);
            xmlInputSources[i] = xmlInputSource;
        } else if (source instanceof SAXSource) {
            SAXSource saxSource = (SAXSource) source;
            InputSource inputSource = saxSource.getInputSource();
            if (inputSource == null) {
                throw new SAXException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "SAXSourceNullInputSource", null));
            }
            xmlInputSources[i] = new SAXInputSource(saxSource.getXMLReader(), inputSource);
        } else if (source instanceof DOMSource) {
            DOMSource domSource = (DOMSource) source;
            Node node = domSource.getNode();
            String systemID = domSource.getSystemId();
            xmlInputSources[i] = new DOMInputSource(node, systemID);
        } else // }
        if (source == null) {
            throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "SchemaSourceArrayMemberNull", null));
        } else {
            throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "SchemaFactorySourceUnrecognized", new Object[] { source.getClass().getName() }));
        }
    }
    try {
        fXMLSchemaLoader.loadGrammar(xmlInputSources);
    } catch (XNIException e) {
        // this should have been reported to users already.
        throw Util.toSAXException(e);
    } catch (IOException e) {
        // this hasn't been reported, so do so now.
        SAXParseException se = new SAXParseException(e.getMessage(), null, e);
        if (fErrorHandler != null) {
            fErrorHandler.error(se);
        }
        // and we must throw it.
        throw se;
    }
    // Clear reference to grammar pool.
    fXMLGrammarPoolWrapper.setGrammarPool(null);
    // Select Schema implementation based on grammar count.
    final int grammarCount = pool.getGrammarCount();
    AbstractXMLSchema schema = null;
    if (fUseGrammarPoolOnly) {
        throw new NotImplementedException("fUseGrammarPoolOnly");
    // if (grammarCount > 1) {
    // schema = new XMLSchemaHack(new ReadOnlyGrammarPool(pool));
    // }
    // else if (grammarCount == 1) {
    // Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
    // schema = new XMLSchemaHack(grammars[0]);
    // }
    // else {
    // schema = new XMLSchemaHack();
    // }
    } else {
        schema = new XMLSchema(new ReadOnlyGrammarPool(pool), false);
    }
    propagateFeatures(schema);
    return schema;
}
Also used : InputSource(org.xml.sax.InputSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) DOMInputSource(org.apache.xerces.util.DOMInputSource) SAXInputSource(org.apache.xerces.util.SAXInputSource) DOMSource(javax.xml.transform.dom.DOMSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) Node(org.w3c.dom.Node) NotImplementedException(org.apache.commons.lang.NotImplementedException) XMLEventReader(javax.xml.stream.XMLEventReader) Reader(java.io.Reader) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) DOMInputSource(org.apache.xerces.util.DOMInputSource) SAXSource(javax.xml.transform.sax.SAXSource) StAXSource(javax.xml.transform.stax.StAXSource) SAXInputSource(org.apache.xerces.util.SAXInputSource) XNIException(org.apache.xerces.xni.XNIException) SAXException(org.xml.sax.SAXException) SAXParseException(org.xml.sax.SAXParseException) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) DOMInputSource(org.apache.xerces.util.DOMInputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXInputSource(org.apache.xerces.util.SAXInputSource)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 SAXSource (javax.xml.transform.sax.SAXSource)1 StAXSource (javax.xml.transform.stax.StAXSource)1 StreamSource (javax.xml.transform.stream.StreamSource)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 DOMInputSource (org.apache.xerces.util.DOMInputSource)1 SAXInputSource (org.apache.xerces.util.SAXInputSource)1 XNIException (org.apache.xerces.xni.XNIException)1 XMLInputSource (org.apache.xerces.xni.parser.XMLInputSource)1 Node (org.w3c.dom.Node)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1