--- projects/cms/source/util/uk/org/iscream/cms/util/XMLStringParser.java 2001/03/10 02:03:55 1.9 +++ projects/cms/source/util/uk/org/iscream/cms/util/XMLStringParser.java 2001/05/29 17:02:35 1.13 @@ -1,21 +1,19 @@ //---PACKAGE DECLARATION--- -package uk.ac.ukc.iscream.util; +package uk.org.iscream.cms.server.util; //---IMPORTS--- import java.io.*; -import java.util.ArrayList; - +import java.util.LinkedList; +import java.util.Iterator; import org.xml.sax.*; import org.xml.sax.helpers.*; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; +import javax.xml.parsers.*; /** * XMLStringParser - Used to assist in creating XMLPacket objects. * * @author $Author: tdb $ - * @version $Id: XMLStringParser.java,v 1.9 2001/03/10 02:03:55 tdb Exp $ + * @version $Id: XMLStringParser.java,v 1.13 2001/05/29 17:02:35 tdb Exp $ */ public class XMLStringParser extends DefaultHandler { @@ -24,7 +22,7 @@ public class XMLStringParser extends DefaultHandler { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.9 $"; + public final String REVISION = "$Revision: 1.13 $"; //---STATIC METHODS--- @@ -46,13 +44,6 @@ public class XMLStringParser extends DefaultHandler { //---PUBLIC METHODS--- - /** - * Accessor to the XMLPacket. - */ - public XMLPacket getXMLPacket() { - return _packet; - } - //=========================================================== // SAX DocumentHandler methods //=========================================================== @@ -68,26 +59,23 @@ public class XMLStringParser extends DefaultHandler { * within the XMLPacket. */ public void startElement (String uri, String name, String qName, Attributes atts) { - _indentLevel++; - _tagList.add(name); + _tagList.addLast(name); if (atts != null) { for (int i = 0; i < atts.getLength (); i++) { _packet.addParam(getPath()+".attributes."+atts.getLocalName(i), atts.getValue(i)); } } } - + /** * When an XML element is finished with, we must remove * the tag name from the tagList and decrement the indent * level. */ public void endElement (String uri, String name, String qName) { - _tagList.remove(_tagList.size() - 1); - _indentLevel--; + _tagList.removeLast(); } - - + /** * Any text falling within a pair of terminal tags must * be added to the XMLPacket. Trim leading and trailing @@ -103,7 +91,7 @@ public class XMLStringParser extends DefaultHandler { * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * - * This uses the uk.ac.ukc.iscream.util.NameFormat class + * This uses the uk.org.iscream.cms.server.util.NameFormat class * to format the toString() * * @return the name of this class and its CVS revision @@ -126,10 +114,12 @@ public class XMLStringParser extends DefaultHandler { * in the XMLPacket. */ private String getPath () { - String path = (String) _tagList.get(0); + String path = ""; if (_tagList.size() > 0) { - for (int i = 1 ; i < _tagList.size() ; i++) { - path = path + "." + (String) _tagList.get(i); + Iterator i = _tagList.iterator(); + path = (String) i.next(); + while(i.hasNext()) { + path = path + "." + (String) i.next(); } } return path; @@ -137,17 +127,19 @@ public class XMLStringParser extends DefaultHandler { //---ACCESSOR/MUTATOR METHODS--- -//---ATTRIBUTES--- - /** - * To keep track of our identation level - */ - private int _indentLevel = 0; + * Accessor to the XMLPacket. + */ + public XMLPacket getXMLPacket() { + return _packet; + } + +//---ATTRIBUTES--- /** - * An ArrayList of tags + * A LinkedList of tags */ - private ArrayList _tagList = new ArrayList(); + private LinkedList _tagList = new LinkedList(); /** * A reference to the XMLPacket we are making