Package io.github.xstream.mxparser
Class MXParser
java.lang.Object
io.github.xstream.mxparser.MXParser
- All Implemented Interfaces:
org.xmlpull.v1.XmlPullParser
Absolutely minimal implementation of XMLPULL V1 API
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanImplementation notice: the is instance variable that controls if newString() is interning.private intprivate String[]private int[]private String[]private String[]private String[]private char[]private intprivate intprivate floatprivate intprivate intprivate intprivate char[]private intprivate intprivate String[]private int[]private String[]private char[][]private int[]private int[]private String[]private booleanprivate intprivate String[]private char[][]private int[]private Stringprivate String[]private char[][]private intprivate static final Stringprivate static final Stringprivate Stringprivate intprivate Stringprivate static final intprivate static final charprivate static boolean[]private static boolean[]private intprivate String[]private int[]private String[]private static final char[]private static final char[]private static booleanprivate booleanprivate char[]private intprivate intprivate intprivate intprivate intprivate booleanprivate booleanprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate booleanprivate static final intprivate Readerprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate static final char[]private Stringprivate booleanprivate static final booleanprivate booleanprivate static final char[]private static final Stringprivate Stringprivate Booleanprivate Stringprivate static final Stringprivate static final char[]Fields inherited from interface org.xmlpull.v1.XmlPullParser
CDSECT, COMMENT, DOCDECL, END_DOCUMENT, END_TAG, ENTITY_REF, FEATURE_PROCESS_DOCDECL, FEATURE_PROCESS_NAMESPACES, FEATURE_REPORT_NAMESPACE_ATTRIBUTES, FEATURE_VALIDATION, IGNORABLE_WHITESPACE, NO_NAMESPACE, PROCESSING_INSTRUCTION, START_DOCUMENT, START_TAG, TEXT, TYPES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddefineEntityReplacementText(String entityName, String replacementText) private voidensureAttributesCapacity(int size) Make sure that in attributes temporary array is enough space.private voidMake sure that we have enough space to keep element stack if passed size.private voidprivate voidensureNamespacesCapacity(int size) private voidensurePC(int end) private static final intfastHash(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 ...private voidfillBuf()private static intfindFragment(int bufMinPos, char[] b, int start, int end) intgetAttributeName(int index) getAttributeNamespace(int index) getAttributePrefix(int index) getAttributeType(int index) getAttributeValue(int index) getAttributeValue(String namespace, String name) intintgetDepth()intbooleangetFeature(String name) Unknown properties are always returned as falseintgetName()getNamespace(String prefix) intgetNamespaceCount(int depth) getNamespacePrefix(int pos) getNamespaceUri(int pos) Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.getProperty(String name) getText()char[]getTextCharacters(int[] holderForStartAndLength) booleanisAttributeDefault(int index) booleanprivate booleanisNameChar(char ch) private booleanisNameStartChar(char ch) private booleanisS(char ch) booleanprivate voidjoinPC()private char[]lookupEntityReplacement(int entityNameLen) private charmore()private StringnewString(char[] cbuf, int off, int len) private StringnewStringIntern(char[] cbuf, int off, int len) intnext()private intnextImpl()intnextTag()nextText()intprivate charprivate voidparseCDSect(boolean hadCharData) private voidprivate voidintprivate char[]private intprivate booleanparsePI()private intintprivate voidparseXmlDecl(char ch) private voidparseXmlDeclWithVersion(int versionStart, int versionEnd) private Stringprintable(char ch) private Stringvoidprivate charrequireInput(char ch, char[] input) private charprivate voidreset()private voidvoidsetFeature(String name, boolean state) Method setFeaturevoidsetInput(InputStream inputStream, String inputEncoding) voidprivate static final voidsetName(char ch) private static final voidsetNameStart(char ch) voidsetProperty(String name, Object value) private charskipS(char ch) voidSkip sub tree that is currently parser positioned on.
-
Field Details
-
XML_URI
- See Also:
-
XMLNS_URI
- See Also:
-
FEATURE_XML_ROUNDTRIP
- See Also:
-
FEATURE_NAMES_INTERNED
- See Also:
-
PROPERTY_XMLDECL_VERSION
- See Also:
-
PROPERTY_XMLDECL_STANDALONE
- See Also:
-
PROPERTY_XMLDECL_CONTENT
- See Also:
-
PROPERTY_LOCATION
- See Also:
-
allStringsInterned
private boolean allStringsInternedImplementation 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
-
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
-
elPrefix
-
elUri
-
elNamespaceCount
private int[] elNamespaceCount -
attributeCount
private int attributeCount -
attributeName
-
attributeNameHash
private int[] attributeNameHash -
attributePrefix
-
attributeUri
-
attributeValue
-
namespaceEnd
private int namespaceEnd -
namespacePrefix
-
namespacePrefixHash
private int[] namespacePrefixHash -
namespaceUri
-
entityEnd
private int entityEnd -
entityName
-
entityNameBuf
private char[][] entityNameBuf -
entityReplacement
-
entityReplacementBuf
private char[][] entityReplacementBuf -
entityNameHash
private int[] entityNameHash -
READ_CHUNK_SIZE
private static final int READ_CHUNK_SIZE- See Also:
-
reader
-
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
-
entityRefName
-
xmlDeclVersion
-
xmlDeclStandalone
-
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
-
newStringIntern
-
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
Method setFeature- Specified by:
setFeaturein interfaceorg.xmlpull.v1.XmlPullParser- Parameters:
name- a Stringstate- a boolean- Throws:
org.xmlpull.v1.XmlPullParserException
-
getFeature
Unknown properties are always returned as false- Specified by:
getFeaturein interfaceorg.xmlpull.v1.XmlPullParser
-
setProperty
- Specified by:
setPropertyin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getProperty
- Specified by:
getPropertyin interfaceorg.xmlpull.v1.XmlPullParser
-
setInput
- Specified by:
setInputin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
setInput
public void setInput(InputStream inputStream, String inputEncoding) throws org.xmlpull.v1.XmlPullParserException - Specified by:
setInputin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getInputEncoding
- Specified by:
getInputEncodingin interfaceorg.xmlpull.v1.XmlPullParser
-
defineEntityReplacementText
public void defineEntityReplacementText(String entityName, String replacementText) throws org.xmlpull.v1.XmlPullParserException - Specified by:
defineEntityReplacementTextin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getNamespaceCount
public int getNamespaceCount(int depth) throws org.xmlpull.v1.XmlPullParserException - Specified by:
getNamespaceCountin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getNamespacePrefix
- Specified by:
getNamespacePrefixin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getNamespaceUri
- Specified by:
getNamespaceUriin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getNamespace
- Specified by:
getNamespacein interfaceorg.xmlpull.v1.XmlPullParser
-
getDepth
public int getDepth()- Specified by:
getDepthin interfaceorg.xmlpull.v1.XmlPullParser
-
findFragment
private static int findFragment(int bufMinPos, char[] b, int start, int end) -
getPositionDescription
Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.- Specified by:
getPositionDescriptionin interfaceorg.xmlpull.v1.XmlPullParser
-
getLineNumber
public int getLineNumber()- Specified by:
getLineNumberin interfaceorg.xmlpull.v1.XmlPullParser
-
getColumnNumber
public int getColumnNumber()- Specified by:
getColumnNumberin interfaceorg.xmlpull.v1.XmlPullParser
-
isWhitespace
public boolean isWhitespace() throws org.xmlpull.v1.XmlPullParserException- Specified by:
isWhitespacein interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getText
- Specified by:
getTextin interfaceorg.xmlpull.v1.XmlPullParser
-
getTextCharacters
public char[] getTextCharacters(int[] holderForStartAndLength) - Specified by:
getTextCharactersin interfaceorg.xmlpull.v1.XmlPullParser
-
getNamespace
- Specified by:
getNamespacein interfaceorg.xmlpull.v1.XmlPullParser
-
getName
- Specified by:
getNamein interfaceorg.xmlpull.v1.XmlPullParser
-
getPrefix
- Specified by:
getPrefixin interfaceorg.xmlpull.v1.XmlPullParser
-
isEmptyElementTag
public boolean isEmptyElementTag() throws org.xmlpull.v1.XmlPullParserException- Specified by:
isEmptyElementTagin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserException
-
getAttributeCount
public int getAttributeCount()- Specified by:
getAttributeCountin interfaceorg.xmlpull.v1.XmlPullParser
-
getAttributeNamespace
- Specified by:
getAttributeNamespacein interfaceorg.xmlpull.v1.XmlPullParser
-
getAttributeName
- Specified by:
getAttributeNamein interfaceorg.xmlpull.v1.XmlPullParser
-
getAttributePrefix
- Specified by:
getAttributePrefixin interfaceorg.xmlpull.v1.XmlPullParser
-
getAttributeType
- Specified by:
getAttributeTypein interfaceorg.xmlpull.v1.XmlPullParser
-
isAttributeDefault
public boolean isAttributeDefault(int index) - Specified by:
isAttributeDefaultin interfaceorg.xmlpull.v1.XmlPullParser
-
getAttributeValue
- Specified by:
getAttributeValuein interfaceorg.xmlpull.v1.XmlPullParser
-
getAttributeValue
- Specified by:
getAttributeValuein interfaceorg.xmlpull.v1.XmlPullParser
-
getEventType
public int getEventType() throws org.xmlpull.v1.XmlPullParserException- Specified by:
getEventTypein interfaceorg.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:
requirein interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
skipSubTree
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.XmlPullParserExceptionIOException
-
nextText
- Specified by:
nextTextin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
nextTag
- Specified by:
nextTagin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
next
- Specified by:
nextin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
nextToken
- Specified by:
nextTokenin interfaceorg.xmlpull.v1.XmlPullParser- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
nextImpl
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseProlog
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseEpilog
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseEndTag
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseStartTag
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseAttribute
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseEntityRef
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
lookupEntityReplacement
private char[] lookupEntityReplacement(int entityNameLen) -
parseComment
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parsePI
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseXmlDecl
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseXmlDeclWithVersion
private void parseXmlDeclWithVersion(int versionStart, int versionEnd) throws org.xmlpull.v1.XmlPullParserException, IOException - Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseDocdecl
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
parseCDSect
private void parseCDSect(boolean hadCharData) throws org.xmlpull.v1.XmlPullParserException, IOException - Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
fillBuf
- Throws:
IOExceptionorg.xmlpull.v1.XmlPullParserException
-
more
- Throws:
IOExceptionorg.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.XmlPullParserExceptionIOException
-
requireNextS
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
skipS
- Throws:
org.xmlpull.v1.XmlPullParserExceptionIOException
-
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
-
printable
-