FileDocCategorySizeDatePackage
BridgeXmlBlockParser.javaAPI DocAndroid 5.1 API14484Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.android

BridgeXmlBlockParser

public class BridgeXmlBlockParser extends Object implements android.content.res.XmlResourceParser
{@link BridgeXmlBlockParser} reimplements most of android.xml.XmlBlock.Parser. It delegates to both an instance of {@link XmlPullParser} and an instance of XmlPullAttributes (for the {@link AttributeSet} part).

Fields Summary
private final XmlPullParser
mParser
private final android.util.BridgeXmlPullAttributes
mAttrib
private final BridgeContext
mContext
private final boolean
mPlatformFile
private boolean
mStarted
private int
mEventType
private boolean
mPopped
Constructors Summary
public BridgeXmlBlockParser(XmlPullParser parser, BridgeContext context, boolean platformFile)
Builds a {@link BridgeXmlBlockParser}.

param
parser The XmlPullParser to get the content from.
param
context the Context.
param
platformFile Indicates whether the the file is a platform file or not.

 // default to true in case it's not pushed.

                                       
           
        if (ParserFactory.LOG_PARSER) {
            System.out.println("CRTE " + parser.toString());
        }

        mParser = parser;
        mContext = context;
        mPlatformFile = platformFile;
        mAttrib = new BridgeXmlPullAttributes(parser, context, mPlatformFile);

        if (mContext != null) {
            mContext.pushParser(this);
            mPopped = false;
        }
    
Methods Summary
public voidclose()

        // pass
    
public voiddefineEntityReplacementText(java.lang.String entityName, java.lang.String replacementText)

        throw new XmlPullParserException(
                "defineEntityReplacementText() not supported");
    
public voidensurePopped()

        if (mContext != null && mPopped == false) {
            mContext.popParser();
            mPopped = true;
        }
    
public static java.lang.StringeventTypeToString(int eventType)

        switch (eventType) {
            case START_DOCUMENT:
                return "START_DOC";
            case END_DOCUMENT:
                return "END_DOC";
            case START_TAG:
                return "START_TAG";
            case END_TAG:
                return "END_TAG";
            case TEXT:
                return "TEXT";
            case CDSECT:
                return "CDSECT";
            case ENTITY_REF:
                return "ENTITY_REF";
            case IGNORABLE_WHITESPACE:
                return "IGNORABLE_WHITESPACE";
            case PROCESSING_INSTRUCTION:
                return "PROCESSING_INSTRUCTION";
            case COMMENT:
                return "COMMENT";
            case DOCDECL:
                return "DOCDECL";
        }

        return "????";
    
public booleangetAttributeBooleanValue(int index, boolean defaultValue)

        return mAttrib.getAttributeBooleanValue(index, defaultValue);
    
public booleangetAttributeBooleanValue(java.lang.String namespace, java.lang.String attribute, boolean defaultValue)

        return mAttrib.getAttributeBooleanValue(namespace, attribute, defaultValue);
    
public intgetAttributeCount()

        return mParser.getAttributeCount();
    
public floatgetAttributeFloatValue(int index, float defaultValue)

        return mAttrib.getAttributeFloatValue(index, defaultValue);
    
public floatgetAttributeFloatValue(java.lang.String namespace, java.lang.String attribute, float defaultValue)

        return mAttrib.getAttributeFloatValue(namespace, attribute, defaultValue);
    
public intgetAttributeIntValue(int index, int defaultValue)

        return mAttrib.getAttributeIntValue(index, defaultValue);
    
public intgetAttributeIntValue(java.lang.String namespace, java.lang.String attribute, int defaultValue)

        return mAttrib.getAttributeIntValue(namespace, attribute, defaultValue);
    
public intgetAttributeListValue(int index, java.lang.String[] options, int defaultValue)

        return mAttrib.getAttributeListValue(index, options, defaultValue);
    
public intgetAttributeListValue(java.lang.String namespace, java.lang.String attribute, java.lang.String[] options, int defaultValue)

        return mAttrib.getAttributeListValue(namespace, attribute, options, defaultValue);
    
public java.lang.StringgetAttributeName(int index)

        return mParser.getAttributeName(index);
    
public intgetAttributeNameResource(int index)

        return mAttrib.getAttributeNameResource(index);
    
public java.lang.StringgetAttributeNamespace(int index)

        return mParser.getAttributeNamespace(index);
    
public java.lang.StringgetAttributePrefix(int index)

        throw new RuntimeException("getAttributePrefix not supported");
    
public intgetAttributeResourceValue(int index, int defaultValue)

        return mAttrib.getAttributeResourceValue(index, defaultValue);
    
public intgetAttributeResourceValue(java.lang.String namespace, java.lang.String attribute, int defaultValue)

        return mAttrib.getAttributeResourceValue(namespace, attribute, defaultValue);
    
public java.lang.StringgetAttributeType(int index)

        return "CDATA";
    
public intgetAttributeUnsignedIntValue(int index, int defaultValue)

        return mAttrib.getAttributeUnsignedIntValue(index, defaultValue);
    
public intgetAttributeUnsignedIntValue(java.lang.String namespace, java.lang.String attribute, int defaultValue)

        return mAttrib.getAttributeUnsignedIntValue(namespace, attribute, defaultValue);
    
public java.lang.StringgetAttributeValue(int index)

        return mParser.getAttributeValue(index);
    
public java.lang.StringgetAttributeValue(java.lang.String namespace, java.lang.String name)

        return mParser.getAttributeValue(namespace, name);
    
public java.lang.StringgetClassAttribute()

        return mAttrib.getClassAttribute();
    
public intgetColumnNumber()

        return -1;
    
public intgetDepth()

        return mParser.getDepth();
    
public intgetEventType()

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

        if (FEATURE_PROCESS_NAMESPACES.equals(name)) {
            return true;
        }
        if (FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) {
            return true;
        }
        return false;
    
public java.lang.StringgetIdAttribute()

        return mAttrib.getIdAttribute();
    
public intgetIdAttributeResourceValue(int defaultValue)

        return mAttrib.getIdAttributeResourceValue(defaultValue);
    
public java.lang.StringgetInputEncoding()

        return null;
    
public intgetLineNumber()

        return mParser.getLineNumber();
    
public java.lang.StringgetName()

        return mParser.getName();
    
public java.lang.StringgetNamespace(java.lang.String prefix)

        throw new RuntimeException("getNamespace() not supported");
    
public java.lang.StringgetNamespace()

        return mParser.getNamespace();
    
public intgetNamespaceCount(int depth)

        throw new XmlPullParserException("getNamespaceCount() not supported");
    
public java.lang.StringgetNamespacePrefix(int pos)

        throw new XmlPullParserException("getNamespacePrefix() not supported");
    
public java.lang.StringgetNamespaceUri(int pos)

        throw new XmlPullParserException("getNamespaceUri() not supported");
    
public org.xmlpull.v1.XmlPullParsergetParser()

        return mParser;
    
public java.lang.StringgetPositionDescription()

        return "Binary XML file line #" + getLineNumber();
    
public java.lang.StringgetPrefix()

        throw new RuntimeException("getPrefix not supported");
    
public java.lang.ObjectgetProperty(java.lang.String name)

        return null;
    
public intgetStyleAttribute()

        return mAttrib.getStyleAttribute();
    
public java.lang.StringgetText()

        return mParser.getText();
    
public char[]getTextCharacters(int[] holderForStartAndLength)

        String txt = getText();
        char[] chars = null;
        if (txt != null) {
            holderForStartAndLength[0] = 0;
            holderForStartAndLength[1] = txt.length();
            chars = new char[txt.length()];
            txt.getChars(0, txt.length(), chars, 0);
        }
        return chars;
    
public java.lang.ObjectgetViewCookie()

        if (mParser instanceof ILayoutPullParser) {
            return ((ILayoutPullParser)mParser).getViewCookie();
        }

        return null;
    
public booleanisAttributeDefault(int index)

        return false;
    
public booleanisEmptyElementTag()

        // XXX Need to detect this.
        return false;
    
public booleanisPlatformFile()

        return mPlatformFile;
    
public booleanisWhitespace()

        // Original comment: whitespace was stripped by aapt.
        return mParser.isWhitespace();
    
public intnext()

        if (!mStarted) {
            mStarted = true;

            if (ParserFactory.LOG_PARSER) {
                System.out.println("STRT " + mParser.toString());
            }

            return START_DOCUMENT;
        }

        int ev = mParser.next();

        if (ParserFactory.LOG_PARSER) {
            System.out.println("NEXT " + mParser.toString() + " " +
                    eventTypeToString(mEventType) + " -> " + eventTypeToString(ev));
        }

        if (ev == END_TAG && mParser.getDepth() == 1) {
            // done with parser remove it from the context stack.
            ensurePopped();

            if (ParserFactory.LOG_PARSER) {
                System.out.println("");
            }
        }

        mEventType = ev;
        return ev;
    
public intnextTag()

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

        if (getEventType() != START_TAG) {
            throw new XmlPullParserException(getPositionDescription()
                    + ": parser must be on START_TAG to read next text", this,
                    null);
        }
        int eventType = next();
        if (eventType == TEXT) {
            String result = getText();
            eventType = next();
            if (eventType != END_TAG) {
                throw new XmlPullParserException(
                        getPositionDescription()
                                + ": event TEXT it must be immediately followed by END_TAG",
                        this, null);
            }
            return result;
        } else if (eventType == END_TAG) {
            return "";
        } else {
            throw new XmlPullParserException(getPositionDescription()
                    + ": parser must be on START_TAG or TEXT to read text",
                    this, null);
        }
    
public intnextToken()

        return next();
    
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 (FEATURE_PROCESS_NAMESPACES.equals(name) && state) {
            return;
        }
        if (FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name) && state) {
            return;
        }
        throw new XmlPullParserException("Unsupported feature: " + name);
    
public voidsetInput(java.io.Reader in)

        mParser.setInput(in);
    
public voidsetInput(java.io.InputStream inputStream, java.lang.String inputEncoding)

        mParser.setInput(inputStream, inputEncoding);
    
public voidsetProperty(java.lang.String name, java.lang.Object value)

        throw new XmlPullParserException("setProperty() not supported");