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

ExpatPullParser

public class ExpatPullParser extends Object implements XmlPullParser
Fast, partial XmlPullParser implementation based upon Expat. Does not support validation or {@code DOCTYPE} processing.

Fields Summary
public static final String
FEATURE_RELAXED
This feature is identified by http://xmlpull.org/v1/doc/features.html#relaxed If this feature is supported that means that XmlPull parser will be lenient when checking XML well formedness. NOTE: use it only if XML input is not well-formed and in general usage if this feature is discouraged NOTE: as there is no definition of what is relaxed XML parsing therefore what parser will do completely depends on implementation used
private static final int
BUFFER_SIZE
private static final String
NOT_A_START_TAG
private Document
document
private boolean
processNamespaces
private boolean
relaxed
Constructors Summary
Methods Summary
public voiddefineEntityReplacementText(java.lang.String entityName, java.lang.String replacementText)
Not supported.

throws
UnsupportedOperationException always

        throw new UnsupportedOperationException();
    
public intgetAttributeCount()

        return this.document.currentEvent.getAttributeCount();
    
public java.lang.StringgetAttributeName(int index)

        return this.document.currentEvent.getAttributeName(index);
    
public java.lang.StringgetAttributeNamespace(int index)

        return this.document.currentEvent.getAttributeNamespace(index);
    
public java.lang.StringgetAttributePrefix(int index)
Not supported.

throws
UnsupportedOperationException always

        throw new UnsupportedOperationException();
    
public java.lang.StringgetAttributeType(int index)

        return "CDATA";
    
public java.lang.StringgetAttributeValue(int index)

        return this.document.currentEvent.getAttributeValue(index);
    
public java.lang.StringgetAttributeValue(java.lang.String namespace, java.lang.String name)

        return this.document.currentEvent.getAttributeValue(namespace, name);
    
public intgetColumnNumber()
Not supported.

return
{@literal -1} always

        // We would have to record the column number in each event.
        return -1;
    
public intgetDepth()

        return this.document.getDepth();
    
public intgetEventType()

        return this.document.currentEvent.getType();
    
public booleangetFeature(java.lang.String name)

        if (name == null) {
            // Required by API.
            throw new IllegalArgumentException("Null feature name");
        }

        // We always support namespaces, but no other features.
        return name.equals(FEATURE_PROCESS_NAMESPACES) && processNamespaces;
    
public java.lang.StringgetInputEncoding()

        return this.document.getEncoding();
    
public intgetLineNumber()
Not supported.

return
{@literal -1} always

        // We would have to record the line number in each event.
        return -1;
    
public java.lang.StringgetName()

        return this.document.currentEvent.getName();
    
public java.lang.StringgetNamespace(java.lang.String prefix)

        // In XmlPullParser API, null == default namespace.
        if (prefix == null) {
            // Internally, we use empty string instead of null.
            prefix = "";
        }

        return document.currentEvent.namespaceStack.uriFor(prefix);
    
public java.lang.StringgetNamespace()

        return this.document.currentEvent.getNamespace();
    
public intgetNamespaceCount(int depth)

        return document.currentEvent.namespaceStack.countAt(depth);
    
public java.lang.StringgetNamespacePrefix(int pos)

        String prefix = document.currentEvent.namespaceStack.prefixAt(pos);
        @SuppressWarnings("StringEquality")
        boolean hasPrefix = prefix != "";
        return hasPrefix ? prefix : null;
    
public java.lang.StringgetNamespaceUri(int pos)

        return document.currentEvent.namespaceStack.uriAt(pos);
    
public java.lang.StringgetPositionDescription()

        return "line " + getLineNumber() + ", column " + getColumnNumber();
    
public java.lang.StringgetPrefix()
Not supported.

throws
UnsupportedOperationException always

        throw new UnsupportedOperationException();
    
public java.lang.ObjectgetProperty(java.lang.String name)

        return null;
    
public java.lang.StringgetText()

        final StringBuilder builder = this.document.currentEvent.getText();
        return builder == null ? null : builder.toString();
    
public char[]getTextCharacters(int[] holderForStartAndLength)

        final StringBuilder builder = this.document.currentEvent.getText();

        final int length = builder.length();
        char[] characters = new char[length];
        builder.getChars(0, length, characters, 0);

        holderForStartAndLength[0] = 0;
        holderForStartAndLength[1] = length;

        return characters;
    
public booleanisAttributeDefault(int index)

        return false;
    
public booleanisEmptyElementTag()

        return this.document.isCurrentElementEmpty();
    
public booleanisNamespaceProcessingEnabled()
Returns true if this parser processes namespaces.

see
#setNamespaceProcessingEnabled(boolean)

        return processNamespaces;
    
public booleanisWhitespace()

        if (getEventType() != TEXT) {
            throw new XmlPullParserException("Not on text.");
        }

        String text = getText();

        if (text.length() == 0) {
            return true;
        }

        int length = text.length();
        for (int i = 0; i < length; i++) {
            if (!Character.isWhitespace(text.charAt(i))) {
                return false;
            }
        }

        return true;
    
public intnext()

        return this.document.dequeue();
    
public intnextTag()

        int eventType = next();
        if (eventType == TEXT && isWhitespace()) {
            eventType = next();
        }
        if (eventType != START_TAG && eventType != END_TAG) {
            throw new XmlPullParserException(
                "Expected start or end tag", this, null);
        }
        return eventType;
    
public java.lang.StringnextText()

        if (this.document.currentEvent.getType() != START_TAG)
            throw new XmlPullParserException("Not on start tag.");

        int next = this.document.dequeue();
        switch (next) {
            case TEXT: return getText();
            case END_TAG: return "";
            default: throw new XmlPullParserException(
                "Unexpected event type: " + TYPES[next]);
        }
    
public intnextToken()
Not supported.

throws
UnsupportedOperationException always

        throw new UnsupportedOperationException();
    
public voidrequire(int type, java.lang.String namespace, java.lang.String name)

        if (type != getEventType()
                || (namespace != null && !namespace.equals(getNamespace()))
                || (name != null && !name.equals(getName()))) {
            throw new XmlPullParserException("expected "
                    + TYPES[type] + getPositionDescription());
        }
    
public voidsetFeature(java.lang.String name, boolean state)


         
              
        if (name == null) {
            // Required by API.          
            throw new IllegalArgumentException("Null feature name");
        }

        if (name.equals(FEATURE_PROCESS_NAMESPACES)) {
            processNamespaces = state;
            return;
        }

        if (name.equals(FEATURE_RELAXED)) {
            relaxed = true;
            return;
        }

        // You're free to turn these features off because we don't support them.
        if (!state && (name.equals(FEATURE_REPORT_NAMESPACE_ATTRIBUTES)
                || name.equals(FEATURE_PROCESS_DOCDECL)
                || name.equals(FEATURE_VALIDATION))) {
            return;
        }

        throw new XmlPullParserException("Unsupported feature: " + name);
    
public voidsetInput(java.io.Reader in)

        this.document = new CharDocument(in, processNamespaces);
    
public voidsetInput(java.io.InputStream in, java.lang.String encodingName)

        this.document = new ByteDocument(in, encodingName, processNamespaces);
    
public voidsetNamespaceProcessingEnabled(boolean processNamespaces)
Enables or disables namespace processing. Set to false by default.

see
#isNamespaceProcessingEnabled()

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

        if (name == null) {
            // Required by API.
            throw new IllegalArgumentException("Null feature name");
        }

        // We don't support any properties.
        throw new XmlPullParserException("Properties aren't supported.");