Add readNullableStartTag method.

This commit is contained in:
Christian P. MOMON 2013-10-19 22:55:29 +02:00
parent 75a5c81d38
commit 323dc51496

View file

@ -121,9 +121,9 @@ public class XMLReader
// Load next event. // Load next event.
if (this.nextEvent == null) if (this.nextEvent == null)
{ {
if (in.hasNext()) if (this.in.hasNext())
{ {
this.nextEvent = in.nextEvent(); this.nextEvent = this.in.nextEvent();
} }
} }
@ -275,6 +275,39 @@ public class XMLReader
return result; return result;
} }
/**
*
* @param label
* @return
* @throws XMLStreamException
* @throws XMLBadFormatException
* @throws Exception
*/
public XMLTag readNullableStartTag(final String label) throws XMLStreamException, XMLBadFormatException
{
XMLTag result;
//
result = readTag();
//
if (result == null)
{
throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
}
else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
{
throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
}
else if (!StringUtils.equals(result.getLabel(), label))
{
throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
}
//
return result;
}
/** /**
* *
* @param label * @param label
@ -345,9 +378,9 @@ public class XMLReader
event = this.nextEvent; event = this.nextEvent;
this.nextEvent = null; this.nextEvent = null;
} }
else if (in.hasNext()) else if (this.in.hasNext())
{ {
event = in.nextEvent(); event = this.in.nextEvent();
} }
else else
{ {