Code example for InputSource

Methods: getByteStream, getCharacterStream, getEncoding, getPublicId, getSystemId

0
             * have to implement namespace processing ourselves if we want 
             * this (not too difficult). We obviously "support" namespace 
             * prefixes if namespaces are disabled. 
             */ 
            throw new SAXNotSupportedException("The 'namespace-prefix' " +
                    "feature is not supported while the 'namespaces' " + 
                    "feature is enabled."); 
        } 
 
        // Try the character stream. 
        Reader reader = input.getCharacterStream();
        if (reader != null) {
            try { 
                parse(reader, input.getPublicId(), input.getSystemId());
            } finally { 
                IoUtils.closeQuietly(reader);
            } 
            return; 
        } 
 
        // Try the byte stream. 
        InputStream in = input.getByteStream();
        String encoding = input.getEncoding();
        if (in != null) {
            try { 
                parse(in, encoding, input.getPublicId(), input.getSystemId());
            } finally { 
                IoUtils.closeQuietly(in);
            } 
            return; 
        } 
 
        String systemId = input.getSystemId();
        if (systemId == null) {
            throw new SAXException("No input specified.");
        } 
 
        // Try the system id. 
        in = ExpatParser.openUrl(systemId);
        try { 
            parse(in, encoding, input.getPublicId(), systemId);
        } finally { 
            IoUtils.closeQuietly(in);
        } 
    } 
 
    private void parse(Reader in, String publicId, String systemId)
            throws IOException, SAXException { 
        ExpatParser parser = new ExpatParser(
                ExpatParser.CHARACTER_ENCODING, 
                this,
                processNamespaces,
                publicId,
                systemId
        ); 
        parser.parseDocument(in);
    } 
 
    private void parse(InputStream in, String charsetName, String publicId, String systemId)
            throws IOException, SAXException { 
        ExpatParser parser =
            new ExpatParser(charsetName, this, processNamespaces, publicId, systemId);
        parser.parseDocument(in);
    } 
 
    public void parse(String systemId) throws IOException, SAXException {
        parse(new InputSource(systemId));
    } 
}