145 |
145 |
public String readXMLDocument(long docid) {
|
146 |
146 |
StringBuffer doc = new StringBuffer();
|
147 |
147 |
DoctypeInfo dti = getDoctypeInfo(docid);
|
148 |
|
String docname = dti.getDocname();
|
149 |
|
String doctype = dti.getDoctype();
|
150 |
|
String sysid = dti.getSystemID();
|
151 |
148 |
|
152 |
|
ElementNode element = new ElementNode(conn, getRootNode(docid));
|
153 |
|
doc.append("<?xml version=\"1.0\"?>\n");
|
154 |
|
|
155 |
|
if (docname != null) {
|
156 |
|
if ((doctype != null) && (sysid != null)) {
|
157 |
|
doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype +
|
158 |
|
"\" \"" + sysid + "\">\n");
|
159 |
|
} else {
|
160 |
|
doc.append("<!DOCTYPE " + docname + ">\n");
|
|
149 |
if (dti != null) {
|
|
150 |
String docname = dti.getDocname();
|
|
151 |
String doctype = dti.getDoctype();
|
|
152 |
String sysid = dti.getSystemID();
|
|
153 |
|
|
154 |
ElementNode element = new ElementNode(conn, getRootNode(docid));
|
|
155 |
doc.append("<?xml version=\"1.0\"?>\n");
|
|
156 |
|
|
157 |
if (docname != null) {
|
|
158 |
if ((doctype != null) && (sysid != null)) {
|
|
159 |
doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype +
|
|
160 |
"\" \"" + sysid + "\">\n");
|
|
161 |
} else {
|
|
162 |
doc.append("<!DOCTYPE " + docname + ">\n");
|
|
163 |
}
|
161 |
164 |
}
|
|
165 |
doc.append(element.toString());
|
|
166 |
} else {
|
|
167 |
doc.append("<error>Document " + docid + " not found.</error>");
|
162 |
168 |
}
|
163 |
|
doc.append(element.toString());
|
164 |
169 |
|
165 |
170 |
return (doc.toString());
|
166 |
171 |
}
|
... | ... | |
194 |
199 |
}
|
195 |
200 |
pstmt.close();
|
196 |
201 |
|
197 |
|
pstmt =
|
198 |
|
conn.prepareStatement("SELECT system_id " +
|
199 |
|
"FROM xml_catalog " +
|
200 |
|
"WHERE public_id = ?");
|
201 |
|
// Bind the values to the query
|
202 |
|
pstmt.setString(1, doctype);
|
203 |
|
|
204 |
|
pstmt.execute();
|
205 |
|
rs = pstmt.getResultSet();
|
206 |
|
tableHasRows = rs.next();
|
207 |
|
if (tableHasRows) {
|
208 |
|
sysid = rs.getString(1);
|
209 |
|
}
|
210 |
|
pstmt.close();
|
|
202 |
if (doctype != null) {
|
|
203 |
pstmt =
|
|
204 |
conn.prepareStatement("SELECT system_id " +
|
|
205 |
"FROM xml_catalog " +
|
|
206 |
"WHERE public_id = ?");
|
|
207 |
// Bind the values to the query
|
|
208 |
pstmt.setString(1, doctype);
|
|
209 |
|
|
210 |
pstmt.execute();
|
|
211 |
rs = pstmt.getResultSet();
|
|
212 |
tableHasRows = rs.next();
|
|
213 |
if (tableHasRows) {
|
|
214 |
sysid = rs.getString(1);
|
|
215 |
}
|
|
216 |
pstmt.close();
|
|
217 |
}
|
211 |
218 |
} catch (SQLException e) {
|
212 |
219 |
System.out.println("Error getting id: " + e.getMessage());
|
213 |
220 |
}
|
214 |
221 |
|
215 |
|
dti = new DoctypeInfo(docname, doctype, sysid);
|
|
222 |
if (docname != null) {
|
|
223 |
dti = new DoctypeInfo(docname, doctype, sysid);
|
|
224 |
} else {
|
|
225 |
dti = null;
|
|
226 |
}
|
|
227 |
|
216 |
228 |
return dti;
|
217 |
229 |
}
|
218 |
230 |
|
improved error handling when docid not found