1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.util; |
2 |
> |
package uk.org.iscream.cms.server.util; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.io.*; |
6 |
< |
import java.util.ArrayList; |
7 |
< |
|
6 |
> |
import java.util.LinkedList; |
7 |
> |
import java.util.Iterator; |
8 |
|
import org.xml.sax.*; |
9 |
|
import org.xml.sax.helpers.*; |
10 |
< |
import javax.xml.parsers.SAXParserFactory; |
11 |
< |
import javax.xml.parsers.ParserConfigurationException; |
12 |
< |
import javax.xml.parsers.SAXParser; |
10 |
> |
import javax.xml.parsers.*; |
11 |
|
|
12 |
|
/** |
13 |
|
* XMLStringParser - Used to assist in creating XMLPacket objects. |
44 |
|
|
45 |
|
//---PUBLIC METHODS--- |
46 |
|
|
49 |
– |
/** |
50 |
– |
* Accessor to the XMLPacket. |
51 |
– |
*/ |
52 |
– |
public XMLPacket getXMLPacket() { |
53 |
– |
return _packet; |
54 |
– |
} |
55 |
– |
|
47 |
|
//=========================================================== |
48 |
|
// SAX DocumentHandler methods |
49 |
|
//=========================================================== |
59 |
|
* within the XMLPacket. |
60 |
|
*/ |
61 |
|
public void startElement (String uri, String name, String qName, Attributes atts) { |
62 |
< |
_indentLevel++; |
72 |
< |
_tagList.add(name); |
62 |
> |
_tagList.addLast(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 uri, String name, String qName) { |
76 |
< |
_tagList.remove(_tagList.size() - 1); |
87 |
< |
_indentLevel--; |
76 |
> |
_tagList.removeLast(); |
77 |
|
} |
78 |
< |
|
90 |
< |
|
78 |
> |
|
79 |
|
/** |
80 |
|
* Any text falling within a pair of terminal tags must |
81 |
|
* be added to the XMLPacket. Trim leading and trailing |
91 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
92 |
|
* method to provide clean logging (every class should have this). |
93 |
|
* |
94 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
94 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
95 |
|
* to format the toString() |
96 |
|
* |
97 |
|
* @return the name of this class and its CVS revision |
114 |
|
* in the XMLPacket. |
115 |
|
*/ |
116 |
|
private String getPath () { |
117 |
< |
String path = (String) _tagList.get(0); |
117 |
> |
String path = ""; |
118 |
|
if (_tagList.size() > 0) { |
119 |
< |
for (int i = 1 ; i < _tagList.size() ; i++) { |
120 |
< |
path = path + "." + (String) _tagList.get(i); |
119 |
> |
Iterator i = _tagList.iterator(); |
120 |
> |
path = (String) i.next(); |
121 |
> |
while(i.hasNext()) { |
122 |
> |
path = path + "." + (String) i.next(); |
123 |
|
} |
124 |
|
} |
125 |
|
return path; |
127 |
|
|
128 |
|
//---ACCESSOR/MUTATOR METHODS--- |
129 |
|
|
140 |
– |
//---ATTRIBUTES--- |
141 |
– |
|
130 |
|
/** |
131 |
< |
* To keep track of our identation level |
132 |
< |
*/ |
133 |
< |
private int _indentLevel = 0; |
131 |
> |
* Accessor to the XMLPacket. |
132 |
> |
*/ |
133 |
> |
public XMLPacket getXMLPacket() { |
134 |
> |
return _packet; |
135 |
> |
} |
136 |
> |
|
137 |
> |
//---ATTRIBUTES--- |
138 |
|
|
139 |
|
/** |
140 |
< |
* An ArrayList of tags |
140 |
> |
* A LinkedList of tags |
141 |
|
*/ |
142 |
< |
private ArrayList _tagList = new ArrayList(); |
142 |
> |
private LinkedList _tagList = new LinkedList(); |
143 |
|
|
144 |
|
/** |
145 |
|
* A reference to the XMLPacket we are making |