Java Code Examples for org.xml.sax.InputSource#getCharacterStream()

The following examples show how to use org.xml.sax.InputSource#getCharacterStream() . 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: AbstractWrapperWSDLLocator.java    From cxf with Apache License 2.0 6 votes vote down vote up
public InputSource getImportInputSource(String parentLocation, String importLocation) {
    // Do a check on the scheme to see if it's anything that could be a security risk
    try {
        URI url = new URI(importLocation);
        if (!(url.getScheme() == null || ALLOWED_SCHEMES.contains(url.getScheme()))) {
            throw new IllegalArgumentException("The " + url.getScheme() + " URI scheme is not allowed");
        }
    } catch (URISyntaxException e) {
        // Just continue here as we might still be able to load it from the filesystem
    }

    InputSource src = parent.getImportInputSource(parentLocation, importLocation);
    lastImport = null;
    if (src == null || (src.getByteStream() == null && src.getCharacterStream() == null)) {
        src = getInputSource(parentLocation, importLocation);
        if (src != null) {
            lastImport = src.getSystemId();
        }
    }
    return src;
}
 
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: InputEntity.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void init(InputSource in, String name, InputEntity stack,
                 boolean isPE)
        throws IOException, SAXException {

    input = in;
    this.isPE = isPE;
    reader = in.getCharacterStream();

    if (reader == null) {
        InputStream bytes = in.getByteStream();

        if (bytes == null)
            reader = XmlReader.createReader(new URL(in.getSystemId())
                    .openStream());
        else if (in.getEncoding() != null)
            reader = XmlReader.createReader(in.getByteStream(),
                    in.getEncoding());
        else
            reader = XmlReader.createReader(in.getByteStream());
    }
    next = stack;
    buf = new char[BUFSIZ];
    this.name = name;
    checkRecursion(stack);
}
 
Example 4
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 5
Source File: XMLStreamReaderFactory.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static XMLStreamReader create(InputSource source, boolean rejectDTDs) {
    try {
        // Char stream available?
        if (source.getCharacterStream() != null) {
            return get().doCreate(source.getSystemId(), source.getCharacterStream(), rejectDTDs);
        }

        // Byte stream available?
        if (source.getByteStream() != null) {
            return get().doCreate(source.getSystemId(), source.getByteStream(), rejectDTDs);
        }

        // Otherwise, open URI
        return get().doCreate(source.getSystemId(), new URL(source.getSystemId()).openStream(),rejectDTDs);
    } catch (IOException e) {
        throw new XMLReaderException("stax.cantCreate",e);
    }
}
 
Example 6
Source File: InputEntity.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void init(InputSource in, String name, InputEntity stack,
                 boolean isPE)
        throws IOException, SAXException {

    input = in;
    this.isPE = isPE;
    reader = in.getCharacterStream();

    if (reader == null) {
        InputStream bytes = in.getByteStream();

        if (bytes == null)
            reader = XmlReader.createReader(new URL(in.getSystemId())
                    .openStream());
        else if (in.getEncoding() != null)
            reader = XmlReader.createReader(in.getByteStream(),
                    in.getEncoding());
        else
            reader = XmlReader.createReader(in.getByteStream());
    }
    next = stack;
    buf = new char[BUFSIZ];
    this.name = name;
    checkRecursion(stack);
}
 
Example 7
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 8
Source File: XMLStreamReaderFactory.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static XMLStreamReader create(InputSource source, boolean rejectDTDs) {
    try {
        // Char stream available?
        if (source.getCharacterStream() != null) {
            return get().doCreate(source.getSystemId(), source.getCharacterStream(), rejectDTDs);
        }

        // Byte stream available?
        if (source.getByteStream() != null) {
            return get().doCreate(source.getSystemId(), source.getByteStream(), rejectDTDs);
        }

        // Otherwise, open URI
        return get().doCreate(source.getSystemId(), new URL(source.getSystemId()).openStream(),rejectDTDs);
    } catch (IOException e) {
        throw new XMLReaderException("stax.cantCreate",e);
    }
}
 
Example 9
Source File: InputEntity.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void init(InputSource in, String name, InputEntity stack,
                 boolean isPE)
        throws IOException, SAXException {

    input = in;
    this.isPE = isPE;
    reader = in.getCharacterStream();

    if (reader == null) {
        InputStream bytes = in.getByteStream();

        if (bytes == null)
            if (Boolean.valueOf(System.getProperty("enableExternalEntityProcessing")))
                reader = XmlReader.createReader(new URL(in.getSystemId()).openStream());
            else
                fatal("P-082", new Object[] {in.getSystemId()});
        else if (in.getEncoding() != null)
            reader = XmlReader.createReader(in.getByteStream(), in.getEncoding());
        else
            reader = XmlReader.createReader(in.getByteStream());
    }
    next = stack;
    buf = new char[BUFSIZ];
    this.name = name;
    checkRecursion(stack);
}
 
Example 10
Source File: InputEntity.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void init(InputSource in, String name, InputEntity stack,
                 boolean isPE)
        throws IOException, SAXException {

    input = in;
    this.isPE = isPE;
    reader = in.getCharacterStream();

    if (reader == null) {
        InputStream bytes = in.getByteStream();

        if (bytes == null)
            reader = XmlReader.createReader(new URL(in.getSystemId())
                    .openStream());
        else if (in.getEncoding() != null)
            reader = XmlReader.createReader(in.getByteStream(),
                    in.getEncoding());
        else
            reader = XmlReader.createReader(in.getByteStream());
    }
    next = stack;
    buf = new char[BUFSIZ];
    this.name = name;
    checkRecursion(stack);
}
 
Example 11
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 12
Source File: XMLSchemaLoader.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static XMLInputSource saxToXMLInputSource(InputSource sis) {
    String publicId = sis.getPublicId();
    String systemId = sis.getSystemId();

    Reader charStream = sis.getCharacterStream();
    if (charStream != null) {
        return new XMLInputSource(publicId, systemId, null, charStream,
                null);
    }

    InputStream byteStream = sis.getByteStream();
    if (byteStream != null) {
        return new XMLInputSource(publicId, systemId, null, byteStream,
                sis.getEncoding());
    }

    return new XMLInputSource(publicId, systemId, null);
}
 
Example 13
Source File: XMLStreamReaderFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static XMLStreamReader create(InputSource source, boolean rejectDTDs) {
    try {
        // Char stream available?
        if (source.getCharacterStream() != null) {
            return get().doCreate(source.getSystemId(), source.getCharacterStream(), rejectDTDs);
        }

        // Byte stream available?
        if (source.getByteStream() != null) {
            return get().doCreate(source.getSystemId(), source.getByteStream(), rejectDTDs);
        }

        // Otherwise, open URI
        return get().doCreate(source.getSystemId(), new URL(source.getSystemId()).openStream(),rejectDTDs);
    } catch (IOException e) {
        throw new XMLReaderException("stax.cantCreate",e);
    }
}
 
Example 14
Source File: IncrementalSAXSource_Xerces.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean parseSomeSetup(InputSource source)
        throws SAXException, IOException, IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.InstantiationException
{
        if(fConfigSetInput!=null)
        {
                // Obtain input from SAX inputSource object, construct XNI version of
                // that object. Logic adapted from Xerces2.
                Object[] parms1={source.getPublicId(),source.getSystemId(),null};
                Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
                Object[] parmsa={source.getByteStream()};
                fConfigSetByteStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getCharacterStream();
                fConfigSetCharStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getEncoding();
                fConfigSetEncoding.invoke(xmlsource,parmsa);

                // Bugzilla5272 patch suggested by Sandy Gao.
                // Has to be reflection to run with Xerces2
                // after compilation against Xerces1. or vice
                // versa, due to return type mismatches.
                Object[] noparms=new Object[0];
                fReset.invoke(fIncrementalParser,noparms);

                parmsa[0]=xmlsource;
                fConfigSetInput.invoke(fPullParserConfig,parmsa);

                // %REVIEW% Do first pull. Should we instead just return true?
                return parseSome();
        }
        else
        {
                Object[] parm={source};
                Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
                return ((Boolean)ret).booleanValue();
        }
}
 
Example 15
Source File: IncrementalSAXSource_Xerces.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean parseSomeSetup(InputSource source)
        throws SAXException, IOException, IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.InstantiationException
{
        if(fConfigSetInput!=null)
        {
                // Obtain input from SAX inputSource object, construct XNI version of
                // that object. Logic adapted from Xerces2.
                Object[] parms1={source.getPublicId(),source.getSystemId(),null};
                Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
                Object[] parmsa={source.getByteStream()};
                fConfigSetByteStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getCharacterStream();
                fConfigSetCharStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getEncoding();
                fConfigSetEncoding.invoke(xmlsource,parmsa);

                // Bugzilla5272 patch suggested by Sandy Gao.
                // Has to be reflection to run with Xerces2
                // after compilation against Xerces1. or vice
                // versa, due to return type mismatches.
                Object[] noparms=new Object[0];
                fReset.invoke(fIncrementalParser,noparms);

                parmsa[0]=xmlsource;
                fConfigSetInput.invoke(fPullParserConfig,parmsa);

                // %REVIEW% Do first pull. Should we instead just return true?
                return parseSome();
        }
        else
        {
                Object[] parm={source};
                Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
                return ((Boolean)ret).booleanValue();
        }
}
 
Example 16
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 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: EntityResolverWrapper.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        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 19
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 20
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;

}