- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java
r9288 r9874 23 23 // Greenstone classes 24 24 //import org.greenstone.gdbm.*; 25 import org.greenstone.gsdl3.core.GSException; 25 26 import org.greenstone.gsdl3.util.GSXML; 26 27 import org.greenstone.gsdl3.util.GSPath; … … 165 166 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 166 167 if (param_list == null) { 167 System.err.println("AbstractDocumentRetrieve, DocumentMetadataRetrieve Error: missing paramList.\n");168 return result; // Return the empty result168 GSXML.addError(this.doc, result, "DocumentMetadataRetrieve: missing "+ GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 169 return result; 169 170 } 170 171 … … 190 191 } 191 192 192 Element node_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 193 result.appendChild(node_list); 194 193 // check that there has been some metadata specified 194 if (!all_metadata && metadata_names_list.size()==0) { 195 GSXML.addError(this.doc, result, "DocumentMetadataRetrieve: no metadata names found in the "+ GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 196 return result; 197 } 198 195 199 // Get the documents 196 200 Element request_node_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 197 201 if (request_node_list == null) { 198 System.err.println("Error: DocumentMetadataRetrieve request had no "+GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);202 GSXML.addError(this.doc, result, "DocumentMetadataRetrieve: missing " +GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 199 203 return result; 200 204 } 201 205 202 NodeList request_nodes = request_node_list.getChildNodes(); 206 // copy the request doc node list to the response 207 Element response_node_list = (Element) this.doc.importNode(request_node_list, true); 208 result.appendChild(response_node_list); 209 210 // use the copied list so that we add the metadata into the copy 211 // are we just adding metadata for the top level nodes? or can we accept a hierarchy here??? 212 NodeList request_nodes = GSXML.getChildrenByTagName(response_node_list, GSXML.DOC_NODE_ELEM); 213 if (request_nodes.getLength()==0) { 214 GSXML.addError(this.doc, result, "DocumentMetadataRetrieve: no "+GSXML.DOC_NODE_ELEM +" found in the "+ GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 215 return result; 216 } 217 218 // Whew, now we have checked (almost) all the syntax of the request, now we can process it. 219 203 220 for (int i = 0; i < request_nodes.getLength(); i++) { 204 221 Element request_node = (Element) request_nodes.item(i); 205 222 String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT); 206 223 207 // Add the document to the results list208 Element new_node = (Element)this.doc.importNode(request_node, false);209 node_list.appendChild(new_node);210 211 224 if (external_id) { 212 225 // can we have .pr etc extensions with external ids? … … 219 232 continue; 220 233 } 221 222 Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list); 223 new_node.appendChild(metadata_list); 234 try { 235 Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list); 236 request_node.appendChild(metadata_list); 237 } catch (GSException e) { 238 GSXML.addError(this.doc, result, e.getMessage(), e.getType()); 239 if (e.getType().equals(GSXML.ERROR_TYPE_SYSTEM)) { 240 // there is no point trying any others 241 return result; 242 } 243 } 224 244 } 225 245 … … 240 260 241 261 String lang = request.getAttribute(GSXML.LANG_ATT); 242 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);243 if (query_doc_list == null) {244 System.err.println("AbstractDocumentRetrieve Error: DocumentStructureRetrieve request specified no doc nodes.\n");245 return result;246 }247 262 248 263 // Get the parameters of the request 249 264 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 250 265 if (param_list == null) { 251 System.err.println("AbstractDocumentRetrieve Error: DocumentStructureRetrieve request had no paramList."); 252 return result; // Return the empty result 253 } 266 GSXML.addError(this.doc, result, "DocumentStructureRetrieve: missing "+ GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 267 return result; 268 } 269 270 // get the documents of the request 271 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 272 if (query_doc_list == null) { 273 GSXML.addError(this.doc, result, "DocumentStructureRetrieve: missing " +GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 274 return result; 275 } 276 277 // copy the doc_list to the response 278 Element response_node_list = (Element) this.doc.importNode(query_doc_list, true); 279 result.appendChild(response_node_list); 280 281 // check that we have some doc nodes specified 282 NodeList node_list = GSXML.getChildrenByTagName(response_node_list, GSXML.DOC_NODE_ELEM); 283 if (node_list.getLength()==0) { 284 GSXML.addError(this.doc, result, "DocumentStructureRetrieve: no "+GSXML.DOC_NODE_ELEM +" found in the "+ GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 285 return result; 286 } 287 254 288 Element extid_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTID_PARAM); 255 289 boolean external_id = false; … … 308 342 if (want_descendants) 309 343 want_children = false; 310 311 // the document list to hold the results 312 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 313 result.appendChild(doc_list); 314 315 // Get the documents 316 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list, 317 GSXML.NODE_ID_ATT); 318 for (int i = 0; i < doc_ids.length; i++) { 319 // Add the document to the list 320 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM); 321 doc_list.appendChild(doc); 322 323 String doc_id = doc_ids[i]; 324 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 344 345 for (int i=0; i < node_list.getLength(); i++) { 346 Element doc = (Element) node_list.item(i); 347 String doc_id = doc.getAttribute(GSXML.NODE_ID_ATT); 325 348 if (external_id) { 326 349 doc_id = translateExternalId(doc_id); … … 433 456 } 434 457 435 // Get the parameters of the request - no parameters at this stage458 // Get the parameters of the request 436 459 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 437 460 Element extid_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTID_PARAM); … … 473 496 continue; 474 497 } 475 476 Element node_content = getNodeContent(doc_id); 477 doc.appendChild(node_content); 498 try { 499 Element node_content = getNodeContent(doc_id); 500 doc.appendChild(node_content); 501 } catch (GSException e) { 502 GSXML.addError(this.doc, result, e.getMessage()); 503 return result; 504 505 } 478 506 } 479 507 return result; … … 594 622 } 595 623 596 /** if id ends in .fc, .pc etc, then translate it to the correct id */ 597 abstract protected String translateId(String id); 624 /** if id ends in .fc, .pc etc, then translate it to the correct id 625 * default implementation: just remove the suffix */ 626 protected String translateId(String id) { 627 return id.substring(0,id.length()); 628 } 598 629 599 630 /** if an id is not a greenstone id (an external id) then translate 600 it to a greenstone one*/ 601 abstract protected String translateExternalId(String id); 631 * it to a greenstone one 632 * default implementation: return the id */ 633 protected String translateExternalId(String id) { 634 return id; 635 } 636 602 637 /** returns the document type of the doc that the specified node 603 638 belongs to. should be one of … … 605 640 GSXML.DOC_TYPE_PAGED, 606 641 GSXML.DOC_TYPE_HIERARCHY 642 default implementation: return DOC_TYPE_SIMPLE 607 643 */ 608 abstract protected String getDocType(String node_id); 609 610 /** returns the id of the root node of the document containing node node_id. . may be the same as node_id */ 611 abstract protected String getRootId(String node_id); 612 /** returns a list of the child ids in order, null if no children */ 613 abstract protected ArrayList getChildrenIds(String node_id); 614 /** returns the node id of the parent node, null if no parent */ 615 abstract protected String getParentId(String node_id); 644 protected String getDocType(String node_id) { 645 return GSXML.DOC_TYPE_SIMPLE; 646 } 647 648 649 /** returns the id of the root node of the document containing 650 * node node_id. may be the same as node_id 651 * default implemntation: return node_id 652 */ 653 protected String getRootId(String node_id) { 654 return node_id; 655 } 656 /** returns a list of the child ids in order, null if no children 657 * default implementation: return null */ 658 protected ArrayList getChildrenIds(String node_id) { 659 return null; 660 } 661 /** returns the node id of the parent node, null if no parent 662 * default implementation: return null */ 663 protected String getParentId(String node_id) { 664 return null; 665 } 616 666 617 667 /** get the metadata for the doc node doc_id … … 621 671 abstract protected Element getMetadataList(String doc_id, 622 672 boolean all_metadata, 623 ArrayList metadata_names) ;673 ArrayList metadata_names) throws GSException; 624 674 /** returns the content of a node 625 * shou dlreturn a nodeContent element:675 * should return a nodeContent element: 626 676 * <nodeContent>text content or other elements</nodeContent> 677 * can return 627 678 */ 628 abstract protected Element getNodeContent(String doc_id) ;679 abstract protected Element getNodeContent(String doc_id) throws GSException; 629 680 630 681 /** returns the structural information asked for.
Note:
See TracChangeset
for help on using the changeset viewer.