Class MXParser

  • All Implemented Interfaces:
    org.xmlpull.v1.XmlPullParser

    public class MXParser
    extends java.lang.Object
    implements org.xmlpull.v1.XmlPullParser
    Absolutely minimal implementation of XMLPULL V1 API
    • Field Detail

      • FEATURE_XML_ROUNDTRIP

        private static final java.lang.String FEATURE_XML_ROUNDTRIP
        See Also:
        Constant Field Values
      • FEATURE_NAMES_INTERNED

        private static final java.lang.String FEATURE_NAMES_INTERNED
        See Also:
        Constant Field Values
      • PROPERTY_XMLDECL_VERSION

        private static final java.lang.String PROPERTY_XMLDECL_VERSION
        See Also:
        Constant Field Values
      • PROPERTY_XMLDECL_STANDALONE

        private static final java.lang.String PROPERTY_XMLDECL_STANDALONE
        See Also:
        Constant Field Values
      • PROPERTY_XMLDECL_CONTENT

        private static final java.lang.String PROPERTY_XMLDECL_CONTENT
        See Also:
        Constant Field Values
      • PROPERTY_LOCATION

        private static final java.lang.String PROPERTY_LOCATION
        See Also:
        Constant Field Values
      • allStringsInterned

        private boolean allStringsInterned
        Implementation notice: the is instance variable that controls if newString() is interning.

        NOTE: newStringIntern always returns interned strings and newString MAY return interned String depending on this variable.

        NOTE: by default in this minimal implementation it is false!

      • processNamespaces

        private boolean processNamespaces
      • roundtripSupported

        private boolean roundtripSupported
      • location

        private java.lang.String location
      • lineNumber

        private int lineNumber
      • columnNumber

        private int columnNumber
      • seenRoot

        private boolean seenRoot
      • reachedEnd

        private boolean reachedEnd
      • eventType

        private int eventType
      • emptyElementTag

        private boolean emptyElementTag
      • depth

        private int depth
      • elRawName

        private char[][] elRawName
      • elRawNameEnd

        private int[] elRawNameEnd
      • elRawNameLine

        private int[] elRawNameLine
      • elName

        private java.lang.String[] elName
      • elPrefix

        private java.lang.String[] elPrefix
      • elUri

        private java.lang.String[] elUri
      • elNamespaceCount

        private int[] elNamespaceCount
      • attributeCount

        private int attributeCount
      • attributeName

        private java.lang.String[] attributeName
      • attributeNameHash

        private int[] attributeNameHash
      • attributePrefix

        private java.lang.String[] attributePrefix
      • attributeUri

        private java.lang.String[] attributeUri
      • attributeValue

        private java.lang.String[] attributeValue
      • namespaceEnd

        private int namespaceEnd
      • namespacePrefix

        private java.lang.String[] namespacePrefix
      • namespacePrefixHash

        private int[] namespacePrefixHash
      • namespaceUri

        private java.lang.String[] namespaceUri
      • entityEnd

        private int entityEnd
      • entityName

        private java.lang.String[] entityName
      • entityNameBuf

        private char[][] entityNameBuf
      • entityReplacement

        private java.lang.String[] entityReplacement
      • entityReplacementBuf

        private char[][] entityReplacementBuf
      • entityNameHash

        private int[] entityNameHash
      • reader

        private java.io.Reader reader
      • inputEncoding

        private java.lang.String inputEncoding
      • bufLoadFactor

        private int bufLoadFactor
      • bufferLoadFactor

        private float bufferLoadFactor
      • buf

        private char[] buf
      • bufSoftLimit

        private int bufSoftLimit
      • preventBufferCompaction

        private boolean preventBufferCompaction
      • bufAbsoluteStart

        private int bufAbsoluteStart
      • bufStart

        private int bufStart
      • bufEnd

        private int bufEnd
      • pos

        private int pos
      • posStart

        private int posStart
      • posEnd

        private int posEnd
      • pc

        private char[] pc
      • pcStart

        private int pcStart
      • pcEnd

        private int pcEnd
      • usePC

        private boolean usePC
      • seenStartTag

        private boolean seenStartTag
      • seenEndTag

        private boolean seenEndTag
      • pastEndTag

        private boolean pastEndTag
      • seenAmpersand

        private boolean seenAmpersand
      • seenMarkup

        private boolean seenMarkup
      • seenDocdecl

        private boolean seenDocdecl
      • tokenize

        private boolean tokenize
      • text

        private java.lang.String text
      • entityRefName

        private java.lang.String entityRefName
      • xmlDeclVersion

        private java.lang.String xmlDeclVersion
      • xmlDeclStandalone

        private java.lang.Boolean xmlDeclStandalone
      • xmlDeclContent

        private java.lang.String xmlDeclContent
      • noUnicode4

        private static boolean noUnicode4
      • charRefOneCharBuf

        private char[] charRefOneCharBuf
      • VERSION

        private static final char[] VERSION
      • NCODING

        private static final char[] NCODING
      • TANDALONE

        private static final char[] TANDALONE
      • YES

        private static final char[] YES
      • NO

        private static final char[] NO
      • lookupNameStartChar

        private static boolean[] lookupNameStartChar
      • lookupNameChar

        private static boolean[] lookupNameChar
    • Constructor Detail

      • MXParser

        public MXParser()
    • Method Detail

      • resetStringCache

        private void resetStringCache()
      • newString

        private java.lang.String newString​(char[] cbuf,
                                           int off,
                                           int len)
      • newStringIntern

        private java.lang.String newStringIntern​(char[] cbuf,
                                                 int off,
                                                 int len)
      • ensureElementsCapacity

        private void ensureElementsCapacity()
        Make sure that we have enough space to keep element stack if passed size. It will always create one additional slot then current depth
      • ensureAttributesCapacity

        private void ensureAttributesCapacity​(int size)
        Make sure that in attributes temporary array is enough space.
      • ensureNamespacesCapacity

        private void ensureNamespacesCapacity​(int size)
      • fastHash

        private static final int fastHash​(char[] ch,
                                          int off,
                                          int len)
        simplistic implementation of hash function that has constant time to compute - so it also means diminishing hash quality for long strings but for XML parsing it should be good enough ...
      • ensureEntityCapacity

        private void ensureEntityCapacity()
      • reset

        private void reset()
      • setFeature

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

        public boolean getFeature​(java.lang.String name)
        Unknown properties are always returned as false
        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
      • getInputEncoding

        public java.lang.String getInputEncoding()
        Specified by:
        getInputEncoding in interface org.xmlpull.v1.XmlPullParser
      • 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
      • 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
      • 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
      • 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
      • getNamespace

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

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

        private static int findFragment​(int bufMinPos,
                                        char[] b,
                                        int start,
                                        int end)
      • getPositionDescription

        public java.lang.String getPositionDescription()
        Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.
        Specified by:
        getPositionDescription in interface org.xmlpull.v1.XmlPullParser
      • getLineNumber

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

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

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

        public java.lang.String getText()
        Specified by:
        getText 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
      • getPrefix

        public java.lang.String getPrefix()
        Specified by:
        getPrefix 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 org.xmlpull.v1.XmlPullParser
      • getAttributeNamespace

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

        public java.lang.String getAttributeName​(int index)
        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
      • 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
      • getAttributeValue

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

        public java.lang.String getAttributeValue​(java.lang.String namespace,
                                                  java.lang.String name)
        Specified by:
        getAttributeValue 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
      • 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
      • skipSubTree

        public void skipSubTree()
                         throws org.xmlpull.v1.XmlPullParserException,
                                java.io.IOException
        Skip sub tree that is currently parser positioned on.
        NOTE: parser must be on START_TAG and when function returns parser will be positioned on corresponding END_TAG
        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
      • 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
      • 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
      • nextImpl

        private int nextImpl()
                      throws org.xmlpull.v1.XmlPullParserException,
                             java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseProlog

        private int parseProlog()
                         throws org.xmlpull.v1.XmlPullParserException,
                                java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseEpilog

        private int parseEpilog()
                         throws org.xmlpull.v1.XmlPullParserException,
                                java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseEndTag

        public int parseEndTag()
                        throws org.xmlpull.v1.XmlPullParserException,
                               java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseStartTag

        public int parseStartTag()
                          throws org.xmlpull.v1.XmlPullParserException,
                                 java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseAttribute

        private char parseAttribute()
                             throws org.xmlpull.v1.XmlPullParserException,
                                    java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseEntityRef

        private char[] parseEntityRef()
                               throws org.xmlpull.v1.XmlPullParserException,
                                      java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • lookupEntityReplacement

        private char[] lookupEntityReplacement​(int entityNameLen)
      • parseComment

        private void parseComment()
                           throws org.xmlpull.v1.XmlPullParserException,
                                  java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parsePI

        private boolean parsePI()
                         throws org.xmlpull.v1.XmlPullParserException,
                                java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseXmlDecl

        private void parseXmlDecl​(char ch)
                           throws org.xmlpull.v1.XmlPullParserException,
                                  java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseXmlDeclWithVersion

        private void parseXmlDeclWithVersion​(int versionStart,
                                             int versionEnd)
                                      throws org.xmlpull.v1.XmlPullParserException,
                                             java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseDocdecl

        private void parseDocdecl()
                           throws org.xmlpull.v1.XmlPullParserException,
                                  java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • parseCDSect

        private void parseCDSect​(boolean hadCharData)
                          throws org.xmlpull.v1.XmlPullParserException,
                                 java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • fillBuf

        private void fillBuf()
                      throws java.io.IOException,
                             org.xmlpull.v1.XmlPullParserException
        Throws:
        java.io.IOException
        org.xmlpull.v1.XmlPullParserException
      • more

        private char more()
                   throws java.io.IOException,
                          org.xmlpull.v1.XmlPullParserException
        Throws:
        java.io.IOException
        org.xmlpull.v1.XmlPullParserException
      • ensurePC

        private void ensurePC​(int end)
      • joinPC

        private void joinPC()
      • requireInput

        private char requireInput​(char ch,
                                  char[] input)
                           throws org.xmlpull.v1.XmlPullParserException,
                                  java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • requireNextS

        private char requireNextS()
                           throws org.xmlpull.v1.XmlPullParserException,
                                  java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • skipS

        private char skipS​(char ch)
                    throws org.xmlpull.v1.XmlPullParserException,
                           java.io.IOException
        Throws:
        org.xmlpull.v1.XmlPullParserException
        java.io.IOException
      • setName

        private static final void setName​(char ch)
      • setNameStart

        private static final void setNameStart​(char ch)
      • isNameStartChar

        private boolean isNameStartChar​(char ch)
      • isNameChar

        private boolean isNameChar​(char ch)
      • isS

        private boolean isS​(char ch)
      • printable

        private java.lang.String printable​(char ch)
      • printable

        private java.lang.String printable​(java.lang.String s)