|
Version: ${maven.project.version} | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.soaplab.services.metadata.TagTracer
public class TagTracer
The class represents a stack of visited tags when parsing an XML source. It helps when the same named tags appear in various parts of the parsed source.
One can push() (at the beginning of every DocumentHandler.startElement()) and pop() (at the end of each DocumentHandler.endElement()) and thus keep track of the currently processed tag and its path.
The TagTracer can also show the whole path, or just compare if a given tag path is a current one.
Here is an example how to use it:
TagTracer tt; private static final String[] ANALYSIS_PATH = new String[] { "DsLSRAnalysis", "analysis" }; private static final String[] EXT_PATH = UUtils.join (ANALYSIS_PATH, new String[] { "analysis_extension" }); private static final String[] APP_INFO_PATH = UUtils.join (EXT_PATH, new String[] { "app_info" }); private static final String[] EVENT_PATH = UUtils.join (EXT_PATH, new String[] { "event" }); ... public void startElement (String name, AttributeList attrs) { tt.push (name); if (tt.is (ANALYSIS_PATH)) { // do something for "analysis" // ... } public void endElement (String name) { // ... tt.pop(); }
Field Summary | |
---|---|
static java.lang.String |
VERSION
Version and date of last update of this class. |
Constructor Summary | |
---|---|
TagTracer()
A default constructor. |
Method Summary | |
---|---|
java.lang.String[] |
getPath()
Gets contents of the whole stack. |
boolean |
is(java.lang.String[] tagPath)
Compares the contents of the current stack with the given list of tag names. |
java.lang.String |
peek()
Looks at the tag name at the top of this stack without removing it from the stack. |
java.lang.String |
pop()
Removes the tag name from the top of this stack and returns it. |
void |
push(java.lang.String name)
Pushes a tag name onto the top of this stack. |
void |
reset()
Removes all elements fom the stack. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VERSION
Constructor Detail |
---|
public TagTracer()
Method Detail |
---|
public void push(java.lang.String name)
name
- a tag name (usually of the currently visited tag)
to be put on the stactpublic java.lang.String pop()
EmptyStackException
- if there is no element on the stackpublic java.lang.String peek()
EmptyStackException
- if there is no element on the stackpublic boolean is(java.lang.String[] tagPath)
TBD: to allow '*' in tagPath> to represents 'anything' - even more elements in a sequence (but then again - I do not want to simulate here the whole XPath :-) )
tagPath
- a list of tag names to be compared with the contents
of the stack
public java.lang.String[] getPath()
public void reset()
|
Version: ${maven.project.version} | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |