FileDocCategorySizeDatePackage
ExpatReader.javaAPI DocAndroid 1.5 API10514Wed May 06 22:41:06 BST 2009org.apache.harmony.xml

ExpatReader

public class ExpatReader extends Object implements XMLReader
SAX wrapper around Expat. Interns strings. Does not support validation. Does not support {@link DTDHandler}.

Fields Summary
private static final Logger
logger
ContentHandler
contentHandler
EntityResolver
entityResolver
ErrorHandler
errorHandler
LexicalHandler
lexicalHandler
private boolean
processNamespaces
private boolean
processNamespacePrefixes
private static final String
LEXICAL_HANDLER_PROPERTY
Constructors Summary
Methods Summary
public org.xml.sax.ContentHandlergetContentHandler()

        return this.contentHandler;
    
public org.xml.sax.DTDHandlergetDTDHandler()
Always returns null.

        return null;
    
public org.xml.sax.EntityResolvergetEntityResolver()

        return entityResolver;
    
public org.xml.sax.ErrorHandlergetErrorHandler()

        return errorHandler;
    
public booleangetFeature(java.lang.String name)

    

       
               
        if (name == null) {
            throw new NullPointerException("name");
        }

        if (name.equals(Feature.VALIDATION)) {
            return false;
        }

        if (name.equals(Feature.NAMESPACES)) {
            return processNamespaces;
        }

        if (name.equals(Feature.NAMESPACE_PREFIXES)) {
            return processNamespacePrefixes;
        }

        if (name.equals(Feature.STRING_INTERNING)) {
            return true;
        }

        throw new SAXNotRecognizedException(name);
    
public org.xml.sax.ext.LexicalHandlergetLexicalHandler()
Returns the current lexical handler.

return
the current lexical handler, or null if none has been registered
see
#setLexicalHandler

        return lexicalHandler;
    
public java.lang.ObjectgetProperty(java.lang.String name)

        if (name == null) {
            throw new NullPointerException("name");
        }

        if (name.equals(LEXICAL_HANDLER_PROPERTY)) {
            return lexicalHandler;
        }

        throw new SAXNotRecognizedException(name);
    
public booleanisNamespaceProcessingEnabled()
Returns true if this SAX parser processes namespaces.

see
#setNamespaceProcessingEnabled(boolean)

        return processNamespaces;
    
public voidparse(org.xml.sax.InputSource input)

        if (processNamespacePrefixes == processNamespaces) {
            /*
             * Expat has XML_SetReturnNSTriplet, but that still doesn't
             * include xmlns attributes like this feature requires. We may
             * 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 {
                // TODO: Don't eat original exception when close() throws.
                reader.close();
            }
            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 {
                // TODO: Don't eat original exception when close() throws.
                in.close();
            }
            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 {
            in.close();
        }
    
private voidparse(java.io.Reader in, java.lang.String publicId, java.lang.String systemId)

        ExpatParser parser = new ExpatParser(
                ExpatParser.CHARACTER_ENCODING,
                this,
                processNamespaces,
                publicId,
                systemId
        );
        parser.parseDocument(in);
    
private voidparse(java.io.InputStream in, java.lang.String encoding, java.lang.String publicId, java.lang.String systemId)

        ExpatParser parser = new ExpatParser(
                encoding,
                this,
                processNamespaces,
                publicId,
                systemId
        );
        parser.parseDocument(in);
    
public voidparse(java.lang.String systemId)

        parse(new InputSource(systemId));
    
public voidsetContentHandler(org.xml.sax.ContentHandler handler)

        this.contentHandler = handler;
    
public voidsetDTDHandler(org.xml.sax.DTDHandler ignored)
Not implemented.

        logger.warning("DTD handlers aren't supported.");
    
public voidsetEntityResolver(org.xml.sax.EntityResolver resolver)

        this.entityResolver = resolver;
    
public voidsetErrorHandler(org.xml.sax.ErrorHandler handler)

        this.errorHandler = handler;
    
public voidsetFeature(java.lang.String name, boolean value)

        if (name == null) {
            throw new NullPointerException("name");
        }

        if (name.equals(Feature.VALIDATION)) {
            if (value) {
                throw new SAXNotSupportedException("Cannot enable " + name);
            } else {
                // Default.
                return;
            }
        }

        if (name.equals(Feature.NAMESPACES)) {
            processNamespaces = value;
            return;
        }

        if (name.equals(Feature.NAMESPACE_PREFIXES)) {
            processNamespacePrefixes = value;
            return;
        }

        if (name.equals(Feature.STRING_INTERNING)) {
            if (value) {
                // Default.
                return;
            } else {
                throw new SAXNotSupportedException("Cannot disable " + name);
            }
        }

        throw new SAXNotRecognizedException(name);
    
public voidsetLexicalHandler(org.xml.sax.ext.LexicalHandler lexicalHandler)
Registers a lexical event handler. Supports neither {@link LexicalHandler#startEntity(String)} nor {@link LexicalHandler#endEntity(String)}.

If the application does not register a lexical handler, all lexical events reported by the SAX parser will be silently ignored.

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

param
lexicalHandler listens for lexical events
see
#getLexicalHandler()

        this.lexicalHandler = lexicalHandler;
    
public voidsetNamespaceProcessingEnabled(boolean processNamespaces)
Enables or disables namespace processing. Set to true by default. If you enable namespace processing, the parser will invoke {@link ContentHandler#startPrefixMapping(String, String)} and {@link ContentHandler#endPrefixMapping(String)}, and it will filter out namespace declarations from element attributes.

see
#isNamespaceProcessingEnabled()

        this.processNamespaces = processNamespaces;
    
public voidsetProperty(java.lang.String name, java.lang.Object value)

        if (name == null) {
            throw new NullPointerException("name");
        }

        if (name.equals(LEXICAL_HANDLER_PROPERTY)) {
            // The object must implement LexicalHandler
            if (value instanceof LexicalHandler) {
                this.lexicalHandler = (LexicalHandler) value;
                return;
            }
            throw new SAXNotSupportedException("value doesn't implement " +
                    "org.xml.sax.ext.LexicalHandler");
        }

        throw new SAXNotRecognizedException(name);