Changeset 9815
- Timestamp:
- 2005-05-04T16:15:31+12:00 (19 years ago)
- Location:
- branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java
r9288 r9815 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. -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java
r9529 r9815 20 20 21 21 // Greenstone classes 22 import org.greenstone.gsdl3.core.GSException; 22 23 import org.greenstone.gsdl3.util.GSXML; 23 24 import org.greenstone.gsdl3.util.GSFile; … … 146 147 // assumes only one value per metadata 147 148 protected Element getMetadataList(String node_id, boolean all_metadata, 148 ArrayList metadata_names) { 149 ArrayList metadata_names) 150 throws GSException { 149 151 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 150 152 DBInfo info = this.gdbm_src.getInfo(node_id); … … 281 283 * <nodeContent>text content or other elements</nodeContent> 282 284 */ 283 abstract protected Element getNodeContent(String doc_id) ;285 abstract protected Element getNodeContent(String doc_id) throws GSException; 284 286 285 287 protected String getMetadata(String node_id, DBInfo info, -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS3DocumentRetrieve.java
r9000 r9815 20 20 21 21 // Greenstone classes 22 import org.greenstone.gsdl3.core.GSException; 22 23 import org.greenstone.gsdl3.util.GSXML; 23 24 import org.greenstone.gsdl3.util.GSFile; … … 109 110 } 110 111 111 /** if an id is not a greenstone id (an external id) then translate112 it to a greenstone one*/113 protected String translateExternalId(String node_id){114 // dont have this yet115 return node_id;116 }117 118 112 /** returns the id of the root node of the document containing node node_id. . may be the same as node_id */ 119 113 protected String getRootId(String node_id) { … … 150 144 // assumes only one value per metadata 151 145 protected Element getMetadataList(String node_id, boolean all_metadata, 152 ArrayList metadata_names) { 146 ArrayList metadata_names) 147 throws GSException { 153 148 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 154 149 … … 215 210 * <nodeContent>text content or other elements</nodeContent> 216 211 */ 217 abstract protected Element getNodeContent(String doc_id) ;212 abstract protected Element getNodeContent(String doc_id) throws GSException; 218 213 219 214 } -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractMGSearch.java
r9280 r9815 201 201 this.mg_src.runQuery(basedir, textdir, query); 202 202 MGQueryResult mqr = this.mg_src.getQueryResult(); 203 if (mqr.isClear()) { 204 // something has gone wrong 205 GSXML.addError(this.doc, result, "Couldn't query the mg database", GSXML.ERROR_TYPE_SYSTEM); 206 return result; 207 } 203 208 long totalDocs = mqr.getTotalDocs(); 204 209 -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java
r8959 r9815 21 21 // Greenstone classes 22 22 import org.greenstone.mgpp.*; 23 import org.greenstone.gsdl3.core.GSException; 23 24 import org.greenstone.gsdl3.util.GSFile; 24 25 import org.greenstone.gsdl3.util.GSXML; … … 79 80 * <nodeContent>text content or other elements</nodeContent> 80 81 */ 81 protected Element getNodeContent(String doc_id) {82 protected Element getNodeContent(String doc_id) throws GSException { 82 83 String lang = "en"; // ********** 83 84 long doc_num = this.gdbm_src.OID2Docnum(doc_id); -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java
r8959 r9815 21 21 // Greenstone classes 22 22 import org.greenstone.mg.*; 23 import org.greenstone.gsdl3.core.GSException; 23 24 import org.greenstone.gsdl3.util.GSFile; 24 25 import org.greenstone.gsdl3.util.GSXML; … … 80 81 * <nodeContent>text content or other elements</nodeContent> 81 82 */ 82 protected Element getNodeContent(String doc_id) {83 protected Element getNodeContent(String doc_id) throws GSException { 83 84 String lang = "en"; // ********** 84 85 long doc_num = this.gdbm_src.OID2Docnum(doc_id); -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPRetrieve.java
r9784 r9815 21 21 // Greenstone classes 22 22 import org.greenstone.mgpp.*; 23 import org.greenstone.gsdl3.core.GSException; 23 24 import org.greenstone.gsdl3.util.GSFile; 24 25 import org.greenstone.gsdl3.util.GSXML; … … 80 81 * <nodeContent>text content or other elements</nodeContent> 81 82 */ 82 protected Element getNodeContent(String doc_id) {83 protected Element getNodeContent(String doc_id) throws GSException { 83 84 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) { 84 85 // if we have a whole doc id, and the document is hierarchical, -
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java
r9001 r9815 21 21 // Greenstone classes 22 22 import org.greenstone.mg.*; 23 import org.greenstone.gsdl3.core.GSException; 23 24 import org.greenstone.gsdl3.util.GSFile; 24 25 import org.greenstone.gsdl3.util.GSXML; … … 86 87 * <nodeContent>text content or other elements</nodeContent> 87 88 */ 88 protected Element getNodeContent(String doc_id) {89 protected Element getNodeContent(String doc_id) throws GSException { 89 90 90 91 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) { … … 111 112 } catch (Exception e) { 112 113 System.out.println("exception happended with mg_src.getDocument()"); 113 doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n"; 114 throw new GSException("Couldn't get document content for id: "+ doc_int+"\n"+e.getMessage()); 115 //doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n"; 114 116 } 115 117
Note:
See TracChangeset
for help on using the changeset viewer.