Revision 110
Added by bojilova over 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
62 | 62 |
public void startDocument() throws SAXException |
63 | 63 |
{ |
64 | 64 |
System.out.println("start Document"); |
65 |
// Create the document node represantation as root |
|
66 |
DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0); |
|
67 |
// Add the element to the stack, so that any text data can be |
|
68 |
// added as it is encountered |
|
69 |
elementStack.push(documentNode); |
|
65 | 70 |
} |
66 | 71 |
|
67 | 72 |
/** SAX Handler that receives notification of end of the document */ |
... | ... | |
80 | 85 |
System.out.println("DOCNAME: " + docname); |
81 | 86 |
System.out.println("DOCTYPE: " + doctype); |
82 | 87 |
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); |
|
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
/** SAX Handler that receives notification of end of DTD |
... | ... | |
95 | 94 |
public void endDoctype() throws SAXException |
96 | 95 |
{ |
97 | 96 |
System.out.println("end of DOCTYPE"); |
98 |
//if (doctype == null) |
|
99 |
// doctype = DBEntityResolver.doctype; |
|
100 |
//DBSAXElement documentNode = (DBSAXElement)elementStack.peek(); |
|
101 |
//new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype); |
|
102 | 97 |
} |
103 | 98 |
|
104 | 99 |
/** SAX Handler that is called at the start of each XML element */ |
... | ... | |
142 | 137 |
else if (doctype == null) |
143 | 138 |
doctype = DBEntityResolver.doctype; |
144 | 139 |
DBSAXElement documentNode = (DBSAXElement)elementStack.peek(); |
140 |
documentNode.writeNodename(docname); |
|
145 | 141 |
new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype); |
146 | 142 |
} |
147 | 143 |
// Create the current element representation |
148 | 144 |
currentElement = new DBSAXElement(conn, localName, parent_id, nodeIndex); |
149 |
// go to create document definition in the db |
|
150 |
// call once after insertion of the first element |
|
151 |
if (parent_id == 0) { |
|
152 |
long rootnodeid = currentElement.getElementID(); |
|
153 |
new DBSAXDocument(conn, rootnodeid, docname, doctype); |
|
154 |
} |
|
155 | 145 |
|
156 | 146 |
// Add all of the attributes |
157 | 147 |
for (int i=0; i<atts.getLength(); i++) |
src/edu/ucsb/nceas/metacat/DBSAXNode.java | ||
---|---|---|
84 | 84 |
// Bind the values to the query |
85 | 85 |
pstmt.setString(1, "COMMENT"); |
86 | 86 |
pstmt.setLong(2, getElementID()); |
87 |
//System.out.println(data.length()); |
|
88 | 87 |
pstmt.setString(3, data); |
89 | 88 |
pstmt.setInt(4, nodeIndex); |
90 | 89 |
// Do the insertion |
... | ... | |
117 | 116 |
} |
118 | 117 |
} |
119 | 118 |
|
119 |
/** creates SQL code to put nodename for the document node into DB connection */ |
|
120 |
void writeNodename(String nodename) { |
|
121 |
try { |
|
122 |
PreparedStatement pstmt; |
|
123 |
pstmt = conn.prepareStatement( |
|
124 |
"UPDATE xml_nodes set nodename = ? " + |
|
125 |
"WHERE nodeid = ?"); |
|
126 |
|
|
127 |
// Bind the values to the query |
|
128 |
pstmt.setString(1, nodename); |
|
129 |
pstmt.setLong(2, getElementID()); |
|
130 |
// Do the insertion |
|
131 |
pstmt.execute(); |
|
132 |
pstmt.close(); |
|
133 |
} catch (SQLException e) { |
|
134 |
System.out.println(e.getMessage()); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
120 | 138 |
/** look up the assigned element id from DB connection */ |
121 | 139 |
private long getAssignedElementID() { |
122 | 140 |
long assigned_id=0; |
src/edu/ucsb/nceas/metacat/DBSAXElement.java | ||
---|---|---|
84 | 84 |
// Bind the values to the query |
85 | 85 |
pstmt.setString(1, "COMMENT"); |
86 | 86 |
pstmt.setLong(2, getElementID()); |
87 |
//System.out.println(data.length()); |
|
88 | 87 |
pstmt.setString(3, data); |
89 | 88 |
pstmt.setInt(4, nodeIndex); |
90 | 89 |
// Do the insertion |
... | ... | |
117 | 116 |
} |
118 | 117 |
} |
119 | 118 |
|
119 |
/** creates SQL code to put nodename for the document node into DB connection */ |
|
120 |
void writeNodename(String nodename) { |
|
121 |
try { |
|
122 |
PreparedStatement pstmt; |
|
123 |
pstmt = conn.prepareStatement( |
|
124 |
"UPDATE xml_nodes set nodename = ? " + |
|
125 |
"WHERE nodeid = ?"); |
|
126 |
|
|
127 |
// Bind the values to the query |
|
128 |
pstmt.setString(1, nodename); |
|
129 |
pstmt.setLong(2, getElementID()); |
|
130 |
// Do the insertion |
|
131 |
pstmt.execute(); |
|
132 |
pstmt.close(); |
|
133 |
} catch (SQLException e) { |
|
134 |
System.out.println(e.getMessage()); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
120 | 138 |
/** look up the assigned element id from DB connection */ |
121 | 139 |
private long getAssignedElementID() { |
122 | 140 |
long assigned_id=0; |
src/edu/ucsb/nceas/metacat/DBWriter.java | ||
---|---|---|
124 | 124 |
} catch (SAXException e) { |
125 | 125 |
System.err.println(e.getMessage()); |
126 | 126 |
} catch (Exception e) { |
127 |
System.err.println("here is the URL exception"); |
|
128 | 127 |
System.err.println(e.toString()); |
129 | 128 |
} |
130 | 129 |
} |
src/edu/ucsb/nceas/metacat/DBSAXWriter.java | ||
---|---|---|
124 | 124 |
} catch (SAXException e) { |
125 | 125 |
System.err.println(e.getMessage()); |
126 | 126 |
} catch (Exception e) { |
127 |
System.err.println("here is the URL exception"); |
|
128 | 127 |
System.err.println(e.toString()); |
129 | 128 |
} |
130 | 129 |
} |
DBSAXElement.java | ||
---|---|---|
84 | 84 |
// Bind the values to the query |
85 | 85 |
pstmt.setString(1, "COMMENT"); |
86 | 86 |
pstmt.setLong(2, getElementID()); |
87 |
//System.out.println(data.length()); |
|
88 | 87 |
pstmt.setString(3, data); |
89 | 88 |
pstmt.setInt(4, nodeIndex); |
90 | 89 |
// Do the insertion |
... | ... | |
117 | 116 |
} |
118 | 117 |
} |
119 | 118 |
|
119 |
/** creates SQL code to put nodename for the document node into DB connection */ |
|
120 |
void writeNodename(String nodename) { |
|
121 |
try { |
|
122 |
PreparedStatement pstmt; |
|
123 |
pstmt = conn.prepareStatement( |
|
124 |
"UPDATE xml_nodes set nodename = ? " + |
|
125 |
"WHERE nodeid = ?"); |
|
126 |
|
|
127 |
// Bind the values to the query |
|
128 |
pstmt.setString(1, nodename); |
|
129 |
pstmt.setLong(2, getElementID()); |
|
130 |
// Do the insertion |
|
131 |
pstmt.execute(); |
|
132 |
pstmt.close(); |
|
133 |
} catch (SQLException e) { |
|
134 |
System.out.println(e.getMessage()); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
120 | 138 |
/** look up the assigned element id from DB connection */ |
121 | 139 |
private long getAssignedElementID() { |
122 | 140 |
long assigned_id=0; |
DBSAXWriter.java | ||
---|---|---|
124 | 124 |
} catch (SAXException e) { |
125 | 125 |
System.err.println(e.getMessage()); |
126 | 126 |
} catch (Exception e) { |
127 |
System.err.println("here is the URL exception"); |
|
128 | 127 |
System.err.println(e.toString()); |
129 | 128 |
} |
130 | 129 |
} |
DBSAXHandler.java | ||
---|---|---|
62 | 62 |
public void startDocument() throws SAXException |
63 | 63 |
{ |
64 | 64 |
System.out.println("start Document"); |
65 |
// Create the document node represantation as root |
|
66 |
DBSAXElement documentNode = new DBSAXElement(conn, docname, 0, 0); |
|
67 |
// Add the element to the stack, so that any text data can be |
|
68 |
// added as it is encountered |
|
69 |
elementStack.push(documentNode); |
|
65 | 70 |
} |
66 | 71 |
|
67 | 72 |
/** SAX Handler that receives notification of end of the document */ |
... | ... | |
80 | 85 |
System.out.println("DOCNAME: " + docname); |
81 | 86 |
System.out.println("DOCTYPE: " + doctype); |
82 | 87 |
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); |
|
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
/** SAX Handler that receives notification of end of DTD |
... | ... | |
95 | 94 |
public void endDoctype() throws SAXException |
96 | 95 |
{ |
97 | 96 |
System.out.println("end of DOCTYPE"); |
98 |
//if (doctype == null) |
|
99 |
// doctype = DBEntityResolver.doctype; |
|
100 |
//DBSAXElement documentNode = (DBSAXElement)elementStack.peek(); |
|
101 |
//new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype); |
|
102 | 97 |
} |
103 | 98 |
|
104 | 99 |
/** SAX Handler that is called at the start of each XML element */ |
... | ... | |
142 | 137 |
else if (doctype == null) |
143 | 138 |
doctype = DBEntityResolver.doctype; |
144 | 139 |
DBSAXElement documentNode = (DBSAXElement)elementStack.peek(); |
140 |
documentNode.writeNodename(docname); |
|
145 | 141 |
new DBSAXDocument(conn, documentNode.getElementID(), docname, doctype); |
146 | 142 |
} |
147 | 143 |
// Create the current element representation |
148 | 144 |
currentElement = new DBSAXElement(conn, localName, parent_id, nodeIndex); |
149 |
// go to create document definition in the db |
|
150 |
// call once after insertion of the first element |
|
151 |
if (parent_id == 0) { |
|
152 |
long rootnodeid = currentElement.getElementID(); |
|
153 |
new DBSAXDocument(conn, rootnodeid, docname, doctype); |
|
154 |
} |
|
155 | 145 |
|
156 | 146 |
// Add all of the attributes |
157 | 147 |
for (int i=0; i<atts.getLength(); i++) |
Also available in: Unified diff
changed case 4/ to be like case 3/ when no doctype specified