3 |
|
|
4 |
|
import org.xml.sax.*; |
5 |
|
|
6 |
< |
import javax.xml.parsers.SAXParserFactory; |
7 |
< |
import javax.xml.parsers.ParserConfigurationException; |
8 |
< |
import javax.xml.parsers.SAXParser; |
6 |
> |
import javax.xml.parsers.SAXParserFactory; |
7 |
> |
import javax.xml.parsers.ParserConfigurationException; |
8 |
> |
import javax.xml.parsers.SAXParser; |
9 |
|
|
10 |
+ |
// Paul Mutton, pjm2@ukc.ac.uk |
11 |
|
|
12 |
+ |
// XMLPacketMaker - Creates an XMLPacket object. |
13 |
|
public class XMLPacketMaker extends HandlerBase { |
14 |
|
|
15 |
|
public XMLPacketMaker () { |
40 |
|
SAXParser saxParser = factory.newSAXParser(); |
41 |
|
saxParser.parse(new File(args[0]), new XMLPacketMaker(packet)); |
42 |
|
|
43 |
< |
// Print out some things from the packet: - |
44 |
< |
|
43 |
> |
// By means of example, print out some things from the packet: - |
44 |
> |
System.out.println("bung.wibble="+packet.getParam("bung.wibble")); |
45 |
> |
System.out.println("bung.ping.value1="+packet.getParam("bung.ping.value1")); |
46 |
|
|
47 |
+ |
// Print out the entire contents of the packet. |
48 |
+ |
packet.printAll(); |
49 |
+ |
|
50 |
|
} catch (Throwable t) { |
51 |
|
t.printStackTrace (); |
52 |
|
} |
115 |
|
String s = new String(buf, offset, len); |
116 |
|
if (!s.trim().equals("")) { |
117 |
|
emit (s); |
118 |
< |
packet.addParam((String)tagList.get(tagList.size()-1), s); |
118 |
> |
packet.addParam(getPath(), s); |
119 |
|
} |
120 |
|
} |
121 |
|
|
144 |
|
} catch (IOException e) { |
145 |
|
throw new SAXException ("I/O error", e); |
146 |
|
} |
147 |
+ |
} |
148 |
+ |
|
149 |
+ |
// Return the heirarchical string to be used as a key value |
150 |
+ |
// in the XMLPacket. |
151 |
+ |
private String getPath () { |
152 |
+ |
String path = (String)tagList.get(0); |
153 |
+ |
if (tagList.size() > 0) { |
154 |
+ |
for (int i = 1 ; i < tagList.size() ; i++) { |
155 |
+ |
path = path + "." + (String)tagList.get(i); |
156 |
+ |
} |
157 |
+ |
} |
158 |
+ |
return path; |
159 |
|
} |
160 |
|
} |