Revision 800
Added by Matt Jones over 23 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
284 | 284 |
{ //there was a backtrackable document found |
285 | 285 |
DocumentImpl xmldoc = null; |
286 | 286 |
String packageDocid = btrs.getString(1); |
287 |
util.debugMessage("Getting document for docid: " + packageDocid); |
|
287 | 288 |
try |
288 | 289 |
{ |
289 |
// THIS CONSTRUCTOR BUILDS THE WHOLE XML doc not needed here |
|
290 |
// xmldoc = new DocumentImpl(dbconn, packageDocid); |
|
291 |
// thus use the following to get the doc info only |
|
292 |
xmldoc = new DocumentImpl(dbconn); |
|
293 |
xmldoc.getDocumentInfo(packageDocid); |
|
290 |
// THIS CONSTRUCTOR BUILDS THE WHOLE XML doc not needed here |
|
291 |
// xmldoc = new DocumentImpl(dbconn, packageDocid); |
|
292 |
// thus use the following to get the doc info only |
|
293 |
// xmldoc = new DocumentImpl(dbconn); |
|
294 |
xmldoc = new DocumentImpl(dbconn, packageDocid, false); |
|
295 |
if (xmldoc == null) { |
|
296 |
util.debugMessage("Document was null for: " + packageDocid); |
|
297 |
} |
|
294 | 298 |
} |
295 | 299 |
catch(Exception e) |
296 | 300 |
{ |
... | ... | |
298 | 302 |
"DBQuery.findDocuments: " + e.getMessage()); |
299 | 303 |
} |
300 | 304 |
|
301 |
docid = xmldoc.getDocID().trim(); |
|
305 |
String docid_org = xmldoc.getDocID(); |
|
306 |
if (docid_org == null) { |
|
307 |
util.debugMessage("Docid_org was null."); |
|
308 |
} |
|
309 |
docid = docid_org.trim(); |
|
302 | 310 |
docname = xmldoc.getDocname(); |
303 | 311 |
doctype = xmldoc.getDoctype(); |
304 | 312 |
createDate = xmldoc.getCreateDate(); |
... | ... | |
478 | 486 |
System.err.println("IO error in DBQuery.findDocuments:"); |
479 | 487 |
System.err.println(ioe.getMessage()); |
480 | 488 |
} catch (Exception ee) { |
481 |
System.out.println("Exception in DBQuery.findDocuments: " +
|
|
489 |
System.err.println("Exception in DBQuery.findDocuments: " +
|
|
482 | 490 |
ee.getMessage()); |
491 |
ee.printStackTrace(System.err); |
|
483 | 492 |
} |
484 | 493 |
finally { |
485 | 494 |
try |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
214 | 214 |
|
215 | 215 |
// Deal with forms that are encoded as "multipart/form-data" differently |
216 | 216 |
// this is mainly used for uploading non-xml files using that may be binary |
217 |
if (request.getContentType().startsWith("multipart/form-data")) { |
|
217 |
String ctype = request.getContentType(); |
|
218 |
if (ctype != null && ctype.startsWith("multipart/form-data")) { |
|
218 | 219 |
handleMultipartForm(request, response); |
219 | 220 |
} else { |
220 | 221 |
// This probably means the data is "application/x-www-url-encoded", we hope :-) |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
91 | 91 |
private TreeSet nodeRecordList = null; |
92 | 92 |
|
93 | 93 |
/** |
94 |
* Constructor used from DBQuery.findDocuments(); |
|
95 |
* used with getDocumentInfo() to get document info from xml_documents |
|
94 |
* Constructor used to create a document and read the document information |
|
95 |
* from the database. If readNodes is false, then the node data is not |
|
96 |
* read at this time, but is deferred until it is needed (such as when a |
|
97 |
* call to toXml() is made). |
|
96 | 98 |
* |
97 | 99 |
* @param conn the database connection from which to read the document |
100 |
* @param docid the identifier of the document to be created |
|
101 |
* @param readNodes flag indicating whether the xmlnodes should be read |
|
98 | 102 |
*/ |
99 |
public DocumentImpl(Connection conn) throws McdbException |
|
103 |
public DocumentImpl(Connection conn, String docid, boolean readNodes) throws McdbException
|
|
100 | 104 |
{ |
101 |
this.conn = conn; |
|
105 |
this(conn, docid); |
|
106 |
|
|
107 |
if (readNodes) { |
|
108 |
try { |
|
109 |
// Download all of the document nodes using a single SQL query |
|
110 |
// The sort order of the records is determined by the NodeComparator |
|
111 |
// class, and needs to represent a depth-first traversal for the |
|
112 |
// toXml() method to work properly |
|
113 |
nodeRecordList = getNodeRecordList(rootnodeid); |
|
114 |
|
|
115 |
} catch (McdbException ex) { |
|
116 |
throw ex; |
|
117 |
} catch (Throwable t) { |
|
118 |
throw new McdbException("Error reading document from " + |
|
119 |
"DocumentImpl.DocumentImpl: " + docid); |
|
120 |
} |
|
121 |
} |
|
102 | 122 |
} |
103 | 123 |
|
104 | 124 |
/** |
... | ... | |
114 | 134 |
this.conn = conn; |
115 | 135 |
this.docid = docid; |
116 | 136 |
|
117 |
// NOT NEEDED |
|
118 |
//DocumentIdentifier id = new DocumentIdentifier(docid); |
|
119 |
|
|
120 | 137 |
// Look up the document information |
121 | 138 |
getDocumentInfo(docid); |
122 | 139 |
|
123 |
// Download all of the document nodes using a single SQL query |
|
124 |
// The sort order of the records is determined by the NodeComparator |
|
125 |
// class, and needs to represent a depth-first traversal for the |
|
126 |
// toXml() method to work properly |
|
127 |
nodeRecordList = getNodeRecordList(rootnodeid); |
|
128 |
|
|
129 | 140 |
} catch (McdbException ex) { |
130 | 141 |
throw ex; |
131 | 142 |
} catch (Throwable t) { |
... | ... | |
322 | 333 |
public String toString() |
323 | 334 |
{ |
324 | 335 |
StringWriter docwriter = new StringWriter(); |
325 |
this.toXml(docwriter); |
|
336 |
try { |
|
337 |
this.toXml(docwriter); |
|
338 |
} catch (McdbException mcdbe) { |
|
339 |
return null; |
|
340 |
} |
|
326 | 341 |
String document = docwriter.toString(); |
327 | 342 |
return document; |
328 | 343 |
} |
... | ... | |
337 | 352 |
* to completion is O(N^N) wrt the number of nodes. See toXml() for a |
338 | 353 |
* better algorithm. |
339 | 354 |
*/ |
340 |
public String readUsingSlowAlgorithm() |
|
355 |
public String readUsingSlowAlgorithm() throws McdbException
|
|
341 | 356 |
{ |
342 | 357 |
StringBuffer doc = new StringBuffer(); |
343 | 358 |
|
359 |
// First, check that we have the needed node data, and get it if not |
|
360 |
if (nodeRecordList == null) { |
|
361 |
nodeRecordList = getNodeRecordList(rootnodeid); |
|
362 |
} |
|
363 |
|
|
344 | 364 |
// Create the elements from the downloaded data in the TreeSet |
345 | 365 |
rootNode = new ElementNode(nodeRecordList, rootnodeid); |
346 | 366 |
|
... | ... | |
365 | 385 |
* |
366 | 386 |
* @param pw the Writer to which we print the document |
367 | 387 |
*/ |
368 |
public void toXml(Writer pw) |
|
388 |
public void toXml(Writer pw) throws McdbException
|
|
369 | 389 |
{ |
370 | 390 |
PrintWriter out = null; |
371 | 391 |
if (pw instanceof PrintWriter) { |
... | ... | |
376 | 396 |
|
377 | 397 |
MetaCatUtil util = new MetaCatUtil(); |
378 | 398 |
|
399 |
// First, check that we have the needed node data, and get it if not |
|
400 |
if (nodeRecordList == null) { |
|
401 |
nodeRecordList = getNodeRecordList(rootnodeid); |
|
402 |
} |
|
403 |
|
|
379 | 404 |
Stack openElements = new Stack(); |
380 | 405 |
boolean atRootElement = true; |
381 | 406 |
boolean previousNodeWasElement = false; |
... | ... | |
533 | 558 |
"' does not exist"); |
534 | 559 |
} |
535 | 560 |
|
536 |
public void getDocumentInfo(String docid) throws McdbException,
|
|
561 |
private void getDocumentInfo(String docid) throws McdbException,
|
|
537 | 562 |
AccessionNumberException |
538 | 563 |
{ |
539 | 564 |
getDocumentInfo(new DocumentIdentifier(docid)); |
src/edu/ucsb/nceas/metacat/RelationHandler.java | ||
---|---|---|
60 | 60 |
// add a new row to xml_relation that represents this new relation |
61 | 61 |
try { |
62 | 62 |
|
63 |
DocumentImpl xmldoc = new DocumentImpl(conn); |
|
64 |
xmldoc.getDocumentInfo(docid); |
|
63 |
DocumentImpl xmldoc = new DocumentImpl(conn,docid,false); |
|
64 |
//DocumentImpl xmldoc = new DocumentImpl(conn); |
|
65 |
//xmldoc.getDocumentInfo(docid); |
|
65 | 66 |
String packagetype = xmldoc.getDoctype(); |
66 | 67 |
|
67 | 68 |
// first delete the relations for this package document if any |
Also available in: Unified diff
Added fix to DocumentImpl that showed problems when the DocumentImpl(conn)
constructor was called. Now there is a new constructor:
DocumentImpl(Connection, String, boolean)
where the boolean value is used to determine if the nodeset should be
read a t the time the cosntructor is called. if false, then
nodeRecordList will be null. Later calls to "toXml()" and other methods
that use nodeRecordList now make sure it is non-null before using it.
So, even if the nodeRecordList isn't read in by the constructor, the toXml()
method will still work as expected.
Changed the "getDocumentInfo(String) method to private scope because there
is now no reason for it to be called outside of the class.
Updated DBQuery and RelationHandler to utilize these changes.