ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/XMLReader/XMLPacketMaker.java
(Generate patch)

Comparing experimental/server/XMLReader/XMLPacketMaker.java (file contents):
Revision 1.3 by pjm2, Tue Nov 14 09:32:31 2000 UTC vs.
Revision 1.5 by pjm2, Tue Nov 14 10:04:01 2000 UTC

# Line 9 | Line 9 | import javax.xml.parsers.SAXParser;  
9  
10  
11   public class XMLPacketMaker extends HandlerBase {
12 +
13 +    public XMLPacketMaker () {
14 +        // default no-args constructor.
15 +    }
16 +
17 +    // Constructor for accepting a reference to an XMLPacket
18 +    public XMLPacketMaker (XMLPacket packet) {
19 +        this.packet = packet;
20 +    }
21 +
22      public static void main(String[] args){
23          if (args.length != 1) {
24              System.err.println ("Usage: cmd filename");
# Line 21 | Line 31 | public class XMLPacketMaker extends HandlerBase {
31              // Set up output stream
32              out = new OutputStreamWriter (System.out, "UTF8");
33  
34 +            // Create the XMLPacket to store values in.
35 +            packet = new XMLPacket();
36 +
37              // Parse the input
38              SAXParser saxParser = factory.newSAXParser();
39 <            saxParser.parse(new File(args[0]), new XMLPacketMaker());
39 >            saxParser.parse(new File(args[0]), new XMLPacketMaker(packet));
40  
41 +            // Print out some things from the packet: -
42 +            
43 +
44          } catch (Throwable t) {
45              t.printStackTrace ();
46          }
# Line 35 | Line 51 | public class XMLPacketMaker extends HandlerBase {
51      private String indentString = "    "; // Amount to indent
52      private int indentLevel = 0;
53  
54 +    // For storing the tag heirarchy.
55      private ArrayList tagList = new ArrayList();
56 +    static private XMLPacket packet = null;
57  
58      //===========================================================
59      // SAX DocumentHandler methods
# Line 61 | Line 79 | public class XMLPacketMaker extends HandlerBase {
79  
80      public void startElement (String name, AttributeList attrs) throws SAXException {
81          indentLevel++;
82 +        tagList.add(name);
83          nl(); emit ("ELEMENT: ");
84          emit ("<"+name);
85          if (attrs != null) {
# Line 81 | Line 100 | public class XMLPacketMaker extends HandlerBase {
100          nl();
101          emit ("END_ELM: ");
102          emit ("</"+name+">");
103 +        tagList.remove(tagList.size()-1);    
104          indentLevel--;
105      }
106  
107      public void characters (char[] buf, int offset, int len) throws SAXException {
108          nl(); emit ("CHARS:   ");
109          String s = new String(buf, offset, len);
110 <        if (!s.trim().equals("")) emit (s);
110 >        if (!s.trim().equals("")) {
111 >            emit (s);
112 >            packet.addParam((String)tagList.get(tagList.size()-1), s);
113 >        }
114      }
115  
116      //===========================================================

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines