FileDocCategorySizeDatePackage
UiElementPullParser.javaAPI DocAndroid 1.5 API6990Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.layout

UiElementPullParser

public final class UiElementPullParser extends BasePullParser
{@link IXmlPullParser} implementation on top of {@link UiElementNode}.

It's designed to work on layout files, and will most likely not work on other resource files.

Fields Summary
private final ArrayList
mNodeStack
private com.android.ide.eclipse.editors.uimodel.UiElementNode
mRoot
Constructors Summary
public UiElementPullParser(com.android.ide.eclipse.editors.uimodel.UiElementNode top)

    
       
        super();
        mRoot = top;
        push(mRoot);
    
Methods Summary
private org.w3c.dom.NodegetAttribute(int i)

        if (mParsingState != START_TAG) {
            throw new IndexOutOfBoundsException();
        }

        // get the current uiNode
        UiElementNode uiNode = getCurrentNode();
        
        // get its xml node
        Node xmlNode = uiNode.getXmlNode();

        if (xmlNode != null) {
            return xmlNode.getAttributes().item(i);
        }

        return null;
    
public intgetAttributeCount()

        UiElementNode node = getCurrentNode();
        if (node != null) {
            return node.getUiAttributes().size();
        }

        return 0;
    
public java.lang.StringgetAttributeName(int i)

        Node attribute = getAttribute(i);
        if (attribute != null) {
            return attribute.getLocalName();
        }

        return null;
    
public java.lang.StringgetAttributeNamespace(int i)

        Node attribute = getAttribute(i);
        if (attribute != null) {
            return attribute.getNamespaceURI();
        }
        return ""; //$NON-NLS-1$
    
public java.lang.StringgetAttributePrefix(int i)

        Node attribute = getAttribute(i);
        if (attribute != null) {
            return attribute.getPrefix();
        }
        return null;
    
public java.lang.StringgetAttributeValue(int i)

        Node attribute = getAttribute(i);
        if (attribute != null) {
            return attribute.getNodeValue();
        }
        
        return null;
    
public java.lang.StringgetAttributeValue(java.lang.String namespace, java.lang.String localName)

        // get the current uiNode
        UiElementNode uiNode = getCurrentNode();
        
        // get its xml node
        Node xmlNode = uiNode.getXmlNode();
        
        if (xmlNode != null) {
            Node attribute = xmlNode.getAttributes().getNamedItemNS(namespace, localName);
            if (attribute != null) {
                return attribute.getNodeValue();
            }
        }

        return null;
    
private com.android.ide.eclipse.editors.uimodel.UiElementNodegetCurrentNode()

        if (mNodeStack.size() > 0) {
            return mNodeStack.get(mNodeStack.size()-1);
        }
        
        return null;
    
public intgetDepth()

        return mNodeStack.size();
    
public java.lang.StringgetName()

        if (mParsingState == START_TAG || mParsingState == END_TAG) {
            return getCurrentNode().getDescriptor().getXmlLocalName();
        }

        return null;
    
public java.lang.StringgetNamespace()

        if (mParsingState == START_TAG || mParsingState == END_TAG) {
            return getCurrentNode().getDescriptor().getNamespace();
        }

        return null;
    
public java.lang.StringgetPositionDescription()

        return "XML DOM element depth:" + mNodeStack.size();
    
public java.lang.StringgetPrefix()

        if (mParsingState == START_TAG || mParsingState == END_TAG) {
            // FIXME will NEVER work
            if (getCurrentNode().getDescriptor().getXmlLocalName().startsWith("android:")) { //$NON-NLS-1$
                return "android"; //$NON-NLS-1$
            }
        }

        return null;
    
public java.lang.ObjectgetViewKey()
{@inheritDoc} This implementation returns the underlying DOM node.

        return getCurrentNode();
    
public booleanisEmptyElementTag()

        if (mParsingState == START_TAG) {
            return getCurrentNode().getUiChildren().size() == 0;
        }
        
        throw new XmlPullParserException("Call to isEmptyElementTag while not in START_TAG",
                this, null);
    
public voidonNextFromEndTag()

        // look for a sibling. if no sibling, go back to the parent
        UiElementNode node = getCurrentNode();
        node = node.getUiNextSibling();
        if (node != null) {
            // to go to the sibling, we need to remove the current node,
            pop();
            // and add its sibling.
            push(node);
            mParsingState = START_TAG;
        } else {
            // move back to the parent
            pop();
            
            // we have only one element left (mRoot), then we're done with the document.
            if (mNodeStack.size() == 1) {
                mParsingState = END_DOCUMENT;
            } else {
                mParsingState = END_TAG;
            }
        }
    
public voidonNextFromStartDocument()

        onNextFromStartTag();
    
public voidonNextFromStartTag()

        // get the current node, and look for text or children (children first)
        UiElementNode node = getCurrentNode();
        List<UiElementNode> children = node.getUiChildren();
        if (children.size() > 0) {
            // move to the new child, and don't change the state.
            push(children.get(0));
            
            // in case the current state is CURRENT_DOC, we set the proper state.
            mParsingState = START_TAG;
        } else {
            if (mParsingState == START_DOCUMENT) {
                // this handles the case where there's no node.
                mParsingState = END_DOCUMENT;
            } else {
                mParsingState = END_TAG;
            }
        }
    
private com.android.ide.eclipse.editors.uimodel.UiElementNodepop()

        return mNodeStack.remove(mNodeStack.size()-1);
    
private voidpush(com.android.ide.eclipse.editors.uimodel.UiElementNode node)

        mNodeStack.add(node);