ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/XMLStringParser.java
(Generate patch)

Comparing projects/cms/source/util/uk/org/iscream/cms/util/XMLStringParser.java (file contents):
Revision 1.8 by tdb, Sat Mar 10 00:49:39 2001 UTC vs.
Revision 1.10 by tdb, Sat Mar 10 04:03:52 2001 UTC

# Line 4 | Line 4 | package uk.ac.ukc.iscream.util;
4   //---IMPORTS---
5   import java.io.*;
6   import java.util.ArrayList;
7
7   import org.xml.sax.*;
8   import org.xml.sax.helpers.*;
9 < import javax.xml.parsers.SAXParserFactory;
11 < import javax.xml.parsers.ParserConfigurationException;
12 < import javax.xml.parsers.SAXParser;
9 > import javax.xml.parsers.*;
10  
11   /**
12   * XMLStringParser - Used to assist in creating XMLPacket objects.
# Line 34 | Line 31 | public class XMLStringParser extends DefaultHandler {
31       * No-args constructor.  Generally not used.
32       */
33      public XMLStringParser () {
34 <        this.packet = new XMLPacket();
34 >        _packet = new XMLPacket();
35      }
36  
37      /**
38       * Constructor for accepting a reference to an XMLPacket
39       */
40      public XMLStringParser (XMLPacket packet) {
41 <        this.packet = packet;
41 >        _packet = packet;
42      }
43  
44   //---PUBLIC METHODS---
45  
49    /**
50     * Accessor to the XMLPacket.
51     */
52    public XMLPacket getXMLPacket() {
53        return packet;
54    }
55
46      //===========================================================
47      // SAX DocumentHandler methods
48      //===========================================================
49  
50 <    public void startDocument () throws SAXException {
51 <        //System.out.println("XMLPacketParser - Starting parse process...");
62 <    }
63 <
64 <    public void endDocument () throws SAXException {
65 <        //System.out.println("XMLPacketParser - I just finished parsing an XML String.");
66 <    }
67 <
68 <    /** Add each tag's attribute to the XMLPacket.
50 >    /**
51 >     * Add each tag's attribute to the XMLPacket.
52       * Note that all attributes within an opening tag are
53       * stored as "someroot.sometag.attributes.attribute_name"
54       * E.g. If <packet> is the root node, then:
# Line 74 | Line 57 | public class XMLStringParser extends DefaultHandler {
57       *     "packet.attributes.machine_name"
58       * within the XMLPacket.
59       */
60 <    public void startElement (String name, Attributes attrs) throws SAXException {
61 <        indentLevel++;
62 <        tagList.add(name);
63 <        if (attrs != null) {
64 <            for (int i = 0; i < attrs.getLength (); i++) {
65 <                packet.addParam(getPath()+".attributes."+attrs.getLocalName(i), attrs.getValue(i));
60 >    public void startElement (String uri, String name, String qName, Attributes atts) {
61 >            _indentLevel++;
62 >        _tagList.add(name);
63 >        if (atts != null) {
64 >            for (int i = 0; i < atts.getLength (); i++) {
65 >                _packet.addParam(getPath()+".attributes."+atts.getLocalName(i), atts.getValue(i));
66              }
67          }
68      }
69 <
69 >    
70      /**
71       * When an XML element is finished with, we must remove
72       * the tag name from the tagList and decrement the indent
73       * level.
74       */
75 <    public void endElement (String name) throws SAXException {
76 <        tagList.remove(tagList.size()-1);    
77 <        indentLevel--;
75 >    public void endElement (String uri, String name, String qName) {
76 >            _tagList.remove(_tagList.size() - 1);    
77 >        _indentLevel--;
78      }
79 <
79 >    
80      /**
81       * Any text falling within a pair of terminal tags must
82       * be added to the XMLPacket.  Trim leading and trailing
# Line 102 | Line 85 | public class XMLStringParser extends DefaultHandler {
85       */
86      public void characters (char[] buf, int offset, int len) throws SAXException {
87          String s = new String(buf, offset, len);
88 <        packet.addParam(getPath(), s);
88 >        _packet.addParam(getPath(), s);
89      }
90  
91      /**
# Line 132 | Line 115 | public class XMLStringParser extends DefaultHandler {
115       * in the XMLPacket.
116       */
117      private String getPath () {
118 <        String path = (String)tagList.get(0);
119 <        if (tagList.size() > 0) {
120 <            for (int i = 1 ; i < tagList.size() ; i++) {
121 <                path = path + "." + (String)tagList.get(i);
118 >        String path = (String) _tagList.get(0);
119 >        if (_tagList.size() > 0) {
120 >            for (int i = 1 ; i < _tagList.size() ; i++) {
121 >                path = path + "." + (String) _tagList.get(i);
122              }
123          }
124          return path;
# Line 143 | Line 126 | public class XMLStringParser extends DefaultHandler {
126  
127   //---ACCESSOR/MUTATOR METHODS---
128  
129 +    /**
130 +     * Accessor to the XMLPacket.
131 +     */
132 +    public XMLPacket getXMLPacket() {
133 +        return _packet;
134 +    }
135 +
136   //---ATTRIBUTES---
137  
138      /**
139       * To keep track of our identation level
140       */
141 <    private int indentLevel = 0;
141 >    private int _indentLevel = 0;
142      
143      /**
144       * An ArrayList of tags
145       */
146 <    private ArrayList tagList = new ArrayList();
146 >    private ArrayList _tagList = new ArrayList();
147      
148      /**
149       * A reference to the XMLPacket we are making
150       */
151 <    private XMLPacket packet;
151 >    private XMLPacket _packet;
152      
153      /**
154       * This is the friendly identifier of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines