Example usage for org.w3c.dom.ls LSInput getSystemId

List of usage examples for org.w3c.dom.ls LSInput getSystemId

Introduction

In this page you can find the example usage for org.w3c.dom.ls LSInput getSystemId.

Prototype

public String getSystemId();

Source Link

Document

The system identifier, a URI reference [<a href='http://www.ietf.org/rfc/rfc2396.txt'>IETF RFC 2396</a>], for this input source.

Usage

From source file:org.apache.ode.utils.xsd.XSUtils.java

private static Map<URI, byte[]> captureSchema(LSInput input, XMLEntityResolver resolver) throws XsdException {
    if (__log.isDebugEnabled())
        __log.debug("captureSchema(LSInput,...): input.systemId=" + input.getSystemId());

    Map<URI, byte[]> captured = new HashMap<URI, byte[]>();

    if (resolver == null) {
        throw new IllegalStateException("no resolver set");
    }/*from   www .j  a v  a2  s.c  o  m*/

    CapturingXMLEntityResolver cr = new CapturingXMLEntityResolver(captured, resolver);

    XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
    schemaLoader.setEntityResolver(cr);
    schemaLoader.setFeature("http://apache.org/xml/features/honour-all-schemaLocations", true);

    LoggingXmlErrorHandler eh = new LoggingXmlErrorHandler(__log);
    schemaLoader.setErrorHandler(eh);

    XSModel model = schemaLoader.load(input);

    // The following mess is due to XMLSchemaLoaders funkyness in error
    // reporting: sometimes it throws an exception, sometime it returns
    // null, sometimes it just prints bs to the screen.
    if (model == null) {
        /*
        * Someone inside Xerces will have eaten this exception, for no good
        * reason.
        */
        List<XMLParseException> errors = eh.getErrors();
        if (errors.size() != 0) {
            __log.error("captureSchema: XMLParseException(s) in " + input);

            XsdException ex = null;
            for (XMLParseException xpe : errors) {
                ex = new XsdException(ex, xpe.getMessage(), xpe.getLineNumber(), xpe.getColumnNumber(),
                        xpe.getLiteralSystemId());
            }
            throw ex;
        }

        if (__log.isDebugEnabled())
            __log.debug("captureSchema: NULL model (unknown error) for " + input.getSystemId());
    }

    return captured;
}