Class MXParser

java.lang.Object
io.github.xstream.mxparser.MXParser
All Implemented Interfaces:
org.xmlpull.v1.XmlPullParser

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

    • XML_URI

      private static final String XML_URI
      See Also:
    • XMLNS_URI

      private static final String XMLNS_URI
      See Also:
    • FEATURE_XML_ROUNDTRIP

      private static final String FEATURE_XML_ROUNDTRIP
      See Also:
    • FEATURE_NAMES_INTERNED

      private static final String FEATURE_NAMES_INTERNED
      See Also:
    • PROPERTY_XMLDECL_VERSION

      private static final String PROPERTY_XMLDECL_VERSION
      See Also:
    • PROPERTY_XMLDECL_STANDALONE

      private static final String PROPERTY_XMLDECL_STANDALONE
      See Also:
    • PROPERTY_XMLDECL_CONTENT

      private static final String PROPERTY_XMLDECL_CONTENT
      See Also:
    • PROPERTY_LOCATION

      private static final String PROPERTY_LOCATION
      See Also:
    • 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!

    • TRACE_SIZING

      private static final boolean TRACE_SIZING
      See Also:
    • processNamespaces

      private boolean processNamespaces
    • roundtripSupported

      private boolean roundtripSupported
    • location

      private 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 String[] elName
    • elPrefix

      private String[] elPrefix
    • elUri

      private String[] elUri
    • elNamespaceCount

      private int[] elNamespaceCount
    • attributeCount

      private int attributeCount
    • attributeName

      private String[] attributeName
    • attributeNameHash

      private int[] attributeNameHash
    • attributePrefix

      private String[] attributePrefix
    • attributeUri

      private String[] attributeUri
    • attributeValue

      private String[] attributeValue
    • namespaceEnd

      private int namespaceEnd
    • namespacePrefix

      private String[] namespacePrefix
    • namespacePrefixHash

      private int[] namespacePrefixHash
    • namespaceUri

      private String[] namespaceUri
    • entityEnd

      private int entityEnd
    • entityName

      private String[] entityName
    • entityNameBuf

      private char[][] entityNameBuf
    • entityReplacement

      private String[] entityReplacement
    • entityReplacementBuf

      private char[][] entityReplacementBuf
    • entityNameHash

      private int[] entityNameHash
    • READ_CHUNK_SIZE

      private static final int READ_CHUNK_SIZE
      See Also:
    • reader

      private Reader reader
    • inputEncoding

      private 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 String text
    • entityRefName

      private String entityRefName
    • xmlDeclVersion

      private String xmlDeclVersion
    • xmlDeclStandalone

      private Boolean xmlDeclStandalone
    • xmlDeclContent

      private 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
    • LOOKUP_MAX

      private static final int LOOKUP_MAX
      See Also:
    • LOOKUP_MAX_CHAR

      private static final char LOOKUP_MAX_CHAR
      See Also:
    • lookupNameStartChar

      private static boolean[] lookupNameStartChar
    • lookupNameChar

      private static boolean[] lookupNameChar
  • Constructor Details

    • MXParser

      public MXParser()
  • Method Details

    • resetStringCache

      private void resetStringCache()
    • newString

      private String newString(char[] cbuf, int off, int len)
    • newStringIntern

      private 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(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(String name)
      Unknown properties are always returned as false
      Specified by:
      getFeature in interface org.xmlpull.v1.XmlPullParser
    • setProperty

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

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

      public void setInput(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(InputStream inputStream, String inputEncoding) throws org.xmlpull.v1.XmlPullParserException
      Specified by:
      setInput in interface org.xmlpull.v1.XmlPullParser
      Throws:
      org.xmlpull.v1.XmlPullParserException
    • getInputEncoding

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

      public void defineEntityReplacementText(String entityName, 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 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 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 String getNamespace(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 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 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 String getNamespace()
      Specified by:
      getNamespace in interface org.xmlpull.v1.XmlPullParser
    • getName

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

      public 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 String getAttributeNamespace(int index)
      Specified by:
      getAttributeNamespace in interface org.xmlpull.v1.XmlPullParser
    • getAttributeName

      public String getAttributeName(int index)
      Specified by:
      getAttributeName in interface org.xmlpull.v1.XmlPullParser
    • getAttributePrefix

      public String getAttributePrefix(int index)
      Specified by:
      getAttributePrefix in interface org.xmlpull.v1.XmlPullParser
    • getAttributeType

      public 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 String getAttributeValue(int index)
      Specified by:
      getAttributeValue in interface org.xmlpull.v1.XmlPullParser
    • getAttributeValue

      public String getAttributeValue(String namespace, 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, String namespace, String name) throws org.xmlpull.v1.XmlPullParserException, IOException
      Specified by:
      require in interface org.xmlpull.v1.XmlPullParser
      Throws:
      org.xmlpull.v1.XmlPullParserException
      IOException
    • skipSubTree

      public void skipSubTree() throws org.xmlpull.v1.XmlPullParserException, 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
      IOException
    • nextText

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

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

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

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

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

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

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

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

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

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

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

      private char[] lookupEntityReplacement(int entityNameLen)
    • parseComment

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

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

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

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

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

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

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

      private char more() throws IOException, org.xmlpull.v1.XmlPullParserException
      Throws:
      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, IOException
      Throws:
      org.xmlpull.v1.XmlPullParserException
      IOException
    • requireNextS

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

      private char skipS(char ch) throws org.xmlpull.v1.XmlPullParserException, IOException
      Throws:
      org.xmlpull.v1.XmlPullParserException
      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 String printable(char ch)
    • printable

      private String printable(String s)