diff --git a/src/fr/devinsy/util/xml/XMLReader.java b/src/fr/devinsy/util/xml/XMLReader.java
index 92bb16d..1fc277d 100644
--- a/src/fr/devinsy/util/xml/XMLReader.java
+++ b/src/fr/devinsy/util/xml/XMLReader.java
@@ -44,586 +44,581 @@ import fr.devinsy.util.xml.XMLTag.TagType;
*/
public class XMLReader
{
+ private static final Logger logger = LoggerFactory.getLogger(XMLReader.class);
- private static final Logger logger = LoggerFactory.getLogger(XMLReader.class);
+ protected XMLEventReader in;
+ private XMLEvent nextEvent;
- protected XMLEventReader in;
- private XMLEvent nextEvent;
-
- /**
+ /**
*
*/
- protected XMLReader()
- {
- this.in = null;
- this.nextEvent = null;
- }
+ protected XMLReader()
+ {
+ this.in = null;
+ this.nextEvent = null;
+ }
- /**
- *
- * @param file
- * @throws XMLStreamException
- * @throws FileNotFoundException
- */
- public XMLReader(final File file) throws FileNotFoundException, XMLStreamException
- {
+ /**
+ *
+ * @param file
+ * @throws XMLStreamException
+ * @throws FileNotFoundException
+ */
+ public XMLReader(final File file) throws FileNotFoundException, XMLStreamException
+ {
+ this.nextEvent = null;
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ this.in = factory.createXMLEventReader(new FileInputStream(file), "UTF-8");
+ }
- this.nextEvent = null;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- this.in = factory.createXMLEventReader(new FileInputStream(file), "UTF-8");
- }
+ /**
+ *
+ * @param target
+ * @throws XMLStreamException
+ */
+ public XMLReader(final InputStream source) throws XMLStreamException
+ {
+ this.nextEvent = null;
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ this.in = factory.createXMLEventReader(source);
+ }
- /**
- *
- * @param target
- * @throws XMLStreamException
- */
- public XMLReader(final InputStream source) throws XMLStreamException
- {
+ /**
+ *
+ * @param target
+ * @throws XMLStreamException
+ */
+ public XMLReader(final Reader source) throws XMLStreamException
+ {
+ this.nextEvent = null;
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ this.in = factory.createXMLEventReader(source);
+ }
- this.nextEvent = null;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- this.in = factory.createXMLEventReader(source);
- }
+ /**
+ * @throws XMLStreamException
+ *
+ */
+ public void close()
+ {
+ if (this.in != null)
+ {
+ try
+ {
+ this.in.close();
+ }
+ catch (XMLStreamException exception)
+ {
+ exception.printStackTrace();
+ }
+ }
+ }
- /**
- *
- * @param target
- * @throws XMLStreamException
- */
- public XMLReader(final Reader source) throws XMLStreamException
- {
+ /**
+ * This methods does a premonition act. Useful to detect end of a list.
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ */
+ public boolean hasNextStartTag(final String label) throws XMLStreamException
+ {
+ boolean result;
- this.nextEvent = null;
- XMLInputFactory factory = XMLInputFactory.newInstance();
- this.in = factory.createXMLEventReader(source);
- }
+ // Load next event.
+ if (this.nextEvent == null)
+ {
+ if (this.in.hasNext())
+ {
+ this.nextEvent = this.in.nextEvent();
+ }
+ }
- /**
- * @throws XMLStreamException
- *
- */
- public void close()
- {
- if (this.in != null)
- {
- try
- {
- this.in.close();
- }
- catch (XMLStreamException exception)
- {
- exception.printStackTrace();
- }
- }
- }
+ // Analyze next event.
+ if (this.nextEvent == null)
+ {
+ result = false;
+ }
+ else if ((this.nextEvent.isStartElement()) && (StringUtils.equals(this.nextEvent.asStartElement().getName().getLocalPart(), label)))
+ {
+ result = true;
+ }
+ else
+ {
+ result = false;
+ }
- /**
- * This methods does a premonition act. Useful to detect end of a list.
- *
- * @param label
- * @return
- * @throws XMLStreamException
- */
- public boolean hasNextStartTag(final String label) throws XMLStreamException
- {
- boolean result;
+ //
+ return result;
+ }
- // Load next event.
- if (this.nextEvent == null)
- {
- if (this.in.hasNext())
- {
- this.nextEvent = this.in.nextEvent();
- }
- }
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLBadFormatException
+ * @throws XMLStreamException
+ */
+ public XMLTag readContentTag(final String label) throws XMLBadFormatException, XMLStreamException
+ {
+ XMLTag result;
- // Analyze next event.
- if (this.nextEvent == null)
- {
- result = false;
- }
- else if ((this.nextEvent.isStartElement()) && (StringUtils.equals(this.nextEvent.asStartElement().getName().getLocalPart(), label)))
- {
- result = true;
- }
- else
- {
- result = false;
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, content tag [" + label + "] is expected.");
+ }
+ else if (result.getType() != TagType.CONTENT)
+ {
+ throw new XMLBadFormatException("Content tag [" + label + "] is missing.");
+ }
+ else if (!StringUtils.equals(label, result.getLabel()))
+ {
+ throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLBadFormatException
- * @throws XMLStreamException
- */
- public XMLTag readContentTag(final String label) throws XMLBadFormatException, XMLStreamException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ */
+ public XMLTag readEndTag(final String label) throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, content tag [" + label + "] is expected.");
- }
- else if (result.getType() != TagType.CONTENT)
- {
- throw new XMLBadFormatException("Content tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(label, result.getLabel()))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, end tag [" + label + "] is expected.");
+ }
+ else if (result.getType() != TagType.END)
+ {
+ throw new XMLBadFormatException("End tag [" + label + "] is missing.");
+ }
+ else if (!StringUtils.equals(result.getLabel(), label))
+ {
+ throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- */
- public XMLTag readEndTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ * @throws Exception
+ */
+ public XMLTag readListTag(final String label) throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, end tag [" + label + "] is expected.");
- }
- else if (result.getType() != TagType.END)
- {
- throw new XMLBadFormatException("End tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(result.getLabel(), label))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
+ }
+ else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
+ {
+ throw new XMLBadFormatException("List tag [" + label + "] is missing.");
+ }
+ else if (!StringUtils.equals(label, result.getLabel()))
+ {
+ throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readListTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ * @throws Exception
+ */
+ public XMLTag readNullableContentTag(final String label) throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
- }
- else if ((result.getType() != TagType.START) && (result.getType() != TagType.EMPTY))
- {
- throw new XMLBadFormatException("List tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(label, result.getLabel()))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
+ }
+ else if (!StringUtils.equals(label, result.getLabel()))
+ {
+ throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
+ }
+ else if ((result.getType() != TagType.EMPTY) && (result.getType() != TagType.CONTENT))
+ {
+ throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readNullableContentTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ * @throws Exception
+ */
+ public XMLTag readNullableStartTag(final String label) throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, tag [" + label + "] is expected.");
- }
- else if (!StringUtils.equals(label, result.getLabel()))
- {
- throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
- }
- else if ((result.getType() != TagType.EMPTY) && (result.getType() != TagType.CONTENT))
- {
- throw new XMLBadFormatException("Nullable content tag [" + label + "] is missing.");
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ 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.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readNullableStartTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ * @throws Exception
+ */
+ public XMLTag readStartTag(final String label) throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- 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.");
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
+ }
+ else if (result.getType() != TagType.START)
+ {
+ throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
+ }
+ else if (!StringUtils.equals(result.getLabel(), label))
+ {
+ throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- * @throws Exception
- */
- public XMLTag readStartTag(final String label) throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ * Transducer graph :
+ *
+ * - START_DOCUMENT => HEADER TAG
+ *
- START_ELEMENT(X) + START_ELEMENT(Y) => => START TAG
+ *
- START_ELEMENT(X) + CHARACTERS(C) + START_ELEMENT(Y) => SPACES=>
+ * START TAG
+ *
- START_ELEMENT(X) + CHARACTERS(C) + END_ELEMENT(X) => C =>
+ * CONTENT TAG
+ *
- START_ELEMENT(X) + END_ELEMENT(X) => => => EMPTY
+ *
- END_ELEMENT(X) =>
=> END TAG
+ * - END_DOCUMENT => FOOTER TAG
+ *
+ *
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ *
+ */
+ public XMLTag readTag() throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, start tag [" + label + "] is expected.");
- }
- else if (result.getType() != TagType.START)
- {
- throw new XMLBadFormatException("Start tag [" + label + "] is missing.");
- }
- else if (!StringUtils.equals(result.getLabel(), label))
- {
- throw new XMLBadFormatException("Tag with label [" + label + "] is missing.");
- }
+ int level = 1;
+ boolean ended = false;
+ result = null;
+ XMLAttributes attributesBuffer = null;
+ QName nameBuffer = null;
+ StringList contentBuffer = null;
+ while (!ended)
+ {
+ //
+ XMLEvent event;
+ if (this.nextEvent != null)
+ {
+ event = this.nextEvent;
+ this.nextEvent = null;
+ }
+ else if (this.in.hasNext())
+ {
+ event = this.in.nextEvent();
+ }
+ else
+ {
+ event = null;
+ }
- //
- return result;
- }
+ if (event == null)
+ {
+ ended = true;
+ result = null;
+ }
+ else
+ {
+ logger.debug("eventType=" + XMLTools.toString(event));
+ switch (level)
+ {
+ case 1:
+ switch (event.getEventType())
+ {
+ case XMLEvent.START_DOCUMENT:
+ // START_DOCUMENT => START DOCUMENT TAG
+ ended = true;
+ result = new XMLTag(null, TagType.HEADER, null);
+ break;
+ case XMLEvent.START_ELEMENT:
+ // START_ELEMENT(X) => ...
+ nameBuffer = event.asStartElement().getName();
+ attributesBuffer = new XMLAttributes(event.asStartElement().getAttributes());
+ level += 1;
+ break;
+ case XMLEvent.END_ELEMENT:
+ // END_ELEMENT(X) => => END TAG
+ ended = true;
+ result = new XMLTag(event.asEndElement().getName(), TagType.END, null);
+ break;
+ case XMLEvent.END_DOCUMENT:
+ // END_DOCUMENT => END DOCUMENT TAG
+ ended = true;
+ result = new XMLTag(null, TagType.FOOTER, null);
+ break;
+ }
+ break;
+ case 2:
+ switch (event.getEventType())
+ {
+ case XMLEvent.START_ELEMENT:
+ // START_ELEMENT(X) + START_ELEMENT(Y) =>
+ // => START TAG
+ ended = true;
+ result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
+ this.nextEvent = event;
+ break;
+ case XMLEvent.CHARACTERS:
+ // START_ELEMENT(X) + CHARACTERS(C) => ...
+ contentBuffer = new StringList(50);
+ contentBuffer.append(event.asCharacters().getData());
+ level += 1;
+ break;
+ case XMLEvent.END_ELEMENT:
+ // START_ELEMENT(X) + END_ELEMENT(X) =>
+ // => => EMPTY
+ ended = true;
+ result = new XMLTag(nameBuffer, TagType.EMPTY, attributesBuffer);
+ break;
+ default:
+ throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
+ }
+ break;
+ case 3:
+ switch (event.getEventType())
+ {
+ case XMLEvent.START_ELEMENT:
+ // START_ELEMENT(X) + CHARACTERS(C) +
+ // START_ELEMENT(Y) =>
+ // SPACES => START TAG
+ ended = true;
+ result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
+ this.nextEvent = event;
+ break;
+ case XMLEvent.CHARACTERS:
+ // START_ELEMENT(X) + CHARACTERS(C1) +
+ // CHARACTERS(C2)=> ...
+ contentBuffer.append(event.asCharacters().getData());
+ break;
+ case XMLEvent.END_ELEMENT:
+ // START_ELEMENT(X) + CHARACTERS(C) +
+ // END_ELEMENT(X) => C
+ // => CONTENT TAG
+ ended = true;
+ result = new XMLTag(nameBuffer, TagType.CONTENT, attributesBuffer);
+ result.setContent(contentBuffer.toString());
+ break;
+ default:
+ throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
+ }
+ break;
+ default:
+ throw new XMLBadFormatException("Unexpected level [" + level + "].");
+ }
+ }
+ }
- /**
- * Transducer graph :
- *
- * - START_DOCUMENT => HEADER TAG
- *
- START_ELEMENT(X) + START_ELEMENT(Y) => => START TAG
- *
- START_ELEMENT(X) + CHARACTERS(C) + START_ELEMENT(Y) => SPACES=>
- * START TAG
- *
- START_ELEMENT(X) + CHARACTERS(C) + END_ELEMENT(X) => C =>
- * CONTENT TAG
- *
- START_ELEMENT(X) + END_ELEMENT(X) => => => EMPTY
- *
- END_ELEMENT(X) =>
=> END TAG
- * - END_DOCUMENT => FOOTER TAG
- *
- *
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- *
- */
- public XMLTag readTag() throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ logger.debug("=> " + XMLTools.toString(result));
- int level = 1;
- boolean ended = false;
- result = null;
- XMLAttributes attributesBuffer = null;
- QName nameBuffer = null;
- StringList contentBuffer = null;
- while (!ended)
- {
- //
- XMLEvent event;
- if (this.nextEvent != null)
- {
- event = this.nextEvent;
- this.nextEvent = null;
- }
- else if (this.in.hasNext())
- {
- event = this.in.nextEvent();
- }
- else
- {
- event = null;
- }
+ //
+ return result;
+ }
- if (event == null)
- {
- ended = true;
- result = null;
- }
- else
- {
- logger.debug("eventType=" + XMLTools.toString(event));
- switch (level)
- {
- case 1:
- switch (event.getEventType())
- {
- case XMLEvent.START_DOCUMENT:
- // START_DOCUMENT => START DOCUMENT TAG
- ended = true;
- result = new XMLTag(null, TagType.HEADER, null);
- break;
- case XMLEvent.START_ELEMENT:
- // START_ELEMENT(X) => ...
- nameBuffer = event.asStartElement().getName();
- attributesBuffer = new XMLAttributes(event.asStartElement().getAttributes());
- level += 1;
- break;
- case XMLEvent.END_ELEMENT:
- // END_ELEMENT(X) => => END TAG
- ended = true;
- result = new XMLTag(event.asEndElement().getName(), TagType.END, null);
- break;
- case XMLEvent.END_DOCUMENT:
- // END_DOCUMENT => END DOCUMENT TAG
- ended = true;
- result = new XMLTag(null, TagType.FOOTER, null);
- break;
- }
- break;
- case 2:
- switch (event.getEventType())
- {
- case XMLEvent.START_ELEMENT:
- // START_ELEMENT(X) + START_ELEMENT(Y) =>
- // => START TAG
- ended = true;
- result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
- this.nextEvent = event;
- break;
- case XMLEvent.CHARACTERS:
- // START_ELEMENT(X) + CHARACTERS(C) => ...
- contentBuffer = new StringList(50);
- contentBuffer.append(event.asCharacters().getData());
- level += 1;
- break;
- case XMLEvent.END_ELEMENT:
- // START_ELEMENT(X) + END_ELEMENT(X) =>
- // => => EMPTY
- ended = true;
- result = new XMLTag(nameBuffer, TagType.EMPTY, attributesBuffer);
- break;
- default:
- throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
- }
- break;
- case 3:
- switch (event.getEventType())
- {
- case XMLEvent.START_ELEMENT:
- // START_ELEMENT(X) + CHARACTERS(C) +
- // START_ELEMENT(Y) =>
- // SPACES => START TAG
- ended = true;
- result = new XMLTag(nameBuffer, TagType.START, attributesBuffer);
- this.nextEvent = event;
- break;
- case XMLEvent.CHARACTERS:
- // START_ELEMENT(X) + CHARACTERS(C1) +
- // CHARACTERS(C2)=> ...
- contentBuffer.append(event.asCharacters().getData());
- break;
- case XMLEvent.END_ELEMENT:
- // START_ELEMENT(X) + CHARACTERS(C) +
- // END_ELEMENT(X) => C
- // => CONTENT TAG
- ended = true;
- result = new XMLTag(nameBuffer, TagType.CONTENT, attributesBuffer);
- result.setContent(contentBuffer.toString());
- break;
- default:
- throw new XMLBadFormatException("Unexpected XMLEvent [" + event.getEventType() + "].");
- }
- break;
- default:
- throw new XMLBadFormatException("Unexpected level [" + level + "].");
- }
- }
- }
+ /**
+ *
+ * @param label
+ * @return
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ */
+ public XMLTag readXMLFooter() throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- logger.debug("=> " + XMLTools.toString(result));
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, end document event is expected.");
+ }
+ else if (result.getType() != TagType.FOOTER)
+ {
+ throw new XMLBadFormatException("End document tag is missing.");
+ }
- /**
- *
- * @param label
- * @return
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- */
- public XMLTag readXMLFooter() throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @return
+ * @throws XMLException
+ * @throws XMLStreamException
+ * @throws XMLBadFormatException
+ */
+ public XMLTag readXMLHeader() throws XMLStreamException, XMLBadFormatException
+ {
+ XMLTag result;
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, end document event is expected.");
- }
- else if (result.getType() != TagType.FOOTER)
- {
- throw new XMLBadFormatException("End document tag is missing.");
- }
+ //
+ result = readTag();
- //
- return result;
- }
+ //
+ if (result == null)
+ {
+ throw new XMLBadFormatException("XML file ends prematurely, start document event is expected.");
+ }
+ else if (result.getType() != TagType.HEADER)
+ {
+ throw new XMLBadFormatException("XML header is missing.");
+ }
- /**
- *
- * @return
- * @throws XMLException
- * @throws XMLStreamException
- * @throws XMLBadFormatException
- */
- public XMLTag readXMLHeader() throws XMLStreamException, XMLBadFormatException
- {
- XMLTag result;
+ //
+ return result;
+ }
- //
- result = readTag();
+ /**
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(final String args[]) throws Exception
+ {
- //
- //
- if (result == null)
- {
- throw new XMLBadFormatException("XML file ends prematurely, start document event is expected.");
- }
- else if (result.getType() != TagType.HEADER)
- {
- throw new XMLBadFormatException("XML header is missing.");
- }
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLEventReader in = factory.createXMLEventReader(new FileReader("/home/cpm/C/Puck/Dev/Puck/test/TT/t3.puc"));
- //
- return result;
- }
+ XMLEvent event;
+ while (in.hasNext())
+ {
+ event = in.nextEvent();
- /**
- *
- * @param args
- * @throws Exception
- */
- public static void main(final String args[]) throws Exception
- {
-
- XMLInputFactory factory = XMLInputFactory.newInstance();
- XMLEventReader in = factory.createXMLEventReader(new FileReader("/home/cpm/C/Puck/Dev/Puck/test/TT/t3.puc"));
-
- XMLEvent event;
- while (in.hasNext())
- {
- event = in.nextEvent();
-
- switch (event.getEventType())
- {
- case XMLEvent.ATTRIBUTE:
- System.out.println("ATTRIBUTE ");
- break;
- case XMLEvent.CDATA:
- System.out.println("CDATA");
- break;
- case XMLEvent.CHARACTERS:
- System.out.println("CHARACTERS [" + event.asCharacters().getData() + "]");
- break;
- case XMLEvent.COMMENT:
- System.out.println("COMMENT");
- break;
- case XMLEvent.DTD:
- System.out.println("DTD");
- break;
- case XMLEvent.END_DOCUMENT:
- System.out.println("END_DOCUMENT");
- break;
- case XMLEvent.END_ELEMENT:
- System.out.println("END_ELEMENT " + event.asEndElement().getName());
- break;
- case XMLEvent.ENTITY_DECLARATION:
- System.out.println("ENTITY_DECLARATION");
- break;
- case XMLEvent.ENTITY_REFERENCE:
- System.out.println("ENTITY_REFERENCE");
- break;
- case XMLEvent.NAMESPACE:
- System.out.println("NAMESPACE");
- break;
- case XMLEvent.NOTATION_DECLARATION:
- System.out.println("NOTATION_DECLARATION");
- break;
- case XMLEvent.PROCESSING_INSTRUCTION:
- System.out.println("PROCESSING_INSTRUCTION");
- break;
- case XMLEvent.SPACE:
- System.out.println("SPACE");
- break;
- case XMLEvent.START_DOCUMENT:
- System.out.println("START_DOCUMENT");
- break;
- case XMLEvent.START_ELEMENT:
- System.out.println("START_ELEMENT [name=" + event.asStartElement().getName() + "][namespaceURI=" + event.asStartElement().getName().getNamespaceURI() + "][prefix="
- + event.asStartElement().getName().getPrefix() + "][localPart=" + event.asStartElement().getName().getLocalPart() + "]");
- break;
- default:
- System.out.println("DEFAULT");
- }
- }
- }
+ switch (event.getEventType())
+ {
+ case XMLEvent.ATTRIBUTE:
+ System.out.println("ATTRIBUTE ");
+ break;
+ case XMLEvent.CDATA:
+ System.out.println("CDATA");
+ break;
+ case XMLEvent.CHARACTERS:
+ System.out.println("CHARACTERS [" + event.asCharacters().getData() + "]");
+ break;
+ case XMLEvent.COMMENT:
+ System.out.println("COMMENT");
+ break;
+ case XMLEvent.DTD:
+ System.out.println("DTD");
+ break;
+ case XMLEvent.END_DOCUMENT:
+ System.out.println("END_DOCUMENT");
+ break;
+ case XMLEvent.END_ELEMENT:
+ System.out.println("END_ELEMENT " + event.asEndElement().getName());
+ break;
+ case XMLEvent.ENTITY_DECLARATION:
+ System.out.println("ENTITY_DECLARATION");
+ break;
+ case XMLEvent.ENTITY_REFERENCE:
+ System.out.println("ENTITY_REFERENCE");
+ break;
+ case XMLEvent.NAMESPACE:
+ System.out.println("NAMESPACE");
+ break;
+ case XMLEvent.NOTATION_DECLARATION:
+ System.out.println("NOTATION_DECLARATION");
+ break;
+ case XMLEvent.PROCESSING_INSTRUCTION:
+ System.out.println("PROCESSING_INSTRUCTION");
+ break;
+ case XMLEvent.SPACE:
+ System.out.println("SPACE");
+ break;
+ case XMLEvent.START_DOCUMENT:
+ System.out.println("START_DOCUMENT");
+ break;
+ case XMLEvent.START_ELEMENT:
+ System.out.println("START_ELEMENT [name=" + event.asStartElement().getName() + "][namespaceURI=" + event.asStartElement().getName().getNamespaceURI() + "][prefix="
+ + event.asStartElement().getName().getPrefix() + "][localPart=" + event.asStartElement().getName().getLocalPart() + "]");
+ break;
+ default:
+ System.out.println("DEFAULT");
+ }
+ }
+ }
}