com.skype.tutorial.util
Class XmlStrMgr

java.lang.Object
  extended by com.skype.tutorial.util.XmlStrMgr

public class XmlStrMgr
extends java.lang.Object

Collect common "parse" XML document fields and encapsulate common code as methods.

Since:
1.0
Author:
Andrea Drane

Field Summary
static java.lang.String MY_CLASS_TAG
          Info/Debug console output message prefix/identifier tag.
private static java.text.DecimalFormat parseFmt
           
private static java.text.ParsePosition parsePos
           
private  java.lang.Number parseResult
           
private  boolean verboseDebugLvl
          Debug console output level: true for verbose; false for normal (default).
 
Constructor Summary
XmlStrMgr()
           
 
Method Summary
 boolean getVerboseDebug()
          Determine whether verbose debug is set.
 java.text.ParsePosition getXmlSubStrPos(java.lang.String xmlDoc, java.lang.String subStr, java.text.ParsePosition xmlStart)
          "Parse" an XML document for the first occurrence of a particular substring and return the position of the character following it.
 int getXmlValueNum(java.lang.String xmlDoc, java.lang.String xmlTag, java.text.ParsePosition xmlStart)
          "Parse" an XML document for the first occurrence of a particular tag and return its value.
 java.lang.String getXmlValueStr(java.lang.String xmlDoc, java.lang.String xmlTag, java.text.ParsePosition xmlStart)
          "Parse" an XML document for the first occurrence of a particular tag and return its value.
 void setVerboseDebug(boolean onOff)
          Turn verbose debug on/off.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MY_CLASS_TAG

public static final java.lang.String MY_CLASS_TAG
Info/Debug console output message prefix/identifier tag. Corresponds to class name.

Since:
1.0
See Also:
Constant Field Values

verboseDebugLvl

private boolean verboseDebugLvl
Debug console output level: true for verbose; false for normal (default).

Since:
1.0

parsePos

private static java.text.ParsePosition parsePos

parseResult

private java.lang.Number parseResult

parseFmt

private static java.text.DecimalFormat parseFmt
Constructor Detail

XmlStrMgr

public XmlStrMgr()
Method Detail

getXmlValueStr

public java.lang.String getXmlValueStr(java.lang.String xmlDoc,
                                       java.lang.String xmlTag,
                                       java.text.ParsePosition xmlStart)
"Parse" an XML document for the first occurrence of a particular tag and return its value. The parse terminates upon encountering the first opening angle bracket (<) following the opening target tag.

Parameters:
xmlDoc - The target XML document.
xmlTag - The target tag including the enclosing angle brackets.
xmlStart - The character position (from zero) in the document at which to start looking for the target tag.
Returns:
  • a String representation of the element value, which will be the empty string if target tag is empty, for example, <part></part>
  • null if not found
Since:
1.0

getXmlValueNum

public int getXmlValueNum(java.lang.String xmlDoc,
                          java.lang.String xmlTag,
                          java.text.ParsePosition xmlStart)
"Parse" an XML document for the first occurrence of a particular tag and return its value. The parse terminates based on the rules for java.text.DecimalFormat, using the pattern and symbol sets for the default locale.

Parameters:
xmlDoc - The target XML document.
xmlTag - The target tag including the enclosing angle brackets.
xmlStart - The character position (from zero) in the document at which to start looking for the target tag.
Returns:
  • an integer representation of the element value
  • -1 if:
    • not found
    • the target tag is empty, for example, <part></part>
    • a parse error occurred
Since:
1.0

getXmlSubStrPos

public java.text.ParsePosition getXmlSubStrPos(java.lang.String xmlDoc,
                                               java.lang.String subStr,
                                               java.text.ParsePosition xmlStart)
"Parse" an XML document for the first occurrence of a particular substring and return the position of the character following it. This enables the invoker to "count" its way through an XML document (by placing the invocation in a loop), access attribute values, skip over closing XML tags, and so forth.

Parameters:
xmlDoc - The target XML document.
subStr - The target substring, typically an opening XML tag and its initial attribute or a closing XML tag, such as:
  • <part identity="
  • </part>
xmlStart - The character position (from zero) in the document at which to start looking for the target substring.
Returns:
A ParsePosition instance with its index set to the position of the character following the target substring or null if not found.
Since:
1.0

getVerboseDebug

public boolean getVerboseDebug()
Determine whether verbose debug is set.

Returns:
  • true: verbose debug set
  • false: normal debug set
Since:
1.0

setVerboseDebug

public void setVerboseDebug(boolean onOff)
Turn verbose debug on/off.

Parameters:
onOff -
  • true: turn on verbose debug
  • false: turn off verbose debug
Since:
1.0