Revision 98
Added by Matt Jones over 24 years ago
DBSAXDocument.java | ||
---|---|---|
20 | 20 |
*/ |
21 | 21 |
public class DBSAXDocument { |
22 | 22 |
|
23 |
private Connection conn;
|
|
23 |
private Connection conn;
|
|
24 | 24 |
private long rootnodeid; |
25 |
private long docid; |
|
25 | 26 |
private String docname; |
26 | 27 |
private String doctype; |
28 |
private String doctitle; |
|
27 | 29 |
|
28 | 30 |
/** |
29 | 31 |
* Construct a new document instance |
30 | 32 |
* |
31 | 33 |
* @param conn the JDBC Connection to which all information is written |
32 | 34 |
* @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. |
|
35 |
* @param docname - the name of DTD, |
|
36 |
* i.e. the name immediately following the DOCTYPE keyword - |
|
37 |
* should be the root element name. |
|
38 |
* (Oracle's and IBM parsers are not aware if it is not the |
|
39 |
* root element name) |
|
40 |
* @param doctype - Public ID of the DTD, |
|
41 |
* i.e. the name immediately following the PUBLIC keyword in |
|
42 |
* DOCTYPE declaration. |
|
43 |
* @param doctitle - document title from first child element named "title" |
|
36 | 44 |
* |
37 | 45 |
*/ |
38 |
public DBSAXDocument (Connection conn, long rootnodeid, String docname, String doctype) |
|
46 |
public DBSAXDocument (Connection conn, long rootnodeid, String docname, |
|
47 |
String doctype) |
|
39 | 48 |
{ |
40 | 49 |
this.conn = conn; |
41 | 50 |
this.rootnodeid = rootnodeid; |
... | ... | |
51 | 60 |
conn.setAutoCommit(false); |
52 | 61 |
PreparedStatement pstmt; |
53 | 62 |
pstmt = conn.prepareStatement( |
54 |
"INSERT INTO xml_documents (docid, rootnodeid, docname, doctype) " + |
|
55 |
"VALUES (null, ?, ?, ?)"); |
|
63 |
"INSERT INTO xml_documents " + |
|
64 |
"(docid, rootnodeid, docname, doctype, doctitle) " + |
|
65 |
"VALUES (null, ?, ?, ?, ?)"); |
|
56 | 66 |
|
57 | 67 |
// Bind the values to the query |
58 | 68 |
pstmt.setLong(1, rootnodeid); |
59 | 69 |
pstmt.setString(2, docname); |
60 | 70 |
pstmt.setString(3, doctype); |
71 |
pstmt.setString(4, doctitle); |
|
61 | 72 |
// Do the insertion |
62 | 73 |
pstmt.execute(); |
63 | 74 |
pstmt.close(); |
75 |
|
|
76 |
long assigned_id=0; |
|
77 |
Statement stmt; |
|
78 |
stmt = conn.createStatement(); |
|
79 |
stmt.execute("SELECT xml_documents_id_seq.currval FROM dual"); |
|
80 |
ResultSet rs = stmt.getResultSet(); |
|
81 |
boolean tableHasRows = rs.next(); |
|
82 |
if (tableHasRows) { |
|
83 |
assigned_id = rs.getLong(1); |
|
84 |
this.docid = assigned_id; |
|
85 |
} |
|
86 |
stmt.close(); |
|
87 |
|
|
64 | 88 |
conn.commit(); |
65 | 89 |
conn.setAutoCommit(true); |
66 | 90 |
} catch (SQLException e) { |
... | ... | |
68 | 92 |
} |
69 | 93 |
} |
70 | 94 |
|
95 |
/** |
|
96 |
* Get the document title |
|
97 |
*/ |
|
98 |
public String getTitle() { |
|
99 |
return doctitle; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Set the document title |
|
104 |
* |
|
105 |
* @param title the new title for the document |
|
106 |
*/ |
|
107 |
public void setTitle( String title ) { |
|
108 |
this.doctitle = title; |
|
109 |
try { |
|
110 |
PreparedStatement pstmt; |
|
111 |
pstmt = conn.prepareStatement( |
|
112 |
"UPDATE xml_documents " + |
|
113 |
" SET doctitle = ? " + |
|
114 |
"WHERE docid = ?"); |
|
115 |
|
|
116 |
// Bind the values to the query |
|
117 |
pstmt.setString(1, doctitle); |
|
118 |
pstmt.setLong(2, docid); |
|
119 |
|
|
120 |
// Do the insertion |
|
121 |
pstmt.execute(); |
|
122 |
pstmt.close(); |
|
123 |
} catch (SQLException e) { |
|
124 |
System.out.println(e.getMessage()); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Look up the title of the first child element named "title" |
|
130 |
* and record it as the document title |
|
131 |
*/ |
|
132 |
public void setTitleFromChildElement() { |
|
133 |
String title = null; |
|
134 |
long assigned_id=0; |
|
135 |
PreparedStatement pstmt; |
|
136 |
try { |
|
137 |
pstmt = conn.prepareStatement("SELECT nodedata " + |
|
138 |
"FROM xml_nodes " + |
|
139 |
"WHERE nodename = 'title' " + |
|
140 |
"START WITH nodeid = ? " + |
|
141 |
"CONNECT BY PRIOR nodeid = parentnodeid "); |
|
142 |
|
|
143 |
// Bind the values to the query |
|
144 |
pstmt.setLong(1, rootnodeid); |
|
145 |
|
|
146 |
pstmt.execute(); |
|
147 |
try { |
|
148 |
ResultSet rs = pstmt.getResultSet(); |
|
149 |
try { |
|
150 |
boolean tableHasRows = rs.next(); |
|
151 |
if (tableHasRows) { |
|
152 |
try { |
|
153 |
title = rs.getString(1); |
|
154 |
} catch (SQLException e) { |
|
155 |
System.out.println("Error with getString: " + e.getMessage()); } |
|
156 |
} |
|
157 |
} catch (SQLException e) { |
|
158 |
System.out.println("Error with next: " + e.getMessage()); |
|
159 |
} |
|
160 |
} catch (SQLException e) { |
|
161 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
162 |
} |
|
163 |
pstmt.close(); |
|
164 |
} catch (SQLException e) { |
|
165 |
System.out.println("Error getting id: " + e.getMessage()); |
|
166 |
} |
|
167 |
|
|
168 |
// assign the new title |
|
169 |
this.setTitle(title); |
|
170 |
} |
|
171 |
|
|
71 | 172 |
} |
src/xmltables.sql | ||
---|---|---|
63 | 63 |
rootnodeid NUMBER(20), |
64 | 64 |
docname VARCHAR2(100), |
65 | 65 |
doctype VARCHAR2(100), |
66 |
doctitle VARCHAR2(1000), |
|
66 | 67 |
date_created DATE, |
67 | 68 |
date_updated DATE, |
68 | 69 |
CONSTRAINT xml_documents_pk PRIMARY KEY (docid), |
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
static int elementNo = 0; |
36 | 36 |
static String docname; |
37 |
private DBSAXDocument currentDocument; |
|
37 | 38 |
private String doctype; |
38 | 39 |
private String systemid; |
40 |
private long rootnodeid = 0; |
|
39 | 41 |
private boolean debug = false; |
40 | 42 |
private boolean stackCreated = false; |
41 | 43 |
private Stack elementStack; |
... | ... | |
67 | 69 |
/** SAX Handler that receives notification of end of the document */ |
68 | 70 |
public void endDocument() throws SAXException |
69 | 71 |
{ |
72 |
currentDocument.setTitleFromChildElement(); |
|
73 |
System.out.println(currentDocument.getTitle()); |
|
70 | 74 |
System.out.println("end Document"); |
71 | 75 |
} |
72 | 76 |
|
... | ... | |
136 | 140 |
// go to create document definition in the db |
137 | 141 |
// call once after insertion of the first element |
138 | 142 |
if (parent_id == 0) { |
139 |
long rootnodeid = currentElement.getElementID();
|
|
140 |
new DBSAXDocument(conn, rootnodeid, docname, doctype); |
|
143 |
this.rootnodeid = currentElement.getElementID();
|
|
144 |
currentDocument = new DBSAXDocument(conn, rootnodeid, docname, doctype);
|
|
141 | 145 |
} |
142 | 146 |
|
143 | 147 |
// Add all of the attributes |
src/edu/ucsb/nceas/metacat/DBSAXDocument.java | ||
---|---|---|
20 | 20 |
*/ |
21 | 21 |
public class DBSAXDocument { |
22 | 22 |
|
23 |
private Connection conn;
|
|
23 |
private Connection conn;
|
|
24 | 24 |
private long rootnodeid; |
25 |
private long docid; |
|
25 | 26 |
private String docname; |
26 | 27 |
private String doctype; |
28 |
private String doctitle; |
|
27 | 29 |
|
28 | 30 |
/** |
29 | 31 |
* Construct a new document instance |
30 | 32 |
* |
31 | 33 |
* @param conn the JDBC Connection to which all information is written |
32 | 34 |
* @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. |
|
35 |
* @param docname - the name of DTD, |
|
36 |
* i.e. the name immediately following the DOCTYPE keyword - |
|
37 |
* should be the root element name. |
|
38 |
* (Oracle's and IBM parsers are not aware if it is not the |
|
39 |
* root element name) |
|
40 |
* @param doctype - Public ID of the DTD, |
|
41 |
* i.e. the name immediately following the PUBLIC keyword in |
|
42 |
* DOCTYPE declaration. |
|
43 |
* @param doctitle - document title from first child element named "title" |
|
36 | 44 |
* |
37 | 45 |
*/ |
38 |
public DBSAXDocument (Connection conn, long rootnodeid, String docname, String doctype) |
|
46 |
public DBSAXDocument (Connection conn, long rootnodeid, String docname, |
|
47 |
String doctype) |
|
39 | 48 |
{ |
40 | 49 |
this.conn = conn; |
41 | 50 |
this.rootnodeid = rootnodeid; |
... | ... | |
51 | 60 |
conn.setAutoCommit(false); |
52 | 61 |
PreparedStatement pstmt; |
53 | 62 |
pstmt = conn.prepareStatement( |
54 |
"INSERT INTO xml_documents (docid, rootnodeid, docname, doctype) " + |
|
55 |
"VALUES (null, ?, ?, ?)"); |
|
63 |
"INSERT INTO xml_documents " + |
|
64 |
"(docid, rootnodeid, docname, doctype, doctitle) " + |
|
65 |
"VALUES (null, ?, ?, ?, ?)"); |
|
56 | 66 |
|
57 | 67 |
// Bind the values to the query |
58 | 68 |
pstmt.setLong(1, rootnodeid); |
59 | 69 |
pstmt.setString(2, docname); |
60 | 70 |
pstmt.setString(3, doctype); |
71 |
pstmt.setString(4, doctitle); |
|
61 | 72 |
// Do the insertion |
62 | 73 |
pstmt.execute(); |
63 | 74 |
pstmt.close(); |
75 |
|
|
76 |
long assigned_id=0; |
|
77 |
Statement stmt; |
|
78 |
stmt = conn.createStatement(); |
|
79 |
stmt.execute("SELECT xml_documents_id_seq.currval FROM dual"); |
|
80 |
ResultSet rs = stmt.getResultSet(); |
|
81 |
boolean tableHasRows = rs.next(); |
|
82 |
if (tableHasRows) { |
|
83 |
assigned_id = rs.getLong(1); |
|
84 |
this.docid = assigned_id; |
|
85 |
} |
|
86 |
stmt.close(); |
|
87 |
|
|
64 | 88 |
conn.commit(); |
65 | 89 |
conn.setAutoCommit(true); |
66 | 90 |
} catch (SQLException e) { |
... | ... | |
68 | 92 |
} |
69 | 93 |
} |
70 | 94 |
|
95 |
/** |
|
96 |
* Get the document title |
|
97 |
*/ |
|
98 |
public String getTitle() { |
|
99 |
return doctitle; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Set the document title |
|
104 |
* |
|
105 |
* @param title the new title for the document |
|
106 |
*/ |
|
107 |
public void setTitle( String title ) { |
|
108 |
this.doctitle = title; |
|
109 |
try { |
|
110 |
PreparedStatement pstmt; |
|
111 |
pstmt = conn.prepareStatement( |
|
112 |
"UPDATE xml_documents " + |
|
113 |
" SET doctitle = ? " + |
|
114 |
"WHERE docid = ?"); |
|
115 |
|
|
116 |
// Bind the values to the query |
|
117 |
pstmt.setString(1, doctitle); |
|
118 |
pstmt.setLong(2, docid); |
|
119 |
|
|
120 |
// Do the insertion |
|
121 |
pstmt.execute(); |
|
122 |
pstmt.close(); |
|
123 |
} catch (SQLException e) { |
|
124 |
System.out.println(e.getMessage()); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Look up the title of the first child element named "title" |
|
130 |
* and record it as the document title |
|
131 |
*/ |
|
132 |
public void setTitleFromChildElement() { |
|
133 |
String title = null; |
|
134 |
long assigned_id=0; |
|
135 |
PreparedStatement pstmt; |
|
136 |
try { |
|
137 |
pstmt = conn.prepareStatement("SELECT nodedata " + |
|
138 |
"FROM xml_nodes " + |
|
139 |
"WHERE nodename = 'title' " + |
|
140 |
"START WITH nodeid = ? " + |
|
141 |
"CONNECT BY PRIOR nodeid = parentnodeid "); |
|
142 |
|
|
143 |
// Bind the values to the query |
|
144 |
pstmt.setLong(1, rootnodeid); |
|
145 |
|
|
146 |
pstmt.execute(); |
|
147 |
try { |
|
148 |
ResultSet rs = pstmt.getResultSet(); |
|
149 |
try { |
|
150 |
boolean tableHasRows = rs.next(); |
|
151 |
if (tableHasRows) { |
|
152 |
try { |
|
153 |
title = rs.getString(1); |
|
154 |
} catch (SQLException e) { |
|
155 |
System.out.println("Error with getString: " + e.getMessage()); } |
|
156 |
} |
|
157 |
} catch (SQLException e) { |
|
158 |
System.out.println("Error with next: " + e.getMessage()); |
|
159 |
} |
|
160 |
} catch (SQLException e) { |
|
161 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
162 |
} |
|
163 |
pstmt.close(); |
|
164 |
} catch (SQLException e) { |
|
165 |
System.out.println("Error getting id: " + e.getMessage()); |
|
166 |
} |
|
167 |
|
|
168 |
// assign the new title |
|
169 |
this.setTitle(title); |
|
170 |
} |
|
171 |
|
|
71 | 172 |
} |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
203 | 203 |
StringBuffer resultset = new StringBuffer(); |
204 | 204 |
|
205 | 205 |
// Print the resulting root nodes |
206 |
long nodeid; |
|
206 |
Long nodeid; |
|
207 |
String document = null; |
|
207 | 208 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
208 | 209 |
//resultset.append("<!DOCTYPE resultset PUBLIC " + |
209 | 210 |
// "\"-//NCEAS//resultset//EN\" \"resultset.dtd\">\n"); |
... | ... | |
211 | 212 |
resultset.append(" <query>" + query + "</query>"); |
212 | 213 |
Enumeration rootlist = nodelist.keys(); |
213 | 214 |
while (rootlist.hasMoreElements()) { |
214 |
nodeid = ((Long)rootlist.nextElement()).longValue(); |
|
215 |
resultset.append(" <docid>" + nodeid + "</docid>"); |
|
215 |
nodeid = (Long)rootlist.nextElement(); |
|
216 |
document = (String)nodelist.get(nodeid); |
|
217 |
resultset.append(" <document>" + document + "</document>"); |
|
216 | 218 |
} |
217 | 219 |
resultset.append("</resultset>"); |
218 | 220 |
|
src/edu/ucsb/nceas/metacat/DBSimpleQuery.java | ||
---|---|---|
177 | 177 |
while (tableHasRows) { |
178 | 178 |
try { |
179 | 179 |
nodeid = rs.getLong(1); |
180 |
|
|
181 | 180 |
} catch (SQLException e) { |
182 | 181 |
System.out.println("Error with getInt: " + e.getMessage()); |
183 | 182 |
} |
184 | 183 |
|
185 | 184 |
// Advance to the next record in the cursor |
186 | 185 |
tableHasRows = rs.next(); |
187 |
|
|
186 |
|
|
188 | 187 |
} |
189 | 188 |
} catch (SQLException e) { |
190 | 189 |
System.out.println("Error with next: " + e.getMessage()); |
... | ... | |
196 | 195 |
} catch (SQLException e) { |
197 | 196 |
System.out.println("Error getting id: " + e.getMessage()); |
198 | 197 |
} |
199 |
|
|
198 |
|
|
200 | 199 |
// Record that the last record should be the root |
201 | 200 |
rootListResult.put(new Long(nodeid),new Long(nodeid)); |
202 | 201 |
} |
203 | 202 |
|
204 | 203 |
// Now look up the document id |
205 | 204 |
long docid = 0; |
205 |
String docname = null; |
|
206 |
String doctype = null; |
|
207 |
String doctitle = null; |
|
208 |
StringBuffer document = null; |
|
206 | 209 |
Enumeration rootlist = rootListResult.keys(); |
207 | 210 |
while (rootlist.hasMoreElements()) { |
208 | 211 |
nodeid = ((Long)rootlist.nextElement()).longValue(); |
209 | 212 |
|
210 | 213 |
try { |
211 | 214 |
pstmt = |
212 |
conn.prepareStatement("SELECT docid " + |
|
215 |
conn.prepareStatement("SELECT docid,docname,doctype,doctitle " +
|
|
213 | 216 |
"FROM xml_documents " + |
214 | 217 |
"WHERE rootnodeid = ?"); |
215 | 218 |
// Bind the values to the query |
... | ... | |
223 | 226 |
while (tableHasRows) { |
224 | 227 |
try { |
225 | 228 |
docid = rs.getLong(1); |
229 |
docname = rs.getString(2); |
|
230 |
doctype = rs.getString(3); |
|
231 |
doctitle = rs.getString(4); |
|
226 | 232 |
|
233 |
document = new StringBuffer(); |
|
234 |
document.append("<docid>").append(docid).append("</docid>"); |
|
235 |
if (docname != null) { |
|
236 |
document.append("<docname>" + docname + "</docname>"); |
|
237 |
} |
|
238 |
if (doctype != null) { |
|
239 |
document.append("<doctype>" + doctype + "</doctype>"); |
|
240 |
} |
|
241 |
if (doctitle != null) { |
|
242 |
document.append("<doctitle>" + doctitle + "</doctitle>"); |
|
243 |
} |
|
227 | 244 |
} catch (SQLException e) { |
228 | 245 |
System.out.println("Error with getLong: " + e.getMessage()); |
229 | 246 |
} |
... | ... | |
244 | 261 |
} |
245 | 262 |
|
246 | 263 |
// Store the document id and the root node id |
247 |
docListResult.put(new Long(docid),new Long(nodeid));
|
|
264 |
docListResult.put(new Long(docid),(String)document.toString());
|
|
248 | 265 |
} |
249 | 266 |
|
250 | 267 |
return docListResult; |
MetaCatServlet.java | ||
---|---|---|
203 | 203 |
StringBuffer resultset = new StringBuffer(); |
204 | 204 |
|
205 | 205 |
// Print the resulting root nodes |
206 |
long nodeid; |
|
206 |
Long nodeid; |
|
207 |
String document = null; |
|
207 | 208 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
208 | 209 |
//resultset.append("<!DOCTYPE resultset PUBLIC " + |
209 | 210 |
// "\"-//NCEAS//resultset//EN\" \"resultset.dtd\">\n"); |
... | ... | |
211 | 212 |
resultset.append(" <query>" + query + "</query>"); |
212 | 213 |
Enumeration rootlist = nodelist.keys(); |
213 | 214 |
while (rootlist.hasMoreElements()) { |
214 |
nodeid = ((Long)rootlist.nextElement()).longValue(); |
|
215 |
resultset.append(" <docid>" + nodeid + "</docid>"); |
|
215 |
nodeid = (Long)rootlist.nextElement(); |
|
216 |
document = (String)nodelist.get(nodeid); |
|
217 |
resultset.append(" <document>" + document + "</document>"); |
|
216 | 218 |
} |
217 | 219 |
resultset.append("</resultset>"); |
218 | 220 |
|
lib/resultset.xsl | ||
---|---|---|
41 | 41 |
<table width="100%"> |
42 | 42 |
<tr class="rowodd"> |
43 | 43 |
<th> </th> |
44 |
<th><xsl:text>Document ID</xsl:text></th> |
|
44 |
<th><xsl:text>Document</xsl:text></th> |
|
45 |
<th><xsl:text>Document Type</xsl:text></th> |
|
45 | 46 |
<th><xsl:text>Title</xsl:text></th> |
46 | 47 |
</tr> |
47 | 48 |
|
48 |
<xsl:for-each select="resultset/docid">
|
|
49 |
<xsl:for-each select="resultset/document">
|
|
49 | 50 |
<tr valign="top"> |
50 | 51 |
<xsl:attribute name="class"> |
51 | 52 |
<xsl:choose> |
... | ... | |
57 | 58 |
<td> |
58 | 59 |
<input type="radio" name="docid"> |
59 | 60 |
<xsl:attribute name="value"> |
60 |
<xsl:value-of select="."/> |
|
61 |
<xsl:value-of select="./docid"/>
|
|
61 | 62 |
</xsl:attribute> |
62 | 63 |
</input> |
63 | 64 |
<input type="submit" value="Display"/> |
64 | 65 |
<!-- |
65 | 66 |
<a> |
66 | 67 |
<xsl:attribute name="href"> |
67 |
/servlets/MetaCatServlet?action=getdocument&docid=<xsl:value-of select="."/> |
|
68 |
/servlets/MetaCatServlet?action=getdocument&docid=<xsl:value-of select="./docid"/>
|
|
68 | 69 |
</xsl:attribute> |
69 |
<xsl:text>Document </xsl:text><xsl:value-of select="."/> |
|
70 |
<xsl:text>Document </xsl:text><xsl:value-of select="./docid"/>
|
|
70 | 71 |
</a> |
71 | 72 |
--> |
72 | 73 |
</td> |
73 | 74 |
<td> |
74 |
<xsl:text>Document </xsl:text><xsl:value-of select="."/> |
|
75 |
<xsl:value-of select="./docname"/> |
|
76 |
<xsl:text> </xsl:text> |
|
77 |
<xsl:value-of select="./docid"/> |
|
75 | 78 |
</td> |
76 |
<td>Fake title</td> |
|
79 |
<td><xsl:value-of select="./doctype"/></td> |
|
80 |
<td><xsl:value-of select="./doctitle"/></td> |
|
77 | 81 |
</tr> |
78 | 82 |
</xsl:for-each> |
79 | 83 |
</table> |
lib/style/resultset.xsl | ||
---|---|---|
41 | 41 |
<table width="100%"> |
42 | 42 |
<tr class="rowodd"> |
43 | 43 |
<th> </th> |
44 |
<th><xsl:text>Document ID</xsl:text></th> |
|
44 |
<th><xsl:text>Document</xsl:text></th> |
|
45 |
<th><xsl:text>Document Type</xsl:text></th> |
|
45 | 46 |
<th><xsl:text>Title</xsl:text></th> |
46 | 47 |
</tr> |
47 | 48 |
|
48 |
<xsl:for-each select="resultset/docid">
|
|
49 |
<xsl:for-each select="resultset/document">
|
|
49 | 50 |
<tr valign="top"> |
50 | 51 |
<xsl:attribute name="class"> |
51 | 52 |
<xsl:choose> |
... | ... | |
57 | 58 |
<td> |
58 | 59 |
<input type="radio" name="docid"> |
59 | 60 |
<xsl:attribute name="value"> |
60 |
<xsl:value-of select="."/> |
|
61 |
<xsl:value-of select="./docid"/>
|
|
61 | 62 |
</xsl:attribute> |
62 | 63 |
</input> |
63 | 64 |
<input type="submit" value="Display"/> |
64 | 65 |
<!-- |
65 | 66 |
<a> |
66 | 67 |
<xsl:attribute name="href"> |
67 |
/servlets/MetaCatServlet?action=getdocument&docid=<xsl:value-of select="."/> |
|
68 |
/servlets/MetaCatServlet?action=getdocument&docid=<xsl:value-of select="./docid"/>
|
|
68 | 69 |
</xsl:attribute> |
69 |
<xsl:text>Document </xsl:text><xsl:value-of select="."/> |
|
70 |
<xsl:text>Document </xsl:text><xsl:value-of select="./docid"/>
|
|
70 | 71 |
</a> |
71 | 72 |
--> |
72 | 73 |
</td> |
73 | 74 |
<td> |
74 |
<xsl:text>Document </xsl:text><xsl:value-of select="."/> |
|
75 |
<xsl:value-of select="./docname"/> |
|
76 |
<xsl:text> </xsl:text> |
|
77 |
<xsl:value-of select="./docid"/> |
|
75 | 78 |
</td> |
76 |
<td>Fake title</td> |
|
79 |
<td><xsl:value-of select="./doctype"/></td> |
|
80 |
<td><xsl:value-of select="./doctitle"/></td> |
|
77 | 81 |
</tr> |
78 | 82 |
</xsl:for-each> |
79 | 83 |
</table> |
DBSAXHandler.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
static int elementNo = 0; |
36 | 36 |
static String docname; |
37 |
private DBSAXDocument currentDocument; |
|
37 | 38 |
private String doctype; |
38 | 39 |
private String systemid; |
40 |
private long rootnodeid = 0; |
|
39 | 41 |
private boolean debug = false; |
40 | 42 |
private boolean stackCreated = false; |
41 | 43 |
private Stack elementStack; |
... | ... | |
67 | 69 |
/** SAX Handler that receives notification of end of the document */ |
68 | 70 |
public void endDocument() throws SAXException |
69 | 71 |
{ |
72 |
currentDocument.setTitleFromChildElement(); |
|
73 |
System.out.println(currentDocument.getTitle()); |
|
70 | 74 |
System.out.println("end Document"); |
71 | 75 |
} |
72 | 76 |
|
... | ... | |
136 | 140 |
// go to create document definition in the db |
137 | 141 |
// call once after insertion of the first element |
138 | 142 |
if (parent_id == 0) { |
139 |
long rootnodeid = currentElement.getElementID();
|
|
140 |
new DBSAXDocument(conn, rootnodeid, docname, doctype); |
|
143 |
this.rootnodeid = currentElement.getElementID();
|
|
144 |
currentDocument = new DBSAXDocument(conn, rootnodeid, docname, doctype);
|
|
141 | 145 |
} |
142 | 146 |
|
143 | 147 |
// Add all of the attributes |
xmltables.sql | ||
---|---|---|
63 | 63 |
rootnodeid NUMBER(20), |
64 | 64 |
docname VARCHAR2(100), |
65 | 65 |
doctype VARCHAR2(100), |
66 |
doctitle VARCHAR2(1000), |
|
66 | 67 |
date_created DATE, |
67 | 68 |
date_updated DATE, |
68 | 69 |
CONSTRAINT xml_documents_pk PRIMARY KEY (docid), |
resultset.xsl | ||
---|---|---|
41 | 41 |
<table width="100%"> |
42 | 42 |
<tr class="rowodd"> |
43 | 43 |
<th> </th> |
44 |
<th><xsl:text>Document ID</xsl:text></th> |
|
44 |
<th><xsl:text>Document</xsl:text></th> |
|
45 |
<th><xsl:text>Document Type</xsl:text></th> |
|
45 | 46 |
<th><xsl:text>Title</xsl:text></th> |
46 | 47 |
</tr> |
47 | 48 |
|
48 |
<xsl:for-each select="resultset/docid">
|
|
49 |
<xsl:for-each select="resultset/document">
|
|
49 | 50 |
<tr valign="top"> |
50 | 51 |
<xsl:attribute name="class"> |
51 | 52 |
<xsl:choose> |
... | ... | |
57 | 58 |
<td> |
58 | 59 |
<input type="radio" name="docid"> |
59 | 60 |
<xsl:attribute name="value"> |
60 |
<xsl:value-of select="."/> |
|
61 |
<xsl:value-of select="./docid"/>
|
|
61 | 62 |
</xsl:attribute> |
62 | 63 |
</input> |
63 | 64 |
<input type="submit" value="Display"/> |
64 | 65 |
<!-- |
65 | 66 |
<a> |
66 | 67 |
<xsl:attribute name="href"> |
67 |
/servlets/MetaCatServlet?action=getdocument&docid=<xsl:value-of select="."/> |
|
68 |
/servlets/MetaCatServlet?action=getdocument&docid=<xsl:value-of select="./docid"/>
|
|
68 | 69 |
</xsl:attribute> |
69 |
<xsl:text>Document </xsl:text><xsl:value-of select="."/> |
|
70 |
<xsl:text>Document </xsl:text><xsl:value-of select="./docid"/>
|
|
70 | 71 |
</a> |
71 | 72 |
--> |
72 | 73 |
</td> |
73 | 74 |
<td> |
74 |
<xsl:text>Document </xsl:text><xsl:value-of select="."/> |
|
75 |
<xsl:value-of select="./docname"/> |
|
76 |
<xsl:text> </xsl:text> |
|
77 |
<xsl:value-of select="./docid"/> |
|
75 | 78 |
</td> |
76 |
<td>Fake title</td> |
|
79 |
<td><xsl:value-of select="./doctype"/></td> |
|
80 |
<td><xsl:value-of select="./doctitle"/></td> |
|
77 | 81 |
</tr> |
78 | 82 |
</xsl:for-each> |
79 | 83 |
</table> |
DBSimpleQuery.java | ||
---|---|---|
177 | 177 |
while (tableHasRows) { |
178 | 178 |
try { |
179 | 179 |
nodeid = rs.getLong(1); |
180 |
|
|
181 | 180 |
} catch (SQLException e) { |
182 | 181 |
System.out.println("Error with getInt: " + e.getMessage()); |
183 | 182 |
} |
184 | 183 |
|
185 | 184 |
// Advance to the next record in the cursor |
186 | 185 |
tableHasRows = rs.next(); |
187 |
|
|
186 |
|
|
188 | 187 |
} |
189 | 188 |
} catch (SQLException e) { |
190 | 189 |
System.out.println("Error with next: " + e.getMessage()); |
... | ... | |
196 | 195 |
} catch (SQLException e) { |
197 | 196 |
System.out.println("Error getting id: " + e.getMessage()); |
198 | 197 |
} |
199 |
|
|
198 |
|
|
200 | 199 |
// Record that the last record should be the root |
201 | 200 |
rootListResult.put(new Long(nodeid),new Long(nodeid)); |
202 | 201 |
} |
203 | 202 |
|
204 | 203 |
// Now look up the document id |
205 | 204 |
long docid = 0; |
205 |
String docname = null; |
|
206 |
String doctype = null; |
|
207 |
String doctitle = null; |
|
208 |
StringBuffer document = null; |
|
206 | 209 |
Enumeration rootlist = rootListResult.keys(); |
207 | 210 |
while (rootlist.hasMoreElements()) { |
208 | 211 |
nodeid = ((Long)rootlist.nextElement()).longValue(); |
209 | 212 |
|
210 | 213 |
try { |
211 | 214 |
pstmt = |
212 |
conn.prepareStatement("SELECT docid " + |
|
215 |
conn.prepareStatement("SELECT docid,docname,doctype,doctitle " +
|
|
213 | 216 |
"FROM xml_documents " + |
214 | 217 |
"WHERE rootnodeid = ?"); |
215 | 218 |
// Bind the values to the query |
... | ... | |
223 | 226 |
while (tableHasRows) { |
224 | 227 |
try { |
225 | 228 |
docid = rs.getLong(1); |
229 |
docname = rs.getString(2); |
|
230 |
doctype = rs.getString(3); |
|
231 |
doctitle = rs.getString(4); |
|
226 | 232 |
|
233 |
document = new StringBuffer(); |
|
234 |
document.append("<docid>").append(docid).append("</docid>"); |
|
235 |
if (docname != null) { |
|
236 |
document.append("<docname>" + docname + "</docname>"); |
|
237 |
} |
|
238 |
if (doctype != null) { |
|
239 |
document.append("<doctype>" + doctype + "</doctype>"); |
|
240 |
} |
|
241 |
if (doctitle != null) { |
|
242 |
document.append("<doctitle>" + doctitle + "</doctitle>"); |
|
243 |
} |
|
227 | 244 |
} catch (SQLException e) { |
228 | 245 |
System.out.println("Error with getLong: " + e.getMessage()); |
229 | 246 |
} |
... | ... | |
244 | 261 |
} |
245 | 262 |
|
246 | 263 |
// Store the document id and the root node id |
247 |
docListResult.put(new Long(docid),new Long(nodeid));
|
|
264 |
docListResult.put(new Long(docid),(String)document.toString());
|
|
248 | 265 |
} |
249 | 266 |
|
250 | 267 |
return docListResult; |
Also available in: Unified diff
improved query result handling