Revision 137
Added by Matt Jones almost 24 years ago
DBSAXHandler.java | ||
---|---|---|
37 | 37 |
private String systemid; |
38 | 38 |
private boolean debug = false; |
39 | 39 |
private boolean stackCreated = false; |
40 |
private Stack elementStack;
|
|
40 |
private Stack nodeStack;
|
|
41 | 41 |
private Connection conn = null; |
42 | 42 |
|
43 | 43 |
/** Construct an instance of the handler class |
... | ... | |
47 | 47 |
public DBSAXHandler(Connection conn) { |
48 | 48 |
this.conn = conn; |
49 | 49 |
|
50 |
// Create the stack for keeping track of element context
|
|
50 |
// Create the stack for keeping track of node context
|
|
51 | 51 |
// if it doesn't already exist |
52 | 52 |
if (!stackCreated) { |
53 |
elementStack = new Stack();
|
|
53 |
nodeStack = new Stack();
|
|
54 | 54 |
stackCreated = true; |
55 | 55 |
} |
56 | 56 |
|
... | ... | |
62 | 62 |
System.out.println("start Document"); |
63 | 63 |
} |
64 | 64 |
// Create the document node represantation as root |
65 |
DBSAXElement documentNode = new DBSAXElement(conn, docname);
|
|
66 |
// Add the element to the stack, so that any text data can be
|
|
65 |
DBSAXNode documentNode = new DBSAXNode(conn, docname);
|
|
66 |
// Add the node to the stack, so that any text data can be
|
|
67 | 67 |
// added as it is encountered |
68 |
elementStack.push(documentNode);
|
|
68 |
nodeStack.push(documentNode);
|
|
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
/** SAX Handler that receives notification of end of the document */ |
... | ... | |
114 | 114 |
String localName; |
115 | 115 |
String nsName; |
116 | 116 |
String expName; |
117 |
DBSAXElement parentElement = null;
|
|
118 |
DBSAXElement currentElement = null;
|
|
117 |
DBSAXNode parentNode = null;
|
|
118 |
DBSAXNode currentNode = null;
|
|
119 | 119 |
|
120 | 120 |
qName = name.getQualifiedName(); |
121 | 121 |
localName = name.getLocalName(); |
... | ... | |
123 | 123 |
expName = name.getExpandedName(); |
124 | 124 |
|
125 | 125 |
elementNo++; |
126 |
// Get a reference to the parent element for the id
|
|
126 |
// Get a reference to the parent node for the id
|
|
127 | 127 |
try { |
128 |
parentElement = (DBSAXElement)elementStack.peek();
|
|
128 |
parentNode = (DBSAXNode)nodeStack.peek();
|
|
129 | 129 |
} catch (EmptyStackException e) { |
130 | 130 |
} |
131 | 131 |
|
... | ... | |
137 | 137 |
} else if (doctype == null) { |
138 | 138 |
doctype = DBEntityResolver.doctype; |
139 | 139 |
} |
140 |
DBSAXElement documentNode = (DBSAXElement)elementStack.peek();
|
|
140 |
DBSAXNode documentNode = (DBSAXNode)nodeStack.peek();
|
|
141 | 141 |
documentNode.writeNodename(docname); |
142 | 142 |
new DBSAXDocument(conn, documentNode.getNodeID(), docname, doctype); |
143 | 143 |
} |
144 | 144 |
|
145 |
// Create the current element representation
|
|
146 |
currentElement = new DBSAXElement(conn, localName, parentElement);
|
|
145 |
// Create the current node representation
|
|
146 |
currentNode = new DBSAXNode(conn, localName, parentNode);
|
|
147 | 147 |
|
148 | 148 |
// Add all of the attributes |
149 | 149 |
for (int i=0; i<atts.getLength(); i++) |
... | ... | |
164 | 164 |
String type = atts.getType(qName); |
165 | 165 |
String value = atts.getValue(qName); |
166 | 166 |
|
167 |
currentElement.setAttribute(localName, value);
|
|
167 |
currentNode.setAttribute(localName, value);
|
|
168 | 168 |
} |
169 | 169 |
|
170 |
// Add the element to the stack, so that any text data can be
|
|
170 |
// Add the node to the stack, so that any text data can be
|
|
171 | 171 |
// added as it is encountered |
172 |
elementStack.push(currentElement);
|
|
172 |
nodeStack.push(currentNode);
|
|
173 | 173 |
|
174 | 174 |
} |
175 | 175 |
|
176 | 176 |
/** SAX Handler that is called for each XML text node */ |
177 | 177 |
public void characters(char[] cbuf, int start, int len) { |
178 |
DBSAXElement currentElement = (DBSAXElement)elementStack.peek();
|
|
178 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
|
|
179 | 179 |
String data = new String(cbuf, start, len); |
180 | 180 |
|
181 |
// Write the content of the element to the database
|
|
182 |
currentElement.writeChildNodeToDB("TEXT", null, data);
|
|
181 |
// Write the content of the node to the database
|
|
182 |
currentNode.writeChildNodeToDB("TEXT", null, data);
|
|
183 | 183 |
} |
184 | 184 |
|
185 | 185 |
/** |
... | ... | |
192 | 192 |
/** |
193 | 193 |
* SAX Handler called once for each comment found: |
194 | 194 |
* node that comment may occur before or after the root element. |
195 |
* For now works only for comments after the root element. |
|
196 | 195 |
*/ |
197 | 196 |
public void comment(String data) throws SAXException { |
198 |
DBSAXElement currentElement = (DBSAXElement)elementStack.peek();
|
|
199 |
currentElement.writeChildNodeToDB("COMMENT", null, data);
|
|
197 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
|
|
198 |
currentNode.writeChildNodeToDB("COMMENT", null, data);
|
|
200 | 199 |
} |
201 | 200 |
|
202 | 201 |
/** |
... | ... | |
205 | 204 |
*/ |
206 | 205 |
public void processingInstruction(String target, String data) |
207 | 206 |
throws SAXException { |
208 |
DBSAXElement currentElement = (DBSAXElement)elementStack.peek();
|
|
209 |
currentElement.writeChildNodeToDB("PI", target, data);
|
|
207 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
|
|
208 |
currentNode.writeChildNodeToDB("PI", target, data);
|
|
210 | 209 |
} |
211 | 210 |
|
212 | 211 |
/** SAX Handler that is called at the end of each XML element */ |
... | ... | |
216 | 215 |
// information. |
217 | 216 |
String expName = name.getExpandedName(); |
218 | 217 |
|
219 |
// Get the element from the stack
|
|
220 |
DBSAXElement currentElement = (DBSAXElement)elementStack.pop();
|
|
218 |
// Get the node from the stack
|
|
219 |
DBSAXNode currentNode = (DBSAXNode)nodeStack.pop();
|
|
221 | 220 |
} |
222 | 221 |
|
223 | 222 |
/** Debug routine */ |
Also available in: Unified diff
Renamed DBSAXElement to DBSAXNode