Java Code Examples for com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource#setEncoding()

The following examples show how to use com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource#setEncoding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityResolver2Wrapper.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 2
Source File: EntityResolver2Wrapper.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId, false);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 3
Source File: EntityResolver2Wrapper.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 4
Source File: EntityResolver2Wrapper.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 5
Source File: EntityResolver2Wrapper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 6
Source File: EntityResolver2Wrapper.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 7
Source File: EntityResolver2Wrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId, false);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 8
Source File: EntityResolver2Wrapper.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 9
Source File: EntityResolverWrapper.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 10
Source File: DOMEntityResolverWrapper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        description of the resource to be revsoved
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {
    // resolve entity using DOM entity resolver
    if (fEntityResolver != null) {
        // For entity resolution the type of the resource would be  XML TYPE
        // DOM L3 LS spec mention only the XML 1.0 recommendation right now
        LSInput inputSource =
            resourceIdentifier == null
                ? fEntityResolver.resolveResource(
                    null,
                    null,
                    null,
                    null,
                    null)
                : fEntityResolver.resolveResource(
                    getType(resourceIdentifier),
                    resourceIdentifier.getNamespace(),
                    resourceIdentifier.getPublicId(),
                    resourceIdentifier.getLiteralSystemId(),
                    resourceIdentifier.getBaseSystemId());
        if (inputSource != null) {
            String publicId = inputSource.getPublicId();
            String systemId = inputSource.getSystemId();
            String baseSystemId = inputSource.getBaseURI();
            InputStream byteStream = inputSource.getByteStream();
            Reader charStream = inputSource.getCharacterStream();
            String encoding = inputSource.getEncoding();
            String data = inputSource.getStringData();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId.
             */
            XMLInputSource xmlInputSource =
                new XMLInputSource(publicId, systemId, baseSystemId);

            if (charStream != null) {
                xmlInputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                xmlInputSource.setByteStream((InputStream) byteStream);
            }
            else if (data != null && data.length() != 0) {
                xmlInputSource.setCharacterStream(new StringReader(data));
            }
            xmlInputSource.setEncoding(encoding);
            return xmlInputSource;
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 11
Source File: EntityResolverWrapper.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 12
Source File: DOMEntityResolverWrapper.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        description of the resource to be revsoved
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {
    // resolve entity using DOM entity resolver
    if (fEntityResolver != null) {
        // For entity resolution the type of the resource would be  XML TYPE
        // DOM L3 LS spec mention only the XML 1.0 recommendation right now
        LSInput inputSource =
            resourceIdentifier == null
                ? fEntityResolver.resolveResource(
                    null,
                    null,
                    null,
                    null,
                    null)
                : fEntityResolver.resolveResource(
                    getType(resourceIdentifier),
                    resourceIdentifier.getNamespace(),
                    resourceIdentifier.getPublicId(),
                    resourceIdentifier.getLiteralSystemId(),
                    resourceIdentifier.getBaseSystemId());
        if (inputSource != null) {
            String publicId = inputSource.getPublicId();
            String systemId = inputSource.getSystemId();
            String baseSystemId = inputSource.getBaseURI();
            InputStream byteStream = inputSource.getByteStream();
            Reader charStream = inputSource.getCharacterStream();
            String encoding = inputSource.getEncoding();
            String data = inputSource.getStringData();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId.
             */
            XMLInputSource xmlInputSource =
                new XMLInputSource(publicId, systemId, baseSystemId);

            if (charStream != null) {
                xmlInputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                xmlInputSource.setByteStream((InputStream) byteStream);
            }
            else if (data != null && data.length() != 0) {
                xmlInputSource.setCharacterStream(new StringReader(data));
            }
            xmlInputSource.setEncoding(encoding);
            return xmlInputSource;
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 13
Source File: EntityResolverWrapper.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 14
Source File: DOMEntityResolverWrapper.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        description of the resource to be revsoved
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {
    // resolve entity using DOM entity resolver
    if (fEntityResolver != null) {
        // For entity resolution the type of the resource would be  XML TYPE
        // DOM L3 LS spec mention only the XML 1.0 recommendation right now
        LSInput inputSource =
            resourceIdentifier == null
                ? fEntityResolver.resolveResource(
                    null,
                    null,
                    null,
                    null,
                    null)
                : fEntityResolver.resolveResource(
                    getType(resourceIdentifier),
                    resourceIdentifier.getNamespace(),
                    resourceIdentifier.getPublicId(),
                    resourceIdentifier.getLiteralSystemId(),
                    resourceIdentifier.getBaseSystemId());
        if (inputSource != null) {
            String publicId = inputSource.getPublicId();
            String systemId = inputSource.getSystemId();
            String baseSystemId = inputSource.getBaseURI();
            InputStream byteStream = inputSource.getByteStream();
            Reader charStream = inputSource.getCharacterStream();
            String encoding = inputSource.getEncoding();
            String data = inputSource.getStringData();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId.
             */
            XMLInputSource xmlInputSource =
                new XMLInputSource(publicId, systemId, baseSystemId);

            if (charStream != null) {
                xmlInputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                xmlInputSource.setByteStream((InputStream) byteStream);
            }
            else if (data != null && data.length() != 0) {
                xmlInputSource.setCharacterStream(new StringReader(data));
            }
            xmlInputSource.setEncoding(encoding);
            return xmlInputSource;
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 15
Source File: DOMEntityResolverWrapper.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        description of the resource to be revsoved
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {
    // resolve entity using DOM entity resolver
    if (fEntityResolver != null) {
        // For entity resolution the type of the resource would be  XML TYPE
        // DOM L3 LS spec mention only the XML 1.0 recommendation right now
        LSInput inputSource =
            resourceIdentifier == null
                ? fEntityResolver.resolveResource(
                    null,
                    null,
                    null,
                    null,
                    null)
                : fEntityResolver.resolveResource(
                    getType(resourceIdentifier),
                    resourceIdentifier.getNamespace(),
                    resourceIdentifier.getPublicId(),
                    resourceIdentifier.getLiteralSystemId(),
                    resourceIdentifier.getBaseSystemId());
        if (inputSource != null) {
            String publicId = inputSource.getPublicId();
            String systemId = inputSource.getSystemId();
            String baseSystemId = inputSource.getBaseURI();
            InputStream byteStream = inputSource.getByteStream();
            Reader charStream = inputSource.getCharacterStream();
            String encoding = inputSource.getEncoding();
            String data = inputSource.getStringData();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId.
             */
            XMLInputSource xmlInputSource =
                new XMLInputSource(publicId, systemId, baseSystemId);

            if (charStream != null) {
                xmlInputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                xmlInputSource.setByteStream((InputStream) byteStream);
            }
            else if (data != null && data.length() != 0) {
                xmlInputSource.setCharacterStream(new StringReader(data));
            }
            xmlInputSource.setEncoding(encoding);
            return xmlInputSource;
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 16
Source File: EntityResolverWrapper.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 17
Source File: EntityResolverWrapper.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 18
Source File: DOMEntityResolverWrapper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        description of the resource to be revsoved
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {
    // resolve entity using DOM entity resolver
    if (fEntityResolver != null) {
        // For entity resolution the type of the resource would be  XML TYPE
        // DOM L3 LS spec mention only the XML 1.0 recommendation right now
        LSInput inputSource =
            resourceIdentifier == null
                ? fEntityResolver.resolveResource(
                    null,
                    null,
                    null,
                    null,
                    null)
                : fEntityResolver.resolveResource(
                    getType(resourceIdentifier),
                    resourceIdentifier.getNamespace(),
                    resourceIdentifier.getPublicId(),
                    resourceIdentifier.getLiteralSystemId(),
                    resourceIdentifier.getBaseSystemId());
        if (inputSource != null) {
            String publicId = inputSource.getPublicId();
            String systemId = inputSource.getSystemId();
            String baseSystemId = inputSource.getBaseURI();
            InputStream byteStream = inputSource.getByteStream();
            Reader charStream = inputSource.getCharacterStream();
            String encoding = inputSource.getEncoding();
            String data = inputSource.getStringData();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId.
             */
            XMLInputSource xmlInputSource =
                new XMLInputSource(publicId, systemId, baseSystemId);

            if (charStream != null) {
                xmlInputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                xmlInputSource.setByteStream((InputStream) byteStream);
            }
            else if (data != null && data.length() != 0) {
                xmlInputSource.setCharacterStream(new StringReader(data));
            }
            xmlInputSource.setEncoding(encoding);
            return xmlInputSource;
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 19
Source File: EntityResolverWrapper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}
 
Example 20
Source File: EntityResolverWrapper.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves an external parsed entity. If the entity cannot be
 * resolved, this method should return null.
 *
 * @param resourceIdentifier        contains the physical co-ordinates of the resource to be resolved
 *
 * @throws XNIException Thrown on general error.
 * @throws IOException  Thrown if resolved entity stream cannot be
 *                      opened or some other i/o error occurs.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
    throws XNIException, IOException {

    // When both pubId and sysId are null, the user's entity resolver
    // can do nothing about it. We'd better not bother calling it.
    // This happens when the resourceIdentifier is a GrammarDescription,
    // which describes a schema grammar of some namespace, but without
    // any schema location hint. -Sg
    String pubId = resourceIdentifier.getPublicId();
    String sysId = resourceIdentifier.getExpandedSystemId();
    if (pubId == null && sysId == null)
        return null;

    // resolve entity using SAX entity resolver
    if (fEntityResolver != null && resourceIdentifier != null) {
        try {
            InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = resourceIdentifier.getBaseSystemId();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);
                xmlInputSource.setByteStream(byteStream);
                xmlInputSource.setCharacterStream(charStream);
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // error resolving entity
        catch (SAXException e) {
            Exception ex = e.getException();
            if (ex == null) {
                ex = e;
            }
            throw new XNIException(ex);
        }
    }

    // unable to resolve entity
    return null;

}