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.3 by tdb, Wed Nov 29 19:11:53 2000 UTC vs.
Revision 1.7 by pjm2, Mon Jan 29 15:36:33 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.xml;
2 > package uk.ac.ukc.iscream.util;
3  
4   //---IMPORTS---
5   import java.io.*;
# Line 29 | Line 29 | public class XMLStringParser extends HandlerBase {
29  
30   //---CONSTRUCTORS---
31  
32 <    // No-args constructor.  Generally not used.
32 >    /**
33 >     * No-args constructor.  Generally not used.
34 >     */
35      public XMLStringParser () {
36          this.packet = new XMLPacket();
37      }
38  
39 <    // Constructor for accepting a reference to an XMLPacket
39 >    /**
40 >     * Constructor for accepting a reference to an XMLPacket
41 >     */
42      public XMLStringParser (XMLPacket packet) {
43          this.packet = packet;
44      }
45  
46   //---PUBLIC METHODS---
47  
48 <    // Accessor to the XMLPacket.
48 >    /**
49 >     * Accessor to the XMLPacket.
50 >     */
51      public XMLPacket getXMLPacket() {
52          return packet;
53      }
# Line 58 | Line 64 | public class XMLStringParser extends HandlerBase {
64          //System.out.println("XMLPacketParser - I just finished parsing an XML String.");
65      }
66  
67 <    // Add each tag's attribute to the XMLPacket.
68 <    // Note that all attributes within an opening tag are
69 <    // stored as "someroot.sometag.attributes.attribute_name"
70 <    // E.g. If <packet> is the root node, then:
71 <    //     <packet machine_name="raptor">
72 <    // is stored as:
73 <    //     "packet.attributes.machine_name"
74 <    // within the XMLPacket.
67 >    /** Add each tag's attribute to the XMLPacket.
68 >     * Note that all attributes within an opening tag are
69 >     * stored as "someroot.sometag.attributes.attribute_name"
70 >     * E.g. If <packet> is the root node, then:
71 >     *     <packet machine_name="raptor">
72 >     * is stored as:
73 >     *     "packet.attributes.machine_name"
74 >     * within the XMLPacket.
75 >     */
76      public void startElement (String name, AttributeList attrs) throws SAXException {
77          indentLevel++;
78          tagList.add(name);
# Line 76 | Line 83 | public class XMLStringParser extends HandlerBase {
83          }
84      }
85  
86 <    // When an XML element is finished with, we must remove
87 <    // the tag name from the tagList and decrement the indent
88 <    // level.
86 >    /**
87 >     * When an XML element is finished with, we must remove
88 >     * the tag name from the tagList and decrement the indent
89 >     * level.
90 >     */
91      public void endElement (String name) throws SAXException {
92          tagList.remove(tagList.size()-1);    
93          indentLevel--;
94      }
95  
96 <    // Any text falling within a pair of terminal tags must
97 <    // be added to the XMLPacket.  Trim leading and trailing
98 <    // spaces and do not bother to add if there is no data
99 <    // specified within the tags.
96 >    /**
97 >     * Any text falling within a pair of terminal tags must
98 >     * be added to the XMLPacket.  Trim leading and trailing
99 >     * spaces and do not bother to add if there is no data
100 >     * specified within the tags.
101 >     */
102      public void characters (char[] buf, int offset, int len) throws SAXException {
103          String s = new String(buf, offset, len);
104 <        if (!s.trim().equals("")) {
94 <            packet.addParam(getPath(), s);
95 <        }
104 >        packet.addParam(getPath(), s);
105      }
106  
107      /**
108       * Overrides the {@link java.lang.Object#toString() Object.toString()}
109       * method to provide clean logging (every class should have this).
110       *
111 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
112 +     * to format the toString()
113 +     *
114       * @return the name of this class and its CVS revision
115       */
116      public String toString() {
117 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
117 >        return FormatName.getName(
118 >            _name,
119 >            getClass().getName(),
120 >            REVISION);
121      }
122  
123   //---PRIVATE METHODS---
# Line 111 | Line 126 | public class XMLStringParser extends HandlerBase {
126      // Helpers ...
127      //===========================================================
128      
129 <    
130 <    // Return the heirarchical string to be used as a key value
131 <    // in the XMLPacket.
129 >    /**
130 >     * Return the heirarchical string to be used as a key value
131 >     * in the XMLPacket.
132 >     */
133      private String getPath () {
134          String path = (String)tagList.get(0);
135          if (tagList.size() > 0) {
# Line 128 | Line 144 | public class XMLStringParser extends HandlerBase {
144  
145   //---ATTRIBUTES---
146  
147 +    /**
148 +     * To keep track of our identation level
149 +     */
150      private int indentLevel = 0;
151 +    
152 +    /**
153 +     * An ArrayList of tags
154 +     */
155      private ArrayList tagList = new ArrayList();
156 +    
157 +    /**
158 +     * A reference to the XMLPacket we are making
159 +     */
160      private XMLPacket packet;
161 +    
162 +    /**
163 +     * This is the friendly identifier of the
164 +     * component this class is running in.
165 +     * eg, a Filter may be called "filter1",
166 +     * If this class does not have an owning
167 +     * component,  a name from the configuration
168 +     * can be placed here.  This name could also
169 +     * be changed to null for utility classes.
170 +     */
171 +    private String _name = null;
172  
173   //---STATIC ATTRIBUTES---
174  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines