Class XmlResourceParserImpl

  • All Implemented Interfaces:
    android.content.res.XmlResourceParser, android.util.AttributeSet, java.lang.AutoCloseable, org.xmlpull.v1.XmlPullParser

    public class XmlResourceParserImpl
    extends java.lang.Object
    implements android.content.res.XmlResourceParser
    Concrete implementation of the XmlResourceParser. Clients expects a pull parser while the resource loader initialise this object with a Document. This implementation navigates the dom and emulates a pull parser by raising all the opportune events. Note that the original android implementation is based on a set of native methods calls. Here those methods are re-implemented in java when possible.
    • Field Detail

      • AVAILABLE_FEATURES

        public static final java.lang.String[] AVAILABLE_FEATURES
        All the parser features currently supported by Android.
      • UNAVAILABLE_FEATURES

        public static final java.lang.String[] UNAVAILABLE_FEATURES
        All the parser features currently NOT supported by Android.
    • Constructor Detail

      • XmlResourceParserImpl

        @Deprecated
        public XmlResourceParserImpl​(org.w3c.dom.Document document,
                                     java.lang.String fileName,
                                     java.lang.String packageName,
                                     java.lang.String applicationPackageName,
                                     org.robolectric.res.ResourceTable resourceTable)
      • XmlResourceParserImpl

        public XmlResourceParserImpl​(org.w3c.dom.Document document,
                                     java.nio.file.Path fileName,
                                     java.lang.String packageName,
                                     java.lang.String applicationPackageName,
                                     org.robolectric.res.ResourceTable resourceTable)
    • Method Detail

      • setFeature

        public void setFeature​(java.lang.String name,
                               boolean state)
                        throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        setFeature in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getFeature

        public boolean getFeature​(java.lang.String name)
        Specified by:
        getFeature in interface org.xmlpull.v1.XmlPullParser
      • setProperty

        public void setProperty​(java.lang.String name,
                                java.lang.Object value)
                         throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        setProperty in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
        Specified by:
        getProperty in interface org.xmlpull.v1.XmlPullParser
      • setInput

        public void setInput​(java.io.Reader in)
                      throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        setInput in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • setInput

        public void setInput​(java.io.InputStream inputStream,
                             java.lang.String inputEncoding)
                      throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        setInput in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • defineEntityReplacementText

        public void defineEntityReplacementText​(java.lang.String entityName,
                                                java.lang.String replacementText)
                                         throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        defineEntityReplacementText in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getNamespacePrefix

        public java.lang.String getNamespacePrefix​(int pos)
                                            throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        getNamespacePrefix in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getInputEncoding

        public java.lang.String getInputEncoding()
        Specified by:
        getInputEncoding in interface org.xmlpull.v1.XmlPullParser
      • getNamespace

        public java.lang.String getNamespace​(java.lang.String prefix)
        Specified by:
        getNamespace in interface org.xmlpull.v1.XmlPullParser
      • getNamespaceCount

        public int getNamespaceCount​(int depth)
                              throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        getNamespaceCount in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getPositionDescription

        public java.lang.String getPositionDescription()
        Specified by:
        getPositionDescription in interface android.util.AttributeSet
        Specified by:
        getPositionDescription in interface org.xmlpull.v1.XmlPullParser
      • getNamespaceUri

        public java.lang.String getNamespaceUri​(int pos)
                                         throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        getNamespaceUri in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getColumnNumber

        public int getColumnNumber()
        Specified by:
        getColumnNumber in interface org.xmlpull.v1.XmlPullParser
      • getDepth

        public int getDepth()
        Specified by:
        getDepth in interface org.xmlpull.v1.XmlPullParser
      • getText

        public java.lang.String getText()
        Specified by:
        getText in interface org.xmlpull.v1.XmlPullParser
      • getLineNumber

        public int getLineNumber()
        Specified by:
        getLineNumber in interface org.xmlpull.v1.XmlPullParser
      • getEventType

        public int getEventType()
                         throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        getEventType in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • isWhitespace

        public boolean isWhitespace​(java.lang.String text)
                             throws org.xmlpull.v1.XmlPullParserException
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • isWhitespace

        public boolean isWhitespace()
                             throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        isWhitespace in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getPrefix

        public java.lang.String getPrefix()
        Specified by:
        getPrefix in interface org.xmlpull.v1.XmlPullParser
      • getTextCharacters

        public char[] getTextCharacters​(int[] holderForStartAndLength)
        Specified by:
        getTextCharacters in interface org.xmlpull.v1.XmlPullParser
      • getNamespace

        public java.lang.String getNamespace()
        Specified by:
        getNamespace in interface org.xmlpull.v1.XmlPullParser
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface org.xmlpull.v1.XmlPullParser
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String namespace,
                                             java.lang.String name)
      • getAttributeNamespace

        public java.lang.String getAttributeNamespace​(int index)
        Specified by:
        getAttributeNamespace in interface android.util.AttributeSet
        Specified by:
        getAttributeNamespace in interface org.xmlpull.v1.XmlPullParser
        Specified by:
        getAttributeNamespace in interface android.content.res.XmlResourceParser
      • getAttributeName

        public java.lang.String getAttributeName​(int index)
        Specified by:
        getAttributeName in interface android.util.AttributeSet
        Specified by:
        getAttributeName in interface org.xmlpull.v1.XmlPullParser
      • getAttributePrefix

        public java.lang.String getAttributePrefix​(int index)
        Specified by:
        getAttributePrefix in interface org.xmlpull.v1.XmlPullParser
      • isEmptyElementTag

        public boolean isEmptyElementTag()
                                  throws org.xmlpull.v1.XmlPullParserException
        Specified by:
        isEmptyElementTag in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
      • getAttributeCount

        public int getAttributeCount()
        Specified by:
        getAttributeCount in interface android.util.AttributeSet
        Specified by:
        getAttributeCount in interface org.xmlpull.v1.XmlPullParser
      • getAttributeValue

        public java.lang.String getAttributeValue​(int index)
        Specified by:
        getAttributeValue in interface android.util.AttributeSet
        Specified by:
        getAttributeValue in interface org.xmlpull.v1.XmlPullParser
      • qualify

        public java.lang.String qualify​(java.lang.String value)
      • getAttributeType

        public java.lang.String getAttributeType​(int index)
        Specified by:
        getAttributeType in interface org.xmlpull.v1.XmlPullParser
      • isAttributeDefault

        public boolean isAttributeDefault​(int index)
        Specified by:
        isAttributeDefault in interface org.xmlpull.v1.XmlPullParser
      • nextToken

        public int nextToken()
                      throws org.xmlpull.v1.XmlPullParserException,
                             java.io.IOException
        Specified by:
        nextToken in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • getAttributeValue

        public java.lang.String getAttributeValue​(java.lang.String namespace,
                                                  java.lang.String name)
        Specified by:
        getAttributeValue in interface android.util.AttributeSet
        Specified by:
        getAttributeValue in interface org.xmlpull.v1.XmlPullParser
      • next

        public int next()
                 throws org.xmlpull.v1.XmlPullParserException,
                        java.io.IOException
        Specified by:
        next in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • require

        public void require​(int type,
                            java.lang.String namespace,
                            java.lang.String name)
                     throws org.xmlpull.v1.XmlPullParserException,
                            java.io.IOException
        Specified by:
        require in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • nextText

        public java.lang.String nextText()
                                  throws org.xmlpull.v1.XmlPullParserException,
                                         java.io.IOException
        Specified by:
        nextText in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • nextTag

        public int nextTag()
                    throws org.xmlpull.v1.XmlPullParserException,
                           java.io.IOException
        Specified by:
        nextTag in interface org.xmlpull.v1.XmlPullParser
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • getAttributeNameResource

        public int getAttributeNameResource​(int index)
        Specified by:
        getAttributeNameResource in interface android.util.AttributeSet
      • getAttributeListValue

        public int getAttributeListValue​(java.lang.String namespace,
                                         java.lang.String attribute,
                                         java.lang.String[] options,
                                         int defaultValue)
        Specified by:
        getAttributeListValue in interface android.util.AttributeSet
      • getAttributeBooleanValue

        public boolean getAttributeBooleanValue​(java.lang.String namespace,
                                                java.lang.String attribute,
                                                boolean defaultValue)
        Specified by:
        getAttributeBooleanValue in interface android.util.AttributeSet
      • getAttributeResourceValue

        public int getAttributeResourceValue​(java.lang.String namespace,
                                             java.lang.String attribute,
                                             int defaultValue)
        Specified by:
        getAttributeResourceValue in interface android.util.AttributeSet
      • getAttributeIntValue

        public int getAttributeIntValue​(java.lang.String namespace,
                                        java.lang.String attribute,
                                        int defaultValue)
        Specified by:
        getAttributeIntValue in interface android.util.AttributeSet
      • getAttributeUnsignedIntValue

        public int getAttributeUnsignedIntValue​(java.lang.String namespace,
                                                java.lang.String attribute,
                                                int defaultValue)
        Specified by:
        getAttributeUnsignedIntValue in interface android.util.AttributeSet
      • getAttributeFloatValue

        public float getAttributeFloatValue​(java.lang.String namespace,
                                            java.lang.String attribute,
                                            float defaultValue)
        Specified by:
        getAttributeFloatValue in interface android.util.AttributeSet
      • getAttributeListValue

        public int getAttributeListValue​(int idx,
                                         java.lang.String[] options,
                                         int defaultValue)
        Specified by:
        getAttributeListValue in interface android.util.AttributeSet
      • getAttributeBooleanValue

        public boolean getAttributeBooleanValue​(int idx,
                                                boolean defaultValue)
        Specified by:
        getAttributeBooleanValue in interface android.util.AttributeSet
      • getAttributeResourceValue

        public int getAttributeResourceValue​(int idx,
                                             int defaultValue)
        Specified by:
        getAttributeResourceValue in interface android.util.AttributeSet
      • getAttributeIntValue

        public int getAttributeIntValue​(int idx,
                                        int defaultValue)
        Specified by:
        getAttributeIntValue in interface android.util.AttributeSet
      • getAttributeUnsignedIntValue

        public int getAttributeUnsignedIntValue​(int idx,
                                                int defaultValue)
        Specified by:
        getAttributeUnsignedIntValue in interface android.util.AttributeSet
      • getAttributeFloatValue

        public float getAttributeFloatValue​(int idx,
                                            float defaultValue)
        Specified by:
        getAttributeFloatValue in interface android.util.AttributeSet
      • getIdAttribute

        public java.lang.String getIdAttribute()
        Specified by:
        getIdAttribute in interface android.util.AttributeSet
      • getClassAttribute

        public java.lang.String getClassAttribute()
        Specified by:
        getClassAttribute in interface android.util.AttributeSet
      • getIdAttributeResourceValue

        public int getIdAttributeResourceValue​(int defaultValue)
        Specified by:
        getIdAttributeResourceValue in interface android.util.AttributeSet
      • getStyleAttribute

        public int getStyleAttribute()
        Specified by:
        getStyleAttribute in interface android.util.AttributeSet
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface android.content.res.XmlResourceParser
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable