--- projects/cms/source/util/uk/org/iscream/cms/util/XMLStringParser.java 2001/03/14 23:25:30 1.11 +++ projects/cms/source/util/uk/org/iscream/cms/util/XMLStringParser.java 2002/05/21 16:47:20 1.16 @@ -1,9 +1,30 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + //---PACKAGE DECLARATION--- -package uk.org.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.*; @@ -12,7 +33,7 @@ import javax.xml.parsers.*; * XMLStringParser - Used to assist in creating XMLPacket objects. * * @author $Author: tdb $ - * @version $Id: XMLStringParser.java,v 1.11 2001/03/14 23:25:30 tdb Exp $ + * @version $Id: XMLStringParser.java,v 1.16 2002/05/21 16:47:20 tdb Exp $ */ public class XMLStringParser extends DefaultHandler { @@ -21,7 +42,7 @@ public class XMLStringParser extends DefaultHandler { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.11 $"; + public final String REVISION = "$Revision: 1.16 $"; //---STATIC METHODS--- @@ -58,11 +79,10 @@ 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(qName); if (atts != null) { for (int i = 0; i < atts.getLength (); i++) { - _packet.addParam(getPath()+".attributes."+atts.getLocalName(i), atts.getValue(i)); + _packet.addParam(getPath()+".attributes."+atts.getQName(i), atts.getValue(i)); } } } @@ -73,8 +93,7 @@ public class XMLStringParser extends DefaultHandler { * level. */ public void endElement (String uri, String name, String qName) { - _tagList.remove(_tagList.size() - 1); - _indentLevel--; + _tagList.removeLast(); } /** @@ -92,7 +111,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.org.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 @@ -115,10 +134,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; @@ -134,16 +155,11 @@ public class XMLStringParser extends DefaultHandler { } //---ATTRIBUTES--- - - /** - * To keep track of our identation level - */ - private int _indentLevel = 0; /** - * 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