Project

General

Profile

« Previous | Next » 

Revision 109

Added by bojilova about 24 years ago

document root node, doctype changes

View differences:

DBSAXHandler.java
33 33
{
34 34

  
35 35
   static int elementNo = 0;
36
   static String docname;
37
   private DBSAXDocument currentDocument;
36
   static String docname = null;
38 37
   private String doctype;
39 38
   private String systemid;
40
   private long rootnodeid = 0;
41 39
   private boolean 	debug 	= false;
42 40
   private boolean 	stackCreated = false;
43 41
   private Stack 	elementStack;
......
69 67
   /** SAX Handler that receives notification of end of the document */
70 68
   public void endDocument() throws SAXException
71 69
   {
72
    currentDocument.setTitleFromChildElement();
73
    System.out.println(currentDocument.getTitle());
74 70
    System.out.println("end Document");
75 71
   }
76 72

  
77 73
   /** SAX Handler that receives notification of DTD. Sets the DTD */
78 74
   public void setDoctype(DTD dtd) throws SAXException
79 75
   {
80
    // here is a bug: dtd.getPublicId() and dtd.getSustemId() return null.
76
    // here is a bug: dtd.getPublicId() and dtd.getSustemId() always return null.
81 77
    docname = dtd.getName();
82 78
    doctype = dtd.getPublicId();
83 79
    systemid = dtd.getSystemId();
84 80
    System.out.println("DOCNAME: " + docname);
85 81
    System.out.println("DOCTYPE: " + doctype);
86 82
    System.out.println("  SYSID: " + systemid);
83

  
84
    // Create the document node represantation as root
85
    DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0);
86
    // Add the element to the stack, so that any text data can be 
87
    // added as it is encountered
88
    elementStack.push(documentNode);
87 89
   }
88 90

  
89 91
   /** SAX Handler that receives notification of end of DTD 
......
93 95
   public void endDoctype() throws SAXException
94 96
   {
95 97
    System.out.println("end of DOCTYPE");
96
    if (doctype == null) {
97
        doctype = DBEntityResolver.doctype;
98
        //if (doctype == null) 
99
        //    doctype = docname;
100
    }
98
    //if (doctype == null)
99
    //    doctype = DBEntityResolver.doctype;
100
    //DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
101
    //new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype);
101 102
   }
102 103

  
103 104
   /** SAX Handler that is called at the start of each XML element */
......
121 122
      expName = name.getExpandedName();
122 123
      
123 124
      elementNo++;
124
      if (docname == null)
125
        throw new SAXException("No DOCTYPE declaration provided");
126 125
      // Get a reference to the parent element for the id
127 126
      long parent_id;
128 127
      int nodeIndex;
......
135 134
        nodeIndex = 0;
136 135
      }
137 136

  
137
      // Document representation that points to the root document node
138
      if (elementNo == 1) {
139
        // If no DOCTYPE declaration: docname = root element name 
140
        if (docname == null)
141
            docname = localName;
142
        else if (doctype == null)
143
            doctype = DBEntityResolver.doctype;
144
        DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
145
        new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype);
146
      }      
138 147
      // Create the current element representation
139 148
      currentElement = new DBSAXElement(conn, localName, parent_id, nodeIndex);
140 149
      // go to create document definition in the db
141 150
      // call once after insertion of the first element
142 151
      if (parent_id == 0) {
143
        this.rootnodeid = currentElement.getElementID();
144
        currentDocument = new DBSAXDocument(conn, rootnodeid, docname, doctype);
152
        long rootnodeid = currentElement.getElementID();
153
        new DBSAXDocument(conn, rootnodeid, docname, doctype);
145 154
      }
146 155

  
147 156
      // Add all of the attributes
......
192 201
     * For now works only for comments after the root element. */
193 202
   public void comment(String data) throws SAXException
194 203
   {
195
    if (elementNo > 0) {
204
    //if (elementNo > 0) {
196 205
      DBSAXElement currentElement = (DBSAXElement)elementStack.peek();
197 206
      int nodeIndex = currentElement.incChildNum();
198 207
      currentElement.writeCommentToDB(data, nodeIndex);
199
    }
208
    //}
200 209
   }
201 210
   public void processingInstruction(String target, String data) throws SAXException
202 211
   {
203
    if (elementNo == 0)
204
        System.out.println("target:" + target + "\ndata:" + data);
205
    else if (elementNo > 0)
206
        System.out.println("targetHere:" + target + "\ndata:" + data);
212
      DBSAXElement currentElement = (DBSAXElement)elementStack.peek();
213
      int nodeIndex = currentElement.incChildNum();
214
      currentElement.writePIToDB(target, data, nodeIndex);
207 215
   }
208 216

  
209 217
   /** SAX Handler that is called at the end of each XML element */

Also available in: Unified diff