Revision 122
Added by Matt Jones over 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
29 | 29 |
* A database aware Class implementing callback bethods for the SAX parser to |
30 | 30 |
* call when processing the XML stream and generating events |
31 | 31 |
*/ |
32 |
public class DBSAXHandler extends DefaultXMLDocumentHandler |
|
33 |
{ |
|
32 |
public class DBSAXHandler extends DefaultXMLDocumentHandler { |
|
34 | 33 |
|
35 | 34 |
static int elementNo = 0; |
36 | 35 |
static String docname = null; |
... | ... | |
45 | 44 |
* |
46 | 45 |
* @param conn the JDBC connection to which information is written |
47 | 46 |
*/ |
48 |
public DBSAXHandler(Connection conn) |
|
49 |
{ |
|
47 |
public DBSAXHandler(Connection conn) { |
|
50 | 48 |
this.conn = conn; |
51 | 49 |
|
52 | 50 |
// Create the stack for keeping track of element context |
... | ... | |
59 | 57 |
} |
60 | 58 |
|
61 | 59 |
/** SAX Handler that receives notification of beginning of the document */ |
62 |
public void startDocument() throws SAXException |
|
63 |
{ |
|
64 |
System.out.println("start Document"); |
|
60 |
public void startDocument() throws SAXException { |
|
61 |
if (debug) { |
|
62 |
System.out.println("start Document"); |
|
63 |
} |
|
65 | 64 |
// Create the document node represantation as root |
66 | 65 |
DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0); |
67 | 66 |
// Add the element to the stack, so that any text data can be |
... | ... | |
70 | 69 |
} |
71 | 70 |
|
72 | 71 |
/** SAX Handler that receives notification of end of the document */ |
73 |
public void endDocument() throws SAXException |
|
74 |
{ |
|
75 |
System.out.println("end Document"); |
|
72 |
public void endDocument() throws SAXException { |
|
73 |
if (debug) { |
|
74 |
System.out.println("end Document"); |
|
75 |
} |
|
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
/** SAX Handler that receives notification of DTD. Sets the DTD */ |
79 |
public void setDoctype(DTD dtd) throws SAXException |
|
80 |
{ |
|
81 |
// here is a bug: dtd.getPublicId() and dtd.getSustemId() always return null. |
|
82 |
docname = dtd.getName(); |
|
83 |
doctype = dtd.getPublicId(); |
|
84 |
systemid = dtd.getSystemId(); |
|
85 |
System.out.println("DOCNAME: " + docname); |
|
86 |
System.out.println("DOCTYPE: " + doctype); |
|
87 |
System.out.println(" SYSID: " + systemid); |
|
79 |
public void setDoctype(DTD dtd) throws SAXException { |
|
80 |
// here is a bug: dtd.getPublicId() and dtd.getSustemId() |
|
81 |
// always return null. |
|
82 |
docname = dtd.getName(); |
|
83 |
doctype = dtd.getPublicId(); |
|
84 |
systemid = dtd.getSystemId(); |
|
85 |
if (debug) { |
|
86 |
System.out.println("DOCNAME: " + docname); |
|
87 |
System.out.println("DOCTYPE: " + doctype); |
|
88 |
System.out.println(" SYSID: " + systemid); |
|
89 |
} |
|
88 | 90 |
} |
89 | 91 |
|
90 |
/** SAX Handler that receives notification of end of DTD |
|
91 |
* All events in DTDHandler about all unparsed entities and the event in EntityResolver for the DTD file declaration |
|
92 |
* appear between setDoctype and endDoctype. |
|
93 |
* The rest of parsable external entities inside DTD file appear later in the elements from where they are referred to. */ |
|
94 |
public void endDoctype() throws SAXException |
|
95 |
{ |
|
96 |
System.out.println("end of DOCTYPE"); |
|
92 |
/** |
|
93 |
* SAX Handler that receives notification of end of DTD |
|
94 |
* All events in DTDHandler about all unparsed entities and the |
|
95 |
* event in EntityResolver for the DTD file declaration appear |
|
96 |
* between setDoctype and endDoctype. The rest of parsable external |
|
97 |
* entities inside DTD file appear later in the elements from where |
|
98 |
* they are referred to. |
|
99 |
*/ |
|
100 |
public void endDoctype() throws SAXException { |
|
101 |
if (debug) { |
|
102 |
System.out.println("end of DOCTYPE"); |
|
103 |
} |
|
97 | 104 |
} |
98 | 105 |
|
99 | 106 |
/** SAX Handler that is called at the start of each XML element */ |
100 |
public void startElement(NSName name, SAXAttrList atts) throws SAXException |
|
101 |
{ |
|
107 |
public void startElement(NSName name, SAXAttrList atts) throws SAXException { |
|
102 | 108 |
|
103 | 109 |
// Use the methods getQualifiedName(), getLocalName(), getNamespace() |
104 | 110 |
// and getExpandedName() in NSName interface to get Namespace |
... | ... | |
172 | 178 |
} |
173 | 179 |
|
174 | 180 |
/** SAX Handler that is called for each XML text node */ |
175 |
public void characters(char[] cbuf, int start, int len) |
|
176 |
{ |
|
181 |
public void characters(char[] cbuf, int start, int len) { |
|
177 | 182 |
DBSAXElement currentElement = (DBSAXElement)elementStack.peek(); |
178 |
currentElement.appendContent(cbuf,start,len); |
|
183 |
int nodeIndex = currentElement.incChildNum(); |
|
184 |
String data = new String(cbuf, start, len); |
|
185 |
|
|
186 |
// Write the content of the element to the database |
|
187 |
currentElement.writeContentToDB(data, nodeIndex); |
|
179 | 188 |
} |
180 | 189 |
|
181 | 190 |
/** |
182 | 191 |
* SAX Handler that is called for each XML text node that is Ignorable |
183 | 192 |
* white space |
184 | 193 |
*/ |
185 |
public void ignorableWhitespace(char[] cbuf, int start, int len) |
|
186 |
{ |
|
194 |
public void ignorableWhitespace(char[] cbuf, int start, int len) { |
|
187 | 195 |
} |
188 | 196 |
|
189 |
/** SAX Handler called once for each comment found:
|
|
190 |
* node that comment may occur before or after the root element.
|
|
191 |
* For now works only for comments after the root element. */
|
|
192 |
public void comment(String data) throws SAXException
|
|
193 |
{
|
|
194 |
//if (elementNo > 0) {
|
|
197 |
/** |
|
198 |
* SAX Handler called once for each comment found:
|
|
199 |
* node that comment may occur before or after the root element.
|
|
200 |
* For now works only for comments after the root element.
|
|
201 |
*/
|
|
202 |
public void comment(String data) throws SAXException {
|
|
195 | 203 |
DBSAXElement currentElement = (DBSAXElement)elementStack.peek(); |
196 | 204 |
int nodeIndex = currentElement.incChildNum(); |
197 | 205 |
currentElement.writeCommentToDB(data, nodeIndex); |
198 |
//} |
|
199 | 206 |
} |
200 |
public void processingInstruction(String target, String data) throws SAXException |
|
201 |
{ |
|
207 |
|
|
208 |
/** |
|
209 |
* SAX Handler called once for each processing instruction found: |
|
210 |
* node that PI may occur before or after the root element. |
|
211 |
*/ |
|
212 |
public void processingInstruction(String target, String data) |
|
213 |
throws SAXException { |
|
202 | 214 |
DBSAXElement currentElement = (DBSAXElement)elementStack.peek(); |
203 | 215 |
int nodeIndex = currentElement.incChildNum(); |
204 | 216 |
currentElement.writePIToDB(target, data, nodeIndex); |
205 | 217 |
} |
206 | 218 |
|
207 | 219 |
/** SAX Handler that is called at the end of each XML element */ |
208 |
public void endElement(NSName name) throws SAXException |
|
209 |
{ |
|
220 |
public void endElement(NSName name) throws SAXException { |
|
210 | 221 |
// Use the methods getQualifiedName(), getLocalName(), getNamespace() |
211 | 222 |
// and getExpandedName() in NSName interface to get Namespace |
212 | 223 |
// information. |
... | ... | |
216 | 227 |
DBSAXElement currentElement = (DBSAXElement)elementStack.pop(); |
217 | 228 |
|
218 | 229 |
// Write the content of the element to the database |
219 |
currentElement.writeContentToDB(); |
|
230 |
// Don't need to do this if using DOM model for TEXT nodes |
|
231 |
//currentElement.writeContentToDB(); |
|
220 | 232 |
} |
221 | 233 |
|
222 | 234 |
/** Debug routine */ |
src/edu/ucsb/nceas/metacat/ElementNode.java | ||
---|---|---|
66 | 66 |
setElementID(nodeid); |
67 | 67 |
setParentID(parentnodeid); |
68 | 68 |
setTagName(nodename); |
69 |
appendContent(nodedata); |
|
69 |
//appendContent(nodedata);
|
|
70 | 70 |
|
71 | 71 |
// Create child nodes (elements or attributes) |
72 | 72 |
setChildrenNodes(nodeid); |
... | ... | |
120 | 120 |
System.out.println("Error getting id: " + e.getMessage()); |
121 | 121 |
} |
122 | 122 |
|
123 |
if (nodetype.equals("ELEMENT")) { |
|
123 |
// Record our node type |
|
124 |
setNodeType(nodetype); |
|
125 |
|
|
126 |
if (nodetype.equals("ELEMENT") || nodetype.equals("DOCUMENT") ) { |
|
124 | 127 |
setElementID(element_id); |
125 | 128 |
setParentID(parentnodeid); |
126 | 129 |
setTagName(nodename); |
127 |
appendContent(nodedata); |
|
130 |
//appendContent(nodedata);
|
|
128 | 131 |
} |
129 | 132 |
} |
130 | 133 |
|
... | ... | |
147 | 150 |
",'<','<') " + |
148 | 151 |
",'>','>') " + |
149 | 152 |
"FROM xml_nodes WHERE parentnodeid = ?"); |
153 |
|
|
154 |
// ORDER BY nodeindex |
|
155 |
|
|
150 | 156 |
// Bind the values to the query |
151 | 157 |
pstmt.setLong(1, nodeid); |
152 | 158 |
|
... | ... | |
163 | 169 |
nodename = rs.getString(4); |
164 | 170 |
nodedata = rs.getString(5); |
165 | 171 |
|
166 |
if (nodetype.equals("ELEMENT")) { |
|
172 |
// Record our node type |
|
173 |
setNodeType(nodetype); |
|
174 |
|
|
175 |
if ( (nodetype.equals("ELEMENT")) || |
|
176 |
(nodetype.equals("DOCUMENT")) |
|
177 |
) { |
|
167 | 178 |
ReaderElement child = new ReaderElement(conn, |
168 | 179 |
element_id,parentnodeid,nodename,nodedata); |
169 | 180 |
children.add(child); |
170 | 181 |
} else if (nodetype.equals("ATTRIBUTE")) { |
171 | 182 |
setAttribute(nodename,nodedata); |
183 |
} else if (nodetype.equals("TEXT")) { |
|
184 |
appendContent(nodedata); |
|
172 | 185 |
} |
173 | 186 |
|
174 | 187 |
} catch (SQLException e) { |
... | ... | |
198 | 211 |
public String toString () |
199 | 212 |
{ |
200 | 213 |
StringBuffer value = new StringBuffer(); |
201 |
value.append('<'); |
|
202 |
value.append(getTagName()); |
|
203 |
value.append(getAttributes().toString()); |
|
204 |
value.append('>'); |
|
205 | 214 |
|
215 |
String nodetype = getNodeType(); |
|
216 |
String nodename = getTagName(); |
|
217 |
System.out.println("NODETYPE ====> " + nodetype + |
|
218 |
"(" + nodename +")"); |
|
219 |
if (nodetype.equals("ELEMENT")) { |
|
220 |
value.append('<'); |
|
221 |
value.append(getTagName()); |
|
222 |
value.append(getAttributes().toString()); |
|
223 |
value.append('>'); |
|
224 |
} |
|
225 |
//else { value.append(getNodeType()); } |
|
226 |
|
|
206 | 227 |
// Process children recursively here |
207 |
// Or do it in ReaderElement using a stack so we don;t have the |
|
208 |
// whole thing in memory at once? |
|
209 | 228 |
ReaderElement child = null; |
210 | 229 |
Enumeration e = children.elements(); |
211 | 230 |
while (e.hasMoreElements()) { |
212 | 231 |
child = (ReaderElement)e.nextElement(); |
213 |
value.append(child); |
|
232 |
try { |
|
233 |
value.append(child); |
|
234 |
} catch (NullPointerException npe) { |
|
235 |
value.append("M"); |
|
236 |
} |
|
214 | 237 |
} |
215 | 238 |
|
216 | 239 |
String cont = getContent(); |
... | ... | |
218 | 241 |
value.append(cont); |
219 | 242 |
} |
220 | 243 |
|
221 |
value.append("</"); |
|
222 |
value.append(getTagName()); |
|
223 |
value.append('>'); |
|
244 |
if (nodetype.equals("ELEMENT")) { |
|
245 |
value.append("</"); |
|
246 |
value.append(getTagName()); |
|
247 |
value.append('>'); |
|
248 |
} |
|
249 |
//else { value.append(getNodeType()); } |
|
250 |
|
|
224 | 251 |
return value.toString(); |
225 | 252 |
} |
226 | 253 |
} |
src/edu/ucsb/nceas/metacat/DBSAXDocument.java | ||
---|---|---|
30 | 30 |
* |
31 | 31 |
* @param conn the JDBC Connection to which all information is written |
32 | 32 |
* @param rootnodeid - sequence id of the root node in the document |
33 |
* @param docname - the name of DTD, i.e. the name immediately following the DOCTYPE keyword - should be the root element name. |
|
34 |
* (Oracle's and IBM parsers are not aware if it is not the root element name) |
|
35 |
* @param doctype - Public ID of the DTD, i.e. the name immediately following the PUBLIC keyword in DOCTYPE declaration. |
|
33 |
* @param docname - the name of DTD, i.e. the name immediately following |
|
34 |
* the DOCTYPE keyword - should be the root element name. |
|
35 |
* (Oracle's and IBM parsers are not aware if it is not the |
|
36 |
* root element name) |
|
37 |
* @param doctype - Public ID of the DTD, i.e. the name immediately |
|
38 |
* following the PUBLIC keyword in DOCTYPE declaration. |
|
36 | 39 |
* |
37 | 40 |
*/ |
38 |
public DBSAXDocument (Connection conn, long rootnodeid, String docname, String doctype) |
|
41 |
public DBSAXDocument (Connection conn, long rootnodeid, String docname, |
|
42 |
String doctype) |
|
39 | 43 |
{ |
40 | 44 |
this.conn = conn; |
41 | 45 |
this.rootnodeid = rootnodeid; |
42 | 46 |
this.docname = docname; |
43 | 47 |
this.doctype = doctype; |
44 | 48 |
writeDocumentToDB(); |
45 |
System.out.println("DBSAXDocument.writeDocumentToDB"); |
|
46 | 49 |
} |
47 | 50 |
|
48 | 51 |
/** creates SQL code and inserts new document into DB connection */ |
... | ... | |
51 | 54 |
conn.setAutoCommit(false); |
52 | 55 |
PreparedStatement pstmt; |
53 | 56 |
pstmt = conn.prepareStatement( |
54 |
"INSERT INTO xml_documents (docid, rootnodeid, docname, doctype) " + |
|
57 |
"INSERT INTO xml_documents " + |
|
58 |
"(docid, rootnodeid, docname, doctype) " + |
|
55 | 59 |
"VALUES (null, ?, ?, ?)"); |
56 | 60 |
|
57 | 61 |
// Bind the values to the query |
src/edu/ucsb/nceas/metacat/DBEntityResolver.java | ||
---|---|---|
1 | 1 |
/** |
2 |
* Name: DBEntityResolver.java
|
|
3 |
* Purpose: A Class that implements org.xml.sax.EntityResolver interface
|
|
2 |
* Name: DBEntityResolver.java |
|
3 |
* Purpose: A Class that implements org.xml.sax.EntityResolver interface |
|
4 | 4 |
* for resolving external entities |
5 |
* Copyright: 2000 Regents of the University of California and the
|
|
5 |
* Copyright: 2000 Regents of the University of California and the |
|
6 | 6 |
* National Center for Ecological Analysis and Synthesis |
7 |
* Authors: Jivka Bojilova
|
|
7 |
* Authors: Jivka Bojilova |
|
8 | 8 |
* |
9 |
* Version: '$Id$'
|
|
9 |
* Version: '$Id$' |
|
10 | 10 |
*/ |
11 | 11 |
|
12 | 12 |
package edu.ucsb.nceas.metacat; |
... | ... | |
20 | 20 |
import java.util.EmptyStackException; |
21 | 21 |
|
22 | 22 |
/** |
23 |
* A database aware Class implementing EntityResolver interface for the SAX parser to |
|
24 |
* call when processing the XML stream and intercepting any external entities |
|
25 |
* (including the external DTD subset and external parameter entities, if any) before including them. |
|
23 |
* A database aware Class implementing EntityResolver interface for the SAX |
|
24 |
* parser to call when processing the XML stream and intercepting any |
|
25 |
* external entities (including the external DTD subset and external |
|
26 |
* parameter entities, if any) before including them. |
|
26 | 27 |
*/ |
27 | 28 |
public class DBEntityResolver implements EntityResolver |
28 | 29 |
{ |
... | ... | |
42 | 43 |
} |
43 | 44 |
|
44 | 45 |
|
45 |
/** The Parser call this method before opening any external entity |
|
46 |
* except the top-level document entity (including the external DTD subset, |
|
47 |
* external entities referenced within the DTD, and external entities referenced |
|
48 |
* within the document element)*/ |
|
46 |
/** |
|
47 |
* The Parser call this method before opening any external entity |
|
48 |
* except the top-level document entity (including the external DTD subset, |
|
49 |
* external entities referenced within the DTD, and external entities |
|
50 |
* referenced within the document element) |
|
51 |
*/ |
|
49 | 52 |
public InputSource resolveEntity (String publicId, String systemId) |
50 | 53 |
throws MalformedURLException |
51 | 54 |
{ |
... | ... | |
55 | 58 |
|
56 | 59 |
if (publicId != null) { |
57 | 60 |
pIdCounter += 1; |
58 |
System.out.println("from DBEntityResolver: current element is " + DBSAXHandler.elementNo); |
|
59 |
System.out.println("from DBEntityResolver: " + pIdCounter + " " + publicId); |
|
61 |
System.out.println("from DBEntityResolver: current element is " + |
|
62 |
DBSAXHandler.elementNo); |
|
63 |
System.out.println("from DBEntityResolver: " + pIdCounter + " " + |
|
64 |
publicId); |
|
60 | 65 |
// look at the db XML Catalog and get dbSystemId by this publicId |
61 | 66 |
if (currentElementNo == 0) { |
62 | 67 |
doctype = publicId; |
... | ... | |
71 | 76 |
new URL(dbSystemId); |
72 | 77 |
return new InputSource(dbSystemId); |
73 | 78 |
} |
74 |
/*else { |
|
75 |
// look at the db XML Catalog and get dbSystemId by this publicId for a given doctype |
|
79 |
/* |
|
80 |
else { |
|
81 |
// look at the db XML Catalog and get dbSystemId by this |
|
82 |
// publicId for a given doctype |
|
76 | 83 |
dbSystemId = getEntitySystemID (conn, doctype, publicId); |
77 | 84 |
if (dbSystemId == "") |
78 |
// register publicId in db for a given doctype and use the provided systemId |
|
85 |
// register publicId in db for a given doctype and |
|
86 |
// use the provided systemId |
|
79 | 87 |
if (systemId != "") { |
80 | 88 |
new URL(systemId); |
81 | 89 |
registerEntityPublicID (conn, doctype, publicId, systemId); |
... | ... | |
83 | 91 |
} |
84 | 92 |
new URL(dbSystemId); |
85 | 93 |
return new InputSource(dbSystemId); |
86 |
}*/ |
|
94 |
} |
|
95 |
*/ |
|
87 | 96 |
} |
88 | 97 |
// publicId is null => doctype is null => doctype = docname |
89 | 98 |
if ( systemId != null) { |
... | ... | |
104 | 113 |
return null; |
105 | 114 |
} |
106 | 115 |
|
107 |
/** Look at db XML Catalog to get System ID (if any) for that doctype. |
|
108 |
* Return empty string if there are not */ |
|
116 |
/** |
|
117 |
* Look at db XML Catalog to get System ID (if any) for that doctype. |
|
118 |
* Return empty string if there are not |
|
119 |
*/ |
|
109 | 120 |
private String getDTDSystemID (Connection conn, String doctype) { |
110 | 121 |
String system_id = ""; |
111 | 122 |
Statement stmt; |
112 | 123 |
try { |
113 | 124 |
stmt = conn.createStatement(); |
114 |
System.out.println("DOCTYPE:" + doctype); |
|
115 | 125 |
stmt.execute("SELECT system_id FROM xml_catalog " + |
116 |
"WHERE entity_type = 'DTD' AND public_id = '" + doctype + "'"); |
|
126 |
"WHERE entry_type = 'DTD' AND public_id = '" + |
|
127 |
doctype + "'"); |
|
117 | 128 |
try { |
118 | 129 |
ResultSet rs = stmt.getResultSet(); |
119 | 130 |
try { |
... | ... | |
122 | 133 |
try { |
123 | 134 |
system_id = rs.getString(1); |
124 | 135 |
} catch (SQLException e) { |
125 |
System.out.println("DBEntityResolver.getDTDSystemID() - Error with getString: " + e.getMessage()); |
|
136 |
System.out.println("DBEntityResolver.getDTDSystemID() " + |
|
137 |
"- Error with getString: " + e.getMessage()); |
|
126 | 138 |
} |
127 | 139 |
} |
128 | 140 |
} catch (SQLException e) { |
129 |
System.out.println("DBEntityResolver.getDTDSystemID() - Error with next: " + e.getMessage()); |
|
141 |
System.out.println("DBEntityResolver.getDTDSystemID() " + |
|
142 |
"- Error with next: " + e.getMessage()); |
|
130 | 143 |
} |
131 | 144 |
} catch (SQLException e) { |
132 |
System.out.println("DBEntityResolver.getDTDSystemID() - Error with getrset: " + e.getMessage()); |
|
145 |
System.out.println("DBEntityResolver.getDTDSystemID() " + |
|
146 |
"- Error with getrset: " + e.getMessage()); |
|
133 | 147 |
} |
134 | 148 |
stmt.close(); |
135 | 149 |
} catch (SQLException e) { |
136 |
System.out.println("DBEntityResolver.getDTDSystemID() - Error getting id: " + e.getMessage()); |
|
150 |
System.out.println("DBEntityResolver.getDTDSystemID() " + |
|
151 |
"- Error getting id: " + e.getMessage()); |
|
137 | 152 |
System.exit(1); |
138 | 153 |
} |
139 | 154 |
|
... | ... | |
141 | 156 |
return system_id; |
142 | 157 |
} |
143 | 158 |
|
144 |
/** Register DTD System ID in db XML Catalog */ |
|
145 |
private void registerDTDSystemID (Connection conn, String doctype, String publicId, String systemId) |
|
159 |
/** |
|
160 |
* Register DTD System ID in db XML Catalog |
|
161 |
*/ |
|
162 |
private void registerDTDSystemID (Connection conn, String doctype, |
|
163 |
String publicId, String systemId) |
|
146 | 164 |
{ |
147 | 165 |
try { |
148 |
java.net.URLConnection urlConn = (new URL(systemId)).openConnection(); |
|
166 |
java.net.URLConnection urlConn = |
|
167 |
(new URL(systemId)).openConnection(); |
|
149 | 168 |
urlConn.connect(); |
150 | 169 |
} catch (java.io.IOException e) { |
151 | 170 |
System.out.println("IOException: " + e.getMessage()); |
... | ... | |
155 | 174 |
conn.setAutoCommit(false); |
156 | 175 |
PreparedStatement pstmt; |
157 | 176 |
pstmt = conn.prepareStatement( |
158 |
"INSERT INTO xml_catalog (entity_id, entity_type, source_doctype, public_id, system_id) " + |
|
177 |
"INSERT INTO xml_catalog " + |
|
178 |
"(catalog_id, entry_type, source_doctype, " + |
|
179 |
"public_id, system_id) " + |
|
159 | 180 |
"VALUES (null, 'DTD', ?, ?, ?)"); |
160 | 181 |
// Bind the values to the query |
161 | 182 |
pstmt.setString(1, doctype); |
... | ... | |
171 | 192 |
} |
172 | 193 |
} |
173 | 194 |
|
174 |
/** Look at db XML Catalog to get System ID (if any) for that Public ID and doctype. |
|
175 |
* Return empty string if there are not */ |
|
176 |
private String getEntitySystemID (Connection conn, String doctype, String publicId) |
|
195 |
/** |
|
196 |
* Look at db XML Catalog to get System ID (if any) for that Public ID |
|
197 |
* and doctype. Return empty string if there are not |
|
198 |
*/ |
|
199 |
private String getEntitySystemID (Connection conn, String doctype, |
|
200 |
String publicId) |
|
177 | 201 |
{ |
178 | 202 |
String system_id = ""; |
179 | 203 |
Statement stmt; |
180 | 204 |
try { |
181 | 205 |
stmt = conn.createStatement(); |
182 | 206 |
stmt.execute("SELECT system_id FROM xml_catalog " + |
183 |
"WHERE entity_type = 'ENTITY' AND source_doctype = '" + doctype + "' AND public_id = '" + publicId + "'"); |
|
207 |
"WHERE entry_type = 'ENTITY' AND source_doctype = '" + |
|
208 |
doctype + "' AND public_id = '" + publicId + "'"); |
|
184 | 209 |
try { |
185 | 210 |
ResultSet rs = stmt.getResultSet(); |
186 | 211 |
try { |
... | ... | |
189 | 214 |
try { |
190 | 215 |
system_id = rs.getString(1); |
191 | 216 |
} catch (SQLException e) { |
192 |
System.out.println("DBEntityResolver.getEntitySystemID() - Error with getString: " + e.getMessage()); |
|
217 |
System.out.println("DBEntityResolver.getEntitySystemID() " + |
|
218 |
"- Error with getString: " + e.getMessage()); |
|
193 | 219 |
} |
194 | 220 |
} |
195 | 221 |
} catch (SQLException e) { |
196 |
System.out.println("DBEntityResolver.getEntitySystemID() - Error with next: " + e.getMessage()); |
|
222 |
System.out.println("DBEntityResolver.getEntitySystemID() " + |
|
223 |
"- Error with next: " + e.getMessage()); |
|
197 | 224 |
} |
198 | 225 |
} catch (SQLException e) { |
199 |
System.out.println("DBEntityResolver.getEntitySystemID() - Error with getrset: " + e.getMessage()); |
|
226 |
System.out.println("DBEntityResolver.getEntitySystemID() " + |
|
227 |
"- Error with getrset: " + e.getMessage()); |
|
200 | 228 |
} |
201 | 229 |
stmt.close(); |
202 | 230 |
} catch (SQLException e) { |
203 |
System.out.println("DBEntityResolver.getEntitySystemID() - Error getting id: " + e.getMessage()); |
|
231 |
System.out.println("DBEntityResolver.getEntitySystemID() " + |
|
232 |
"- Error getting id: " + e.getMessage()); |
|
204 | 233 |
} |
205 | 234 |
|
206 | 235 |
// return the selected System ID number |
207 | 236 |
return system_id; |
208 | 237 |
} |
209 | 238 |
|
210 |
/** Register Public ID in db XML Catalog */ |
|
211 |
private void registerEntityPublicID (Connection conn, String doctype, String publicId, String systemId) |
|
239 |
/** |
|
240 |
* Register Public ID in db XML Catalog |
|
241 |
*/ |
|
242 |
private void registerEntityPublicID (Connection conn, String doctype, |
|
243 |
String publicId, String systemId) |
|
212 | 244 |
{ |
213 | 245 |
try { |
214 | 246 |
conn.setAutoCommit(false); |
215 | 247 |
PreparedStatement pstmt; |
216 | 248 |
pstmt = conn.prepareStatement( |
217 |
"INSERT INTO xml_catalog (entity_id, entity_name, entity_type, source_doctype, public_id, system_id) " + |
|
218 |
"VALUES (null, null, 'ENTITY', ?, ?, ?)"); |
|
249 |
"INSERT INTO xml_catalog (catalog_id, entry_type, " + |
|
250 |
"source_doctype, public_id, system_id) " + |
|
251 |
"VALUES (null, 'ENTITY', ?, ?, ?)"); |
|
219 | 252 |
// Bind the values to the query |
220 | 253 |
pstmt.setString(1, doctype); |
221 | 254 |
pstmt.setString(2, publicId); |
... | ... | |
229 | 262 |
System.out.println(e.getMessage()); |
230 | 263 |
} |
231 | 264 |
} |
232 |
|
|
233 | 265 |
} |
src/edu/ucsb/nceas/metacat/DBSAXNode.java | ||
---|---|---|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
/** creates SQL code and inserts comment into DB connection */ |
77 |
void writeCommentToDB(String data, int nodeIndex) { |
|
77 |
public void writeCommentToDB(String data, int nodeIndex) {
|
|
78 | 78 |
try { |
79 | 79 |
PreparedStatement pstmt; |
80 | 80 |
pstmt = conn.prepareStatement( |
81 |
"INSERT INTO xml_nodes (nodeid, nodetype, " + |
|
82 |
"nodename, parentnodeid, nodedata, nodeindex) VALUES (null, ?, null, ?, ?, ?)"); |
|
81 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename, " + |
|
82 |
"parentnodeid, nodedata, nodeindex) " + |
|
83 |
"VALUES (null, ?, null, ?, ?, ?)"); |
|
83 | 84 |
|
84 | 85 |
// Bind the values to the query |
85 | 86 |
pstmt.setString(1, "COMMENT"); |
... | ... | |
95 | 96 |
} |
96 | 97 |
|
97 | 98 |
/** creates SQL code and inserts PI into DB connection */ |
98 |
void writePIToDB(String target, String data, int nodeIndex) { |
|
99 |
public void writePIToDB(String target, String data, int nodeIndex) {
|
|
99 | 100 |
try { |
100 | 101 |
PreparedStatement pstmt; |
101 | 102 |
pstmt = conn.prepareStatement( |
102 |
"INSERT INTO xml_nodes (nodeid, nodetype, " + |
|
103 |
"nodename, parentnodeid, nodedata, nodeindex) VALUES (null, ?, ?, ?, ?, ?)"); |
|
103 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename, " + |
|
104 |
"parentnodeid, nodedata, nodeindex) " + |
|
105 |
"VALUES (null, ?, ?, ?, ?, ?)"); |
|
104 | 106 |
|
105 | 107 |
// Bind the values to the query |
106 | 108 |
pstmt.setString(1, "PI"); |
... | ... | |
116 | 118 |
} |
117 | 119 |
} |
118 | 120 |
|
119 |
/** creates SQL code to put nodename for the document node into DB connection */ |
|
120 |
void writeNodename(String nodename) { |
|
121 |
/** |
|
122 |
* creates SQL code to put nodename for the document node |
|
123 |
* into DB connection |
|
124 |
*/ |
|
125 |
public void writeNodename(String nodename) { |
|
121 | 126 |
try { |
122 | 127 |
PreparedStatement pstmt; |
123 | 128 |
pstmt = conn.prepareStatement( |
... | ... | |
199 | 204 |
} |
200 | 205 |
|
201 | 206 |
/** Write the element content to the db connection */ |
202 |
public void writeContentToDB() { |
|
207 |
public void writeContentToDB(String content, int nodeIndex) {
|
|
203 | 208 |
try { |
204 | 209 |
PreparedStatement pstmt = conn.prepareStatement( |
205 |
"UPDATE xml_nodes SET nodedata = ? WHERE nodeid = ?"); |
|
206 |
|
|
210 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename, " + |
|
211 |
"parentnodeid, nodedata, nodeindex) " + |
|
212 |
"VALUES (null, ?, null, ?, ?, ?)"); |
|
207 | 213 |
// Bind the values to the query |
208 |
pstmt.setString(1, getContent());
|
|
214 |
pstmt.setString(1, "TEXT");
|
|
209 | 215 |
pstmt.setLong(2, getElementID()); |
216 |
pstmt.setString(3, content); |
|
217 |
pstmt.setInt(4, nodeIndex); |
|
210 | 218 |
|
211 | 219 |
// Do the update |
212 | 220 |
pstmt.execute(); |
src/edu/ucsb/nceas/metacat/DBSAXElement.java | ||
---|---|---|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
/** creates SQL code and inserts comment into DB connection */ |
77 |
void writeCommentToDB(String data, int nodeIndex) { |
|
77 |
public void writeCommentToDB(String data, int nodeIndex) {
|
|
78 | 78 |
try { |
79 | 79 |
PreparedStatement pstmt; |
80 | 80 |
pstmt = conn.prepareStatement( |
81 |
"INSERT INTO xml_nodes (nodeid, nodetype, " + |
|
82 |
"nodename, parentnodeid, nodedata, nodeindex) VALUES (null, ?, null, ?, ?, ?)"); |
|
81 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename, " + |
|
82 |
"parentnodeid, nodedata, nodeindex) " + |
|
83 |
"VALUES (null, ?, null, ?, ?, ?)"); |
|
83 | 84 |
|
84 | 85 |
// Bind the values to the query |
85 | 86 |
pstmt.setString(1, "COMMENT"); |
... | ... | |
95 | 96 |
} |
96 | 97 |
|
97 | 98 |
/** creates SQL code and inserts PI into DB connection */ |
98 |
void writePIToDB(String target, String data, int nodeIndex) { |
|
99 |
public void writePIToDB(String target, String data, int nodeIndex) {
|
|
99 | 100 |
try { |
100 | 101 |
PreparedStatement pstmt; |
101 | 102 |
pstmt = conn.prepareStatement( |
102 |
"INSERT INTO xml_nodes (nodeid, nodetype, " + |
|
103 |
"nodename, parentnodeid, nodedata, nodeindex) VALUES (null, ?, ?, ?, ?, ?)"); |
|
103 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename, " + |
|
104 |
"parentnodeid, nodedata, nodeindex) " + |
|
105 |
"VALUES (null, ?, ?, ?, ?, ?)"); |
|
104 | 106 |
|
105 | 107 |
// Bind the values to the query |
106 | 108 |
pstmt.setString(1, "PI"); |
... | ... | |
116 | 118 |
} |
117 | 119 |
} |
118 | 120 |
|
119 |
/** creates SQL code to put nodename for the document node into DB connection */ |
|
120 |
void writeNodename(String nodename) { |
|
121 |
/** |
|
122 |
* creates SQL code to put nodename for the document node |
|
123 |
* into DB connection |
|
124 |
*/ |
|
125 |
public void writeNodename(String nodename) { |
|
121 | 126 |
try { |
122 | 127 |
PreparedStatement pstmt; |
123 | 128 |
pstmt = conn.prepareStatement( |
... | ... | |
199 | 204 |
} |
200 | 205 |
|
201 | 206 |
/** Write the element content to the db connection */ |
202 |
public void writeContentToDB() { |
|
207 |
public void writeContentToDB(String content, int nodeIndex) {
|
|
203 | 208 |
try { |
204 | 209 |
PreparedStatement pstmt = conn.prepareStatement( |
205 |
"UPDATE xml_nodes SET nodedata = ? WHERE nodeid = ?"); |
|
206 |
|
|
210 |
"INSERT INTO xml_nodes (nodeid, nodetype, nodename, " + |
|
211 |
"parentnodeid, nodedata, nodeindex) " + |
|
212 |
"VALUES (null, ?, null, ?, ?, ?)"); |
|
207 | 213 |
// Bind the values to the query |
208 |
pstmt.setString(1, getContent());
|
|
214 |
pstmt.setString(1, "TEXT");
|
|
209 | 215 |
pstmt.setLong(2, getElementID()); |
216 |
pstmt.setString(3, content); |
|
217 |
pstmt.setInt(4, nodeIndex); |
|
210 | 218 |
|
211 | 219 |
// Do the update |
212 | 220 |
pstmt.execute(); |
src/edu/ucsb/nceas/metacat/ReaderElement.java | ||
---|---|---|
66 | 66 |
setElementID(nodeid); |
67 | 67 |
setParentID(parentnodeid); |
68 | 68 |
setTagName(nodename); |
69 |
appendContent(nodedata); |
|
69 |
//appendContent(nodedata);
|
|
70 | 70 |
|
71 | 71 |
// Create child nodes (elements or attributes) |
72 | 72 |
setChildrenNodes(nodeid); |
... | ... | |
120 | 120 |
System.out.println("Error getting id: " + e.getMessage()); |
121 | 121 |
} |
122 | 122 |
|
123 |
if (nodetype.equals("ELEMENT")) { |
|
123 |
// Record our node type |
|
124 |
setNodeType(nodetype); |
|
125 |
|
|
126 |
if (nodetype.equals("ELEMENT") || nodetype.equals("DOCUMENT") ) { |
|
124 | 127 |
setElementID(element_id); |
125 | 128 |
setParentID(parentnodeid); |
126 | 129 |
setTagName(nodename); |
127 |
appendContent(nodedata); |
|
130 |
//appendContent(nodedata);
|
|
128 | 131 |
} |
129 | 132 |
} |
130 | 133 |
|
... | ... | |
147 | 150 |
",'<','<') " + |
148 | 151 |
",'>','>') " + |
149 | 152 |
"FROM xml_nodes WHERE parentnodeid = ?"); |
153 |
|
|
154 |
// ORDER BY nodeindex |
|
155 |
|
|
150 | 156 |
// Bind the values to the query |
151 | 157 |
pstmt.setLong(1, nodeid); |
152 | 158 |
|
... | ... | |
163 | 169 |
nodename = rs.getString(4); |
164 | 170 |
nodedata = rs.getString(5); |
165 | 171 |
|
166 |
if (nodetype.equals("ELEMENT")) { |
|
172 |
// Record our node type |
|
173 |
setNodeType(nodetype); |
|
174 |
|
|
175 |
if ( (nodetype.equals("ELEMENT")) || |
|
176 |
(nodetype.equals("DOCUMENT")) |
|
177 |
) { |
|
167 | 178 |
ReaderElement child = new ReaderElement(conn, |
168 | 179 |
element_id,parentnodeid,nodename,nodedata); |
169 | 180 |
children.add(child); |
170 | 181 |
} else if (nodetype.equals("ATTRIBUTE")) { |
171 | 182 |
setAttribute(nodename,nodedata); |
183 |
} else if (nodetype.equals("TEXT")) { |
|
184 |
appendContent(nodedata); |
|
172 | 185 |
} |
173 | 186 |
|
174 | 187 |
} catch (SQLException e) { |
... | ... | |
198 | 211 |
public String toString () |
199 | 212 |
{ |
200 | 213 |
StringBuffer value = new StringBuffer(); |
201 |
value.append('<'); |
|
202 |
value.append(getTagName()); |
|
203 |
value.append(getAttributes().toString()); |
|
204 |
value.append('>'); |
|
205 | 214 |
|
215 |
String nodetype = getNodeType(); |
|
216 |
String nodename = getTagName(); |
|
217 |
System.out.println("NODETYPE ====> " + nodetype + |
|
218 |
"(" + nodename +")"); |
|
219 |
if (nodetype.equals("ELEMENT")) { |
|
220 |
value.append('<'); |
|
221 |
value.append(getTagName()); |
|
222 |
value.append(getAttributes().toString()); |
|
223 |
value.append('>'); |
|
224 |
} |
|
225 |
//else { value.append(getNodeType()); } |
|
226 |
|
|
206 | 227 |
// Process children recursively here |
207 |
// Or do it in ReaderElement using a stack so we don;t have the |
|
208 |
// whole thing in memory at once? |
|
209 | 228 |
ReaderElement child = null; |
210 | 229 |
Enumeration e = children.elements(); |
211 | 230 |
while (e.hasMoreElements()) { |
212 | 231 |
child = (ReaderElement)e.nextElement(); |
213 |
value.append(child); |
|
232 |
try { |
|
233 |
value.append(child); |
|
234 |
} catch (NullPointerException npe) { |
|
235 |
value.append("M"); |
|
236 |
} |
|
214 | 237 |
} |
215 | 238 |
|
216 | 239 |
String cont = getContent(); |
... | ... | |
218 | 241 |
value.append(cont); |
219 | 242 |
} |
220 | 243 |
|
221 |
value.append("</"); |
|
222 |
value.append(getTagName()); |
|
223 |
value.append('>'); |
|
244 |
if (nodetype.equals("ELEMENT")) { |
|
245 |
value.append("</"); |
|
246 |
value.append(getTagName()); |
|
247 |
value.append('>'); |
|
248 |
} |
|
249 |
//else { value.append(getNodeType()); } |
|
250 |
|
|
224 | 251 |
return value.toString(); |
225 | 252 |
} |
226 | 253 |
} |
src/edu/ucsb/nceas/metacat/DBDTDHandler.java | ||
---|---|---|
20 | 20 |
import java.util.EmptyStackException; |
21 | 21 |
|
22 | 22 |
/** |
23 |
* A database aware Class implementing DTDHandler interface for the SAX parser to |
|
24 |
* call when processing the XML stream and intercepting notations and unparsed entities |
|
23 |
* A database aware Class implementing DTDHandler interface for the SAX |
|
24 |
* parser to call when processing the XML stream and intercepting notations |
|
25 |
* and unparsed entities |
|
25 | 26 |
*/ |
26 | 27 |
public class DBDTDHandler implements DTDHandler |
27 | 28 |
{ |
... | ... | |
47 | 48 |
return; |
48 | 49 |
} |
49 | 50 |
|
50 |
/** All are reported after startDocument and before first startElement event*/ |
|
51 |
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) |
|
51 |
/** All are reported after startDocument and before first |
|
52 |
* startElement event |
|
53 |
*/ |
|
54 |
public void unparsedEntityDecl(String name, String publicId, |
|
55 |
String systemId, String notationName) |
|
52 | 56 |
throws SAXException |
53 | 57 |
{ |
54 | 58 |
System.out.println("from DBDTDHandler.unparsedEntityDecl"); |
... | ... | |
62 | 66 |
return; |
63 | 67 |
} |
64 | 68 |
|
65 |
/** Look at db XML Catalog to get System ID (if any) for that Public ID and doctype. |
|
66 |
* Return empty string if there are not */ |
|
67 |
private String getEntitySystemID (Connection conn, String doctype, String publicId) |
|
69 |
/** |
|
70 |
* Look at db XML Catalog to get System ID (if any) for that Public ID |
|
71 |
* and doctype. |
|
72 |
* Return empty string if there are not |
|
73 |
*/ |
|
74 |
/* |
|
75 |
private String getEntitySystemID (Connection conn, String doctype, |
|
76 |
String publicId) |
|
68 | 77 |
{ |
69 | 78 |
String system_id = ""; |
70 | 79 |
Statement stmt; |
71 | 80 |
try { |
72 | 81 |
stmt = conn.createStatement(); |
73 | 82 |
stmt.execute("SELECT system_id FROM xml_catalog " + |
74 |
"WHERE entity_type = 'ENTITY' AND source_doctype = '" + doctype + "' AND public_id = '" + publicId + "'"); |
|
83 |
"WHERE entry_type = 'ENTITY' AND source_doctype = '" + |
|
84 |
doctype + "' AND public_id = '" + publicId + "'"); |
|
75 | 85 |
try { |
76 | 86 |
ResultSet rs = stmt.getResultSet(); |
77 | 87 |
try { |
... | ... | |
80 | 90 |
try { |
81 | 91 |
system_id = rs.getString(1); |
82 | 92 |
} catch (SQLException e) { |
83 |
System.out.println("DBDTDHandler.getEntitySystemID() - Error with getString: " + e.getMessage()); |
|
93 |
System.out.println("DBDTDHandler.getEntitySystemID() " + |
|
94 |
"- Error with getString: " + e.getMessage()); |
|
84 | 95 |
} |
85 | 96 |
} |
86 | 97 |
} catch (SQLException e) { |
87 |
System.out.println("DBDTDHandler.getEntitySystemID() - Error with next: " + e.getMessage()); |
|
98 |
System.out.println("DBDTDHandler.getEntitySystemID() " + |
|
99 |
"- Error with next: " + e.getMessage()); |
|
88 | 100 |
} |
89 | 101 |
} catch (SQLException e) { |
90 |
System.out.println("DBDTDHandler.getEntitySystemID() - Error with getrset: " + e.getMessage()); |
|
102 |
System.out.println("DBDTDHandler.getEntitySystemID() " + |
|
103 |
"- Error with getrset: " + e.getMessage()); |
|
91 | 104 |
} |
92 | 105 |
stmt.close(); |
93 | 106 |
} catch (SQLException e) { |
94 |
System.out.println("DBDTDHandler.getEntitySystemID() - Error getting id: " + e.getMessage()); |
|
107 |
System.out.println("DBDTDHandler.getEntitySystemID() " + |
|
108 |
"- Error getting id: " + e.getMessage()); |
|
95 | 109 |
} |
96 | 110 |
|
97 | 111 |
// return the selected System ID |
98 | 112 |
return system_id; |
99 | 113 |
} |
100 |
|
|
101 |
/** Register Public ID in db XML Catalog */ |
|
102 |
private void registerEntityPublicID (Connection conn, String doctype, String publicId, String systemId) |
|
114 |
*/ |
|
115 |
/** |
|
116 |
* Register Public ID in db XML Catalog |
|
117 |
*/ |
|
118 |
/* |
|
119 |
private void registerEntityPublicID (Connection conn, String doctype, |
|
120 |
String publicId, String systemId) |
|
103 | 121 |
{ |
104 | 122 |
try { |
105 | 123 |
conn.setAutoCommit(false); |
106 | 124 |
PreparedStatement pstmt; |
107 | 125 |
pstmt = conn.prepareStatement( |
108 |
"INSERT INTO xml_catalog (entity_id, entity_name, entity_type, source_doctype, public_id, system_id) " + |
|
126 |
"INSERT INTO xml_catalog (entity_id, entity_name, " + |
|
127 |
"entry_type, source_doctype, public_id, system_id) " + |
|
109 | 128 |
"VALUES (null, null, 'ENTITY', ?, ?, ?)"); |
110 | 129 |
// Bind the values to the query |
111 | 130 |
pstmt.setString(1, doctype); |
... | ... | |
120 | 139 |
System.out.println(e.getMessage()); |
121 | 140 |
} |
122 | 141 |
} |
123 |
|
|
142 |
*/ |
|
143 |
|
|
124 | 144 |
} |
src/edu/ucsb/nceas/metacat/DBTransform.java | ||
---|---|---|
95 | 95 |
pstmt = |
96 | 96 |
conn.prepareStatement("SELECT system_id " + |
97 | 97 |
"FROM xml_catalog " + |
98 |
"WHERE entity_type LIKE ? " +
|
|
98 |
"WHERE entry_type LIKE ? " +
|
|
99 | 99 |
"AND source_doctype LIKE ? " + |
100 | 100 |
"AND target_doctype LIKE ? "); |
101 | 101 |
// Bind the values to the query |
src/edu/ucsb/nceas/metacat/BasicNode.java | ||
---|---|---|
24 | 24 |
private Hashtable attributes; |
25 | 25 |
private int childNum; |
26 | 26 |
private int nodeIndex; |
27 |
private String nodeType; |
|
27 | 28 |
|
28 | 29 |
/** Construct a Basic Element */ |
29 | 30 |
public BasicElement () { |
... | ... | |
35 | 36 |
* |
36 | 37 |
* @param tagname the name of the element |
37 | 38 |
* @param parent_id the id number of the parent element |
38 |
* @param nodeIndex - number of the element in the order for a given parent node |
|
39 |
* Every element initializes childNum to 0 when created and has interface incChildNum |
|
40 |
* when new child is created |
|
39 |
* @param nodeIndex - order of node among siblings in parent node |
|
40 |
* Every element initializes childNum to 0 when |
|
41 |
* created and has interface incChildNum |
|
42 |
* when new child is created |
|
41 | 43 |
*/ |
42 | 44 |
public BasicElement (String tagname, long parent_id, int nodeIndex) { |
43 | 45 |
this(); |
... | ... | |
53 | 55 |
* @param tagname the name of the element |
54 | 56 |
* @param parent_id the id number of the parent element |
55 | 57 |
*/ |
56 |
public BasicElement (long element_id, String tagname, long parent_id, int nodeIndex) { |
|
58 |
public BasicElement (long element_id, String tagname, long parent_id, |
|
59 |
int nodeIndex) { |
|
57 | 60 |
this(tagname,parent_id,nodeIndex); |
58 | 61 |
this.element_id = element_id; |
59 | 62 |
} |
... | ... | |
121 | 124 |
while (attList.hasMoreElements()) { |
122 | 125 |
attName = (String)attList.nextElement(); |
123 | 126 |
attValue = (String)attributes.get(attName); |
124 |
buf.append(" ").append(attName).append("=\"").append(attValue).append("\""); |
|
127 |
buf.append(" ").append(attName).append("=\""); |
|
128 |
buf.append(attValue).append("\""); |
|
125 | 129 |
} |
126 | 130 |
return buf.toString(); |
127 | 131 |
} |
... | ... | |
166 | 170 |
public int incChildNum() { |
167 | 171 |
return ++this.childNum; |
168 | 172 |
} |
173 |
|
|
174 |
/** Get the type of this node */ |
|
175 |
public String getNodeType() |
|
176 |
{ |
|
177 |
return nodeType; |
|
178 |
} |
|
179 |
|
|
180 |
/** Set the type of this node */ |
|
181 |
public void setNodeType(String type) |
|
182 |
{ |
|
183 |
this.nodeType = type; |
|
184 |
} |
|
169 | 185 |
} |
src/edu/ucsb/nceas/metacat/BasicElement.java | ||
---|---|---|
24 | 24 |
private Hashtable attributes; |
25 | 25 |
private int childNum; |
26 | 26 |
private int nodeIndex; |
27 |
private String nodeType; |
|
27 | 28 |
|
28 | 29 |
/** Construct a Basic Element */ |
29 | 30 |
public BasicElement () { |
... | ... | |
35 | 36 |
* |
36 | 37 |
* @param tagname the name of the element |
37 | 38 |
* @param parent_id the id number of the parent element |
38 |
* @param nodeIndex - number of the element in the order for a given parent node |
|
39 |
* Every element initializes childNum to 0 when created and has interface incChildNum |
|
40 |
* when new child is created |
|
39 |
* @param nodeIndex - order of node among siblings in parent node |
|
40 |
* Every element initializes childNum to 0 when |
|
41 |
* created and has interface incChildNum |
|
42 |
* when new child is created |
|
41 | 43 |
*/ |
42 | 44 |
public BasicElement (String tagname, long parent_id, int nodeIndex) { |
43 | 45 |
this(); |
... | ... | |
53 | 55 |
* @param tagname the name of the element |
54 | 56 |
* @param parent_id the id number of the parent element |
55 | 57 |
*/ |
56 |
public BasicElement (long element_id, String tagname, long parent_id, int nodeIndex) { |
|
58 |
public BasicElement (long element_id, String tagname, long parent_id, |
|
59 |
int nodeIndex) { |
|
57 | 60 |
this(tagname,parent_id,nodeIndex); |
58 | 61 |
this.element_id = element_id; |
59 | 62 |
} |
... | ... | |
121 | 124 |
while (attList.hasMoreElements()) { |
122 | 125 |
attName = (String)attList.nextElement(); |
123 | 126 |
attValue = (String)attributes.get(attName); |
124 |
buf.append(" ").append(attName).append("=\"").append(attValue).append("\""); |
|
127 |
buf.append(" ").append(attName).append("=\""); |
|
128 |
buf.append(attValue).append("\""); |
|
125 | 129 |
} |
126 | 130 |
return buf.toString(); |
127 | 131 |
} |
... | ... | |
166 | 170 |
public int incChildNum() { |
167 | 171 |
return ++this.childNum; |
168 | 172 |
} |
173 |
|
|
174 |
/** Get the type of this node */ |
|
175 |
public String getNodeType() |
|
176 |
{ |
|
177 |
return nodeType; |
|
178 |
} |
|
179 |
|
|
180 |
/** Set the type of this node */ |
|
181 |
public void setNodeType(String type) |
|
182 |
{ |
|
183 |
this.nodeType = type; |
|
184 |
} |
|
169 | 185 |
} |
Also available in: Unified diff
Modifying storage model to use DOM TEXT nodes -- update is incomplete and query code doesn not work for this checkin