hudson.plugins.violations.parse
Class AbstractParser

java.lang.Object
  extended by hudson.plugins.violations.parse.AbstractParser
Direct Known Subclasses:
AbstractTypeParser, BuildModelParser, FileModelParser

public abstract class AbstractParser
extends java.lang.Object

Base class for parsing xml files. Contains a number of utility protected methods to aid in use of XmlPullParser.


Constructor Summary
AbstractParser()
           
 
Method Summary
protected  void checkEvent(int event, java.lang.String message)
          check the current event type.
protected  java.lang.String checkGetAttribute(java.lang.String name)
          Get an attribute value and ensure that the attribute is present.
protected  int checkGetInt(java.lang.String name)
          Get an attribute value as an int and ensure that the attribute is present.
protected  long checkGetLong(java.lang.String name)
          Get an attribute value as a long and ensure that the attribute is present.
protected  void checkNextEvent(int event, java.lang.String message)
          get the next event and check the type.
protected  java.lang.String checkNotBlank(java.lang.String name)
          Get an attribute value and ensure that the attribute is present and is not blank.
protected  void endElement()
          skip to the end of the element.
protected abstract  void execute()
          Abstract method to run the parsing.
protected  void expectNextTag(java.lang.String tag)
          Find the next START_TAG event and throw an exception if the tagname is not "tag";
protected  void expectStartTag(java.lang.String tag)
          Find the next START_TAG event and throw an exception if the tagname is not "tag";
protected  int getInt(java.lang.String name)
          Get an attribute value as an int.
protected  java.lang.String getNextText(java.lang.String message)
          Get the next event and check it is a text event.
protected  org.xmlpull.v1.XmlPullParser getParser()
          Get the parser.
protected  java.lang.String getSibTag()
          get the next sibling element.
protected  java.lang.String getString(java.lang.String name)
          Get an attribute value as a string.
 void setParser(org.xmlpull.v1.XmlPullParser parser)
          Set the parser.
protected  void skipTag()
          Assume at a start tag, skip it and the rest of the element.
protected  boolean skipToTag(java.lang.String tagName)
          Skip to a specific tag within a element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

public AbstractParser()
Method Detail

getParser

protected org.xmlpull.v1.XmlPullParser getParser()
Get the parser.

Returns:
the parser.

setParser

public void setParser(org.xmlpull.v1.XmlPullParser parser)
Set the parser.

Parameters:
parser - the value to use.

execute

protected abstract void execute()
                         throws java.io.IOException,
                                org.xmlpull.v1.XmlPullParserException
Abstract method to run the parsing.

Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

getString

protected java.lang.String getString(java.lang.String name)
                              throws java.io.IOException,
                                     org.xmlpull.v1.XmlPullParserException
Get an attribute value as a string.

Parameters:
name - the name of the attribute.
Returns:
the int value of the attribute, or "" if the attribute is not present.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

getInt

protected int getInt(java.lang.String name)
              throws java.io.IOException,
                     org.xmlpull.v1.XmlPullParserException
Get an attribute value as an int.

Parameters:
name - the name of the attribute.
Returns:
the int value of the attribute, or 0 if the attribute is not present or is not an int.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

checkGetInt

protected int checkGetInt(java.lang.String name)
                   throws java.io.IOException,
                          org.xmlpull.v1.XmlPullParserException
Get an attribute value as an int and ensure that the attribute is present.

Parameters:
name - the name of the attribute.
Returns:
the int value of the attribute, or 0 if the attribute is not an int.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax or the attribute is not present.

checkGetLong

protected long checkGetLong(java.lang.String name)
                     throws java.io.IOException,
                            org.xmlpull.v1.XmlPullParserException
Get an attribute value as a long and ensure that the attribute is present.

Parameters:
name - the name of the attribute.
Returns:
the long value of the attribute, or 0 if the attribute is not an long.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax, of the attribute is not present.

checkGetAttribute

protected java.lang.String checkGetAttribute(java.lang.String name)
                                      throws java.io.IOException,
                                             org.xmlpull.v1.XmlPullParserException
Get an attribute value and ensure that the attribute is present.

Parameters:
name - the name of the attribute.
Returns:
the value of the attribute.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax, or the attribute is not present.

checkNotBlank

protected java.lang.String checkNotBlank(java.lang.String name)
                                  throws java.io.IOException,
                                         org.xmlpull.v1.XmlPullParserException
Get an attribute value and ensure that the attribute is present and is not blank.

Parameters:
name - the name of the attribute.
Returns:
the value of the attribute.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax. or the attribute is not present or is blank.

skipToTag

protected boolean skipToTag(java.lang.String tagName)
                     throws java.io.IOException,
                            org.xmlpull.v1.XmlPullParserException
Skip to a specific tag within a element.

Parameters:
tagName - the tag to look for.
Returns:
true if the tag is found, false otherwise.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

getSibTag

protected java.lang.String getSibTag()
                              throws java.io.IOException,
                                     org.xmlpull.v1.XmlPullParserException
get the next sibling element.

Returns:
the tag of the element or none if there are no more elements.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

skipTag

protected void skipTag()
                throws java.io.IOException,
                       org.xmlpull.v1.XmlPullParserException
Assume at a start tag, skip it and the rest of the element.

Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

expectStartTag

protected void expectStartTag(java.lang.String tag)
                       throws java.io.IOException,
                              org.xmlpull.v1.XmlPullParserException
Find the next START_TAG event and throw an exception if the tagname is not "tag";

Parameters:
tag - the tag to expect.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

expectNextTag

protected void expectNextTag(java.lang.String tag)
                      throws java.io.IOException,
                             org.xmlpull.v1.XmlPullParserException
Find the next START_TAG event and throw an exception if the tagname is not "tag";

Parameters:
tag - the tag to expect.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

checkEvent

protected void checkEvent(int event,
                          java.lang.String message)
                   throws java.io.IOException,
                          org.xmlpull.v1.XmlPullParserException
check the current event type.

Parameters:
event - the event type expected.
message - a message to use in the RT exception if the event is not found.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

checkNextEvent

protected void checkNextEvent(int event,
                              java.lang.String message)
                       throws java.io.IOException,
                              org.xmlpull.v1.XmlPullParserException
get the next event and check the type.

Parameters:
event - the event type expected.
message - a message to use in the RT exception if the event is not found.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

getNextText

protected java.lang.String getNextText(java.lang.String message)
                                throws java.io.IOException,
                                       org.xmlpull.v1.XmlPullParserException
Get the next event and check it is a text event.

Parameters:
message - a message to use in the RT exception if the TEXT event is not found.
Returns:
the text in the event.
Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.

endElement

protected void endElement()
                   throws java.io.IOException,
                          org.xmlpull.v1.XmlPullParserException
skip to the end of the element. recursivly skip over nested elements.

Throws:
java.io.IOException - if there is a problem writing or reading.
org.xmlpull.v1.XmlPullParserException - if there is a problem in the syntax.


Copyright © 2004-2012. All Rights Reserved.