Package com.tangosol.run.xml
Class SimpleParser
java.lang.Object
com.tangosol.util.Base
com.tangosol.run.xml.SimpleParser
This class uses the XmlTokenizer to produce an XmlDocument from XML text.
- Version:
- 1.00, 2001.07.16
- Author:
- Cameron Purdy
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanIf true, validate XML if it contains an XSD referenceprotected com.tangosol.run.xml.XmlTokenThe "current" token being evaluated.protected com.tangosol.run.xml.XmlTokenizerThe lexical tokenizer. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an XML SimpleParser.SimpleParser(boolean fValidate) Construct an XML SimpleParser. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.tangosol.run.xml.XmlTokencurrent()Returns the current token and advances to the next token.protected booleanDetermine if there is a current token.protected booleanhasNext()Determine if there is a next token.protected voidinit()Internal initialization.protected XmlDocumentFactory method to instantiate an XmlDocument implementation.static voidUnit test.protected com.tangosol.run.xml.XmlTokenmark()Marks the current position and returns it as a token.protected com.tangosol.run.xml.XmlTokenmatch(int id) Verifies that the current token matches the passed token id and, if so, advances to the next token.protected com.tangosol.run.xml.XmlTokenVerifies that the current token is a name token whose name matches the passed String and, if so, advances to the next token.protected com.tangosol.run.xml.XmlTokennext()Advances to and returns the next token.protected voidparseComment(XmlElement xml) Parse comments.protected voidparseComment(XmlElement xml, boolean fIsDocument) Parse comments.protected voidparseDoctype(XmlDocument xml) Parse doc type.protected voidparseDocument(XmlDocument xml) Factory method to instantiate an XmlDocument implementation.protected voidparseElement(XmlElement xml) Note: '<' and element name have already been parsedprotected voidparseMisc(XmlElement xml) Parse comments / other PIs.protected voidparsePi(XmlElement xml) Parse <?protected voidparsePi(XmlElement xml, boolean fXmlDeclAllowed) Parse <?parseXml(InputStream stream) Parse the specified InputStream into an XmlDocument object.parseXml(InputStream stream, String sCharset) Parse the specified InputStream into an XmlDocument object using the specified charset.Parse the specified Reader into an XmlDocument object.Parse the specified String into an XmlDocument object.parseXml(String sXml, XmlDocument xml) Parse the passed script.protected voidparseXmlDecl(XmlDocument xml) Parse XML declaration.protected com.tangosol.run.xml.XmlTokenpeek(int id) Tests if the current token matches the passed token id and, if so, advances to the next token.protected com.tangosol.run.xml.XmlTokenpeek(int cat, int subcat) Tests if the current token matches the passed token category and sub-category.protected com.tangosol.run.xml.XmlTokenTests if the current token is a name that matches the passed String and, if so, advances to the next token.protected InputStreamskipBOM(InputStream in) Read the providedInputStreamto determine if the stream starts with a UTF-8 BOM (http://www.unicode.org/faq/utf_bom.html#BOM).Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, newHashMap, newHashMap, newHashSet, newHashSet, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Field Details
-
m_fValidate
protected final boolean m_fValidateIf true, validate XML if it contains an XSD reference -
m_toker
protected com.tangosol.run.xml.XmlTokenizer m_tokerThe lexical tokenizer. -
m_token
protected com.tangosol.run.xml.XmlToken m_tokenThe "current" token being evaluated.
-
-
Constructor Details
-
SimpleParser
public SimpleParser()Construct an XML SimpleParser. If the XML contains an XSD reference, the parser will validate using the provided XSD. -
SimpleParser
public SimpleParser(boolean fValidate) Construct an XML SimpleParser.- Parameters:
fValidate- if true, validate XML if it contains an XSD reference
-
-
Method Details
-
init
protected void init()Internal initialization. -
parseXml
Parse the specified String into an XmlDocument object.- Parameters:
sXml- the String to parse- Returns:
- an XmlDocument object
- Throws:
IOException- if I/O error occurs
-
parseXml
Parse the specified Reader into an XmlDocument object.- Parameters:
reader- the Reader object- Returns:
- an XmlDocument object
- Throws:
IOException- if I/O error occurs
-
parseXml
Parse the specified InputStream into an XmlDocument object.- Parameters:
stream- the InputStream object- Returns:
- an XmlDocument object
- Throws:
IOException- if I/O error occurs
-
parseXml
Parse the specified InputStream into an XmlDocument object using the specified charset.- Parameters:
stream- the InputStream objectsCharset- the charset name- Returns:
- an XmlDocument object
- Throws:
IOException- if I/O error occurs
-
parseXml
Parse the passed script.- Parameters:
sXml- the script to parse (as a string)xml- the XML document object to parse into- Returns:
- the XmlDocument object
- Throws:
IOException- if I/O error occurs
-
instantiateDocument
Factory method to instantiate an XmlDocument implementation.- Returns:
- an object implementing XmlDocument
-
main
Unit test.- Parameters:
asArgs- the string array arguments
-
parseDocument
Factory method to instantiate an XmlDocument implementation.- Parameters:
xml- a blank XmlDocument- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parsePi
Parse <?xml.- Parameters:
xml- the XML element- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parsePi
protected void parsePi(XmlElement xml, boolean fXmlDeclAllowed) throws com.tangosol.dev.compiler.CompilerException Parse <?xml.- Parameters:
xml- the XML elementfXmlDeclAllowed- whether XML declaration is allowed- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parseXmlDecl
Parse XML declaration.- Parameters:
xml- the XML document- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parseDoctype
Parse doc type.- Parameters:
xml- the XML document- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parseElement
Note: '<' and element name have already been parsed- Parameters:
xml- the XML element- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parseMisc
Parse comments / other PIs.- Parameters:
xml- the XML element- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parseComment
Parse comments.- Parameters:
xml- the XML element- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
parseComment
protected void parseComment(XmlElement xml, boolean fIsDocument) throws com.tangosol.dev.compiler.CompilerException Parse comments.- Parameters:
xml- the XML elementfIsDocument- whether the passed in XmlElement is an XmlDocument- Throws:
com.tangosol.dev.compiler.CompilerException- if compiler error occurs
-
hasCurrent
protected boolean hasCurrent()Determine if there is a current token.- Returns:
- true if there is a current token
-
current
protected com.tangosol.run.xml.XmlToken current() throws com.tangosol.dev.compiler.CompilerExceptionReturns the current token and advances to the next token.- Returns:
- the current token
- Throws:
com.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
hasNext
protected boolean hasNext()Determine if there is a next token.- Returns:
- true if there is a next token
-
next
protected com.tangosol.run.xml.XmlToken next() throws com.tangosol.dev.compiler.CompilerExceptionAdvances to and returns the next token.- Returns:
- the next token
- Throws:
com.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
match
protected com.tangosol.run.xml.XmlToken match(int id) throws com.tangosol.dev.compiler.CompilerException Verifies that the current token matches the passed token id and, if so, advances to the next token. Otherwise, a syntax exception is thrown.- Parameters:
id- the token id to match- Returns:
- the current token
- Throws:
com.tangosol.dev.compiler.SyntaxException- thrown if the token does not matchcom.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
match
protected com.tangosol.run.xml.XmlToken match(String sName) throws com.tangosol.dev.compiler.CompilerException Verifies that the current token is a name token whose name matches the passed String and, if so, advances to the next token. Otherwise, a syntax exception is thrown.- Parameters:
sName- the name token text to match- Returns:
- the matched token
- Throws:
com.tangosol.dev.compiler.SyntaxException- thrown if the token does not matchcom.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
peek
protected com.tangosol.run.xml.XmlToken peek(int id) throws com.tangosol.dev.compiler.CompilerException Tests if the current token matches the passed token id and, if so, advances to the next token.- Parameters:
id- the token id to peek for- Returns:
- the current token, if matched, or null
- Throws:
com.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
peek
protected com.tangosol.run.xml.XmlToken peek(int cat, int subcat) throws com.tangosol.dev.compiler.CompilerException Tests if the current token matches the passed token category and sub-category. If so, it returns the current token and advances to the next token.- Parameters:
cat- the category to peek forsubcat- the sub-category to peek for- Returns:
- the current token, if matched, or null
- Throws:
com.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
peek
protected com.tangosol.run.xml.XmlToken peek(String sName) throws com.tangosol.dev.compiler.CompilerException Tests if the current token is a name that matches the passed String and, if so, advances to the next token.- Parameters:
sName- the name token text to peek for- Returns:
- id the current token, if matched, or null
- Throws:
com.tangosol.dev.compiler.CompilerException- potentially thrown by the tokenizer
-
mark
protected com.tangosol.run.xml.XmlToken mark()Marks the current position and returns it as a token.- Returns:
- the current token
-
skipBOM
Read the providedInputStreamto determine if the stream starts with a UTF-8 BOM (http://www.unicode.org/faq/utf_bom.html#BOM). If the BOM is present, advance the stream to skip it.This is a workaround for the inability of the Java UTF-8 encoding to recognize the UTF-8 BOM (http://bugs.sun.com/view_bug.do?bug_id=4508058).
- Parameters:
in- InputStream to check for BOM- Returns:
- an InputStream with the UTF-8 BOM skipped
- Throws:
IOException- if I/O error occurs
-