Changeset 9874 for trunk/gsdl3/src
- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- Location:
- trunk/gsdl3/src
- Files:
-
- 9 added
- 12 deleted
- 77 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServer.java.in
r8081 r9874 17 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 18 */ 19 19 20 package org.greenstone.gsdl3; 20 21 21 22 import org.greenstone.gsdl3.core.*; 23 import org.greenstone.gsdl3.util.GSXML; 22 24 import org.w3c.dom.Element; 23 25 import java.io.File; … … 30 32 * 31 33 * @author <a href="mailto:[email protected]">Katherine Don</a> 32 * @version $Revision$33 34 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a> 34 35 */ 35 36 36 public class SOAPServer 37 implements ModuleInterface { 38 37 public class SOAPServerlocalsite 38 { 39 39 private String config_file_name = "SOAPServer.cfg"; 40 40 … … 43 43 44 44 /** The no-args constructor */ 45 public SOAPServer () {45 public SOAPServer@sitename@() { 46 46 // find out gsdl3home 47 47 URL url = ClassLoader.getSystemResource(config_file_name); … … 54 54 return; 55 55 } 56 String site_home=gsdl3_home+File.separator+"web"+File.separator+"sites"+File.separator+" @sitename@";56 String site_home=gsdl3_home+File.separator+"web"+File.separator+"sites"+File.separator+"localsite"; 57 57 58 58 File site_file = new File(site_home); … … 66 66 } 67 67 68 69 /** Process a String request */ 70 public String process(String xml_in) { 71 return mr_.process(xml_in); 72 73 } 74 75 /** Process an Element request */ 76 public Element process(Element xml_in) { 77 return mr_.process(xml_in); 68 public Element [] process (Element [] xml_in) { 69 Element [] result = new Element[xml_in.length]; 70 for (int i=0; i<xml_in.length; i++) { 71 Element req = xml_in[i]; 72 // get rid of the obligatory namespace that axis needs 73 String tag_name = req.getTagName(); 74 String namespace=""; 75 if (tag_name.indexOf(':')!= -1) { 76 namespace = tag_name.substring(0, tag_name.indexOf(':')); 77 tag_name = tag_name.substring(tag_name.indexOf(':')+1); 78 } 79 Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true); 80 Element r = mr_.process(new_req); 81 // add the namespace back on 82 //Element new_res = r; 83 //if (!namespace.equals("")) { 84 // new_res = GSXML.duplicateWithNewName(r.getOwnerDocument(), r, namespace+r.getTagName(), true); 85 //} 86 result[i] = r; 87 } 88 return result; 78 89 } 79 90 … … 92 103 return null; 93 104 } 94 105 95 106 } 96 107 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/Action.java
r8832 r9874 52 52 public String process(String xml_in) { 53 53 54 Element message = this.converter.getDOM(xml_in).getDocumentElement(); 55 56 Element result = process(message); 54 Document message_doc = this.converter.getDOM(xml_in); 55 if (message_doc == null) { 56 System.err.println("Action.process(String) Error: Couldn't parse request"); 57 System.err.println(xml_in); 58 return null; 59 } 60 Element result = process(message_doc.getDocumentElement()); 57 61 return this.converter.getString(result); 58 62 } … … 115 119 } 116 120 121 protected boolean processErrorElements(Element message, Element page) { 122 NodeList error_nodes = message.getElementsByTagName(GSXML.ERROR_ELEM); 123 if (error_nodes.getLength()==0) { 124 return false; 125 } 126 Document owner = page.getOwnerDocument(); 127 for (int i=0; i<error_nodes.getLength(); i++) { 128 page.appendChild(owner.importNode(error_nodes.item(i), true)); 129 } 130 return true; 131 } 117 132 } 118 133 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
r9007 r9874 209 209 // Process the document structure retrieve message 210 210 Element ds_response_message = (Element) this.mr.process(ds_message); 211 211 if (processErrorElements(ds_response_message, page_response)) { 212 return result; 213 } 214 212 215 // get the info and print out 213 216 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); … … 309 312 doc_list.appendChild(doc_node); 310 313 Element dm_response_message = (Element) this.mr.process(dm_message); 314 if (processErrorElements(dm_response_message, page_response)) { 315 return result; 316 } 311 317 312 318 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); … … 348 354 System.err.println("request = "+converter.getString(dc_message)); 349 355 Element dc_response_message = (Element) this.mr.process(dc_message); 356 if (processErrorElements(dc_response_message, page_response)) { 357 return result; 358 } 359 350 360 Element dc_response_doc_list = (Element) GSXML.getNodeByPath(dc_response_message, path); 351 361 … … 536 546 HashMap params = GSXML.extractParams(cgi_param_list, false); 537 547 538 539 String service_name = (String)((HashMap)params.get("p")).get(GSParams.SERVICE); 548 HashMap previous_params = (HashMap)params.get("p"); 549 if (previous_params == null) { 550 return dc_response_doc_content; 551 } 552 String service_name = (String)previous_params.get(GSParams.SERVICE); 540 553 if (service_name == null || !service_name.endsWith("Query")) { // hack for now - we only do highlighting if we were in a query last - ie not if we were in a browse thingy 541 554 System.err.println("DocumentAction: invalid service, not doing highlighting"); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java
r8575 r9874 126 126 horizontal_at_top = true; 127 127 } 128 if (top_id.equals(classifier_node) && horizontal_at_top) { 128 // *** TODO need to fix this 129 //if (top_id.equals(classifier_node) && horizontal_at_top) { 129 130 // we have asked for a top node - if the first list is horizontal, we will select the first element of that list 130 // this is a hack. also it craps out if the classifier really isn't horizontalAtTop. 131 classifier_node = classifier_node+".1";131 // this is a hack. also it craps out if the classifier really isn't horizontalAtTop. - 132 //classifier_node = classifier_node+".1"; 132 133 133 }134 //} 134 135 135 136 // get the browse structure for the selected node -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java
r9264 r9874 60 60 String to = GSPath.appendLink(collection, service_name); 61 61 62 // part of the response is the service description 63 // for now get this again from the service. 64 // this will probably need to be cached somehow later on. 65 Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 66 Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid); 67 mr_info_message.appendChild(mr_info_request); 68 62 if (request_type.indexOf("d")!=-1) { 63 // we have been asked for the service description 64 Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 65 Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid); 66 mr_info_message.appendChild(mr_info_request); 67 68 // process the message 69 Element mr_info_response = (Element) this.mr.process(mr_info_message); 70 // the response 71 Element service_response = (Element)GSXML.getChildByTagName(mr_info_response, GSXML.RESPONSE_ELEM); 72 73 Element service_description = (Element)this.doc.importNode(GSXML.getChildByTagName(service_response, GSXML.SERVICE_ELEM), true); 74 page_response.appendChild(service_description); 75 } 76 77 if (request_type.indexOf("r") == -1) { 78 // just a display request, no actual processing to do 79 return page_response; 80 } 81 82 // check that we have some service params 83 HashMap service_params = (HashMap)params.get("s1"); 84 if (service_params == null) { // no query 85 return page_response; 86 } 87 88 // create the query request 89 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 90 Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid); 91 mr_query_message.appendChild(mr_query_request); 92 93 Element query_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 94 GSXML.addParametersToList(this.doc, query_param_list, service_params); 95 mr_query_request.appendChild(query_param_list); 96 69 97 // also get the format stuff now if there is some 70 98 Element format_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_FORMAT, to, lang, uid); 71 mr_info_message.appendChild(format_request); 72 73 // process the messages 74 Element mr_info_response = (Element) this.mr.process(mr_info_message); 75 76 // the two responses 77 NodeList responses = mr_info_response.getElementsByTagName(GSXML.RESPONSE_ELEM); 78 Element service_response = (Element)responses.item(0); 79 Element format_response = (Element)responses.item(1); 80 81 Element service_description = (Element)this.doc.importNode(GSXML.getChildByTagName(service_response, GSXML.SERVICE_ELEM), true); 82 page_response.appendChild(service_description); 83 84 if (request_type.equals("d")) {// just a display request 85 return page_response; 86 } 87 99 mr_query_message.appendChild(format_request); 100 101 // do the query 102 Element mr_query_response = (Element)this.mr.process(mr_query_message); 103 104 // check for errors 105 if (processErrorElements(mr_query_response, page_response)) { 106 return page_response; 107 } 108 109 NodeList responses = mr_query_response.getElementsByTagName(GSXML.RESPONSE_ELEM); 110 Element query_response = (Element) responses.item(0); 111 Element format_response = (Element) responses.item(1); 112 113 Element query_result_metadata_list = (Element) GSXML.getChildByTagName(query_response, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 114 if (query_result_metadata_list == null) { 115 System.err.println("QueryAction: Warning: No query result metadata.\n"); 116 } else { // add it into the page response 117 page_response.appendChild(this.doc.importNode(query_result_metadata_list, true)); 118 } 119 120 Element query_term_info_list = (Element) GSXML.getChildByTagName(query_response, GSXML.TERM_ELEM+GSXML.LIST_MODIFIER); 121 if (query_term_info_list == null) { 122 System.err.println("QueryAction: Warning: No query term information.\n"); 123 } else { // add it into the page response 124 page_response.appendChild(this.doc.importNode(query_term_info_list, true)); 125 } 126 127 // check that there are some documents - for now check the list, but later should use a numdocs metadata elem 128 Element document_list = (Element)GSXML.getChildByTagName(query_response, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 129 // documentList not present if no docs found 130 if (document_list == null) { 131 return page_response; 132 } 133 134 // now we check to see if there is metadata already - some search services return predefined metadata. if there is some, don't do a metadata request 135 NodeList doc_metadata = document_list.getElementsByTagName(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 136 if (doc_metadata.getLength()>0) { 137 System.err.println("have already found metadata!"); 138 // append the doc list to the result 139 page_response.appendChild(this.doc.importNode(document_list, true)); 140 return page_response; 141 } 142 143 // get the metadata elements needed from the format statement if any 88 144 HashSet metadata_names = new HashSet(); 89 145 metadata_names.add("Title"); … … 98 154 extractMetadataNames(format_elem, metadata_names); 99 155 } 100 101 // do the query102 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);103 Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);104 mr_query_message.appendChild(mr_query_request);105 106 // paramList107 HashMap service_params = (HashMap)params.get("s1");108 if (service_params == null) { // no query109 return page_response;110 }111 Element query_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);112 GSXML.addParametersToList(this.doc, query_param_list, service_params);113 ///ystem.out.println("service params are "+this.converter.getString(query_param_list));114 mr_query_request.appendChild(query_param_list);115 116 // do the query117 Element mr_query_response = (Element)this.mr.process(mr_query_message);118 119 //. check for errors120 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.ERROR_ELEM);121 Element error_elem = (Element) GSXML.getNodeByPath(mr_query_response, path);122 if (error_elem != null) {123 // should we continue?? perhaps have a kind of error - information vs fatal??124 System.err.println("found an error elem");125 page_response.appendChild(this.doc.importNode(error_elem, true));126 return page_response;127 }128 path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);129 Element query_result_metadata_list = (Element) GSXML.getNodeByPath(mr_query_response, path);130 if (query_result_metadata_list == null) {131 System.err.println("QueryAction: Warning: No query result metadata.\n");132 } else { // add it into the page response133 page_response.appendChild(this.doc.importNode(query_result_metadata_list, true));134 }135 136 path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);137 Element query_term_info_list = (Element) GSXML.getNodeByPath(mr_query_response, path);138 if (query_term_info_list == null) {139 System.err.println("QueryAction: Warning: No query term information.\n");140 } else { // add it into the page response141 page_response.appendChild(this.doc.importNode(query_term_info_list, true));142 }143 144 // check that there are some documents - for now check the list, but later should use a numdocs metadata elem145 path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);146 147 Element document_list = (Element)GSXML.getNodeByPath(mr_query_response,148 path);149 // documentList not present if no docs found150 if (document_list == null) {151 return page_response;152 }153 156 154 157 // paging of the results is done here - we filter the list to remove unwanted entries before retrieving metadata 155 Element filtered_doc_list = filterDocList(params, service_description, document_list); 156 157 // now we check to see if there is metadata already - some search services return predefined metadata. if there is some, don't do a metadata request 158 NodeList doc_metadata = document_list.getElementsByTagName(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 159 if (doc_metadata.getLength()>0) { 160 System.err.println("have already found metadata!"); 161 // append the doc list to the result 162 page_response.appendChild(this.doc.importNode(document_list, true)); 163 return page_response; 164 } 158 Element filtered_doc_list = filterDocList(params, service_params, document_list); 159 165 160 // do the metadata request on the filtered list 166 161 Element mr_metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM); … … 176 171 mr_metadata_request.appendChild(dm_param_list); 177 172 178 179 173 // add in the doc node list too 180 174 mr_metadata_request.appendChild(filtered_doc_list); 181 175 182 176 Element mr_metadata_response = (Element) this.mr.process(mr_metadata_message); 183 184 path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 185 Element query_result_document_list = (Element) GSXML.getNodeByPath(mr_metadata_response, path); 186 177 // check for errors 178 processErrorElements(mr_metadata_response, page_response); 179 180 Element metadata_response = (Element) GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM); 181 182 Element query_result_document_list = (Element) GSXML.getChildByTagName(metadata_response, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 183 187 184 if (query_result_document_list != null) { 188 185 page_response.appendChild(this.doc.importNode(query_result_document_list, true)); 189 186 } 190 191 System.out.println("Query page:\n" + this.converter.getPrettyString(page_response));187 188 ///ystem.out.println("Query page:\n" + this.converter.getPrettyString(page_response)); 192 189 return page_response; 193 190 } 194 191 195 192 /** this filters out some of the doc results for result paging */ 196 protected Element filterDocList(HashMap params, Element service_description, Element orig_doc_list) { 197 198 // check in the service descripiton to see if hitsPerpage is a param 199 Element service_p_list = (Element)GSXML.getChildByTagName(service_description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 200 Element hits_param = GSXML.getNamedElement(service_p_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, "hitsPerPage"); 201 202 boolean service_paging = false; 203 if (hits_param != null) { 204 service_paging = true; 205 } 206 if (service_paging) { 207 // the service is doing the paging, so we want to display all of teh returned docs 193 protected Element filterDocList(HashMap params, HashMap service_params, Element orig_doc_list) { 194 195 // check the hits_per_page param - is it a service param?? 196 String hits_pp = (String) service_params.get("hitsPerPage"); 197 if (hits_pp != null) { 198 // the service is doing the paging, so we want to display all of the returned docs 208 199 return (Element)this.doc.importNode(orig_doc_list, true); 209 200 } 210 201 211 Stringhits_pp = (String)params.get("hitsPerPage");202 hits_pp = (String)params.get("hitsPerPage"); 212 203 int hits = 20; 213 204 if (hits_pp != null && !hits_pp.equals("")) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java
r5403 r9874 101 101 } 102 102 // get the xml for both files 103 Element coll_config_elem = this.converter.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement(); 103 Document coll_config_doc = this.converter.getDOM(coll_config_file, CONFIG_ENCODING); 104 Element coll_config_elem = null; 105 if (coll_config_doc != null) { 106 coll_config_elem = coll_config_doc.getDocumentElement(); 107 } 104 108 return coll_config_elem; 105 109 … … 116 120 return null; 117 121 } 118 Element build_config_elem = this.converter.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement(); 119 122 Document build_config_doc = this.converter.getDOM(build_config_file, CONFIG_ENCODING); 123 Element build_config_elem = null; 124 if (build_config_doc != null) { 125 build_config_elem = build_config_doc.getDocumentElement(); 126 } 120 127 return build_config_elem; 121 128 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
r9433 r9874 34 34 import java.io.File; 35 35 import java.util.HashMap; 36 import java.util.Iterator; 36 37 37 38 /* ServiceCluster - a groups of services that are related in some way … … 91 92 } 92 93 94 public void cleanUp() { 95 Iterator i = this.service_map.values().iterator(); 96 while (i.hasNext()) { 97 ServiceRack s = (ServiceRack)i.next(); 98 s.cleanUp(); 99 } 100 } 93 101 public void setClusterName(String name) { 94 102 this.cluster_name = name; … … 139 147 140 148 Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING); 149 if (doc == null) { 150 System.err.println("ServiceCluster: couldn't parse config file "+config_file.getPath()); 151 return false; 152 } 141 153 142 154 // get the appropriate service cluster element … … 147 159 return this.configure(sc); 148 160 } 149 161 150 162 151 163 public boolean configure(Element service_cluster_info) { … … 159 171 } 160 172 } 161 173 162 174 // get the display info 163 175 Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER); … … 528 540 } 529 541 530 Element site_config_elem = this.converter.getDOM(configFile).getDocumentElement(); 542 Document site_config_doc = this.converter.getDOM(configFile); 543 if (site_config_doc == null) { 544 System.err.println("ServiceCluster: could not read in site config file: "+configFile.getPath()); 545 return false; 546 } 547 548 Element site_config_elem = site_config_doc.getDocumentElement(); 531 549 Element cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name); 532 550 if (cluster_config_elem == null) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/Communicator.java
r4035 r9874 48 48 converter_ = new XMLConverter(); 49 49 } 50 public void cleanUp() {} 50 51 51 52 public void setLocalSiteName(String name) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java
r4035 r9874 26 26 import java.net.MalformedURLException; 27 27 import java.util.Vector; 28 import org.apache.soap.SOAPException; 29 import org.apache.soap.Fault; 30 import org.apache.soap.Constants; 31 import org.apache.soap.rpc.Call; 32 import org.apache.soap.rpc.Parameter; 33 import org.apache.soap.rpc.Response; 28 // import org.apache.soap.SOAPException; 29 // import org.apache.soap.Fault; 30 // import org.apache.soap.Constants; 31 // import org.apache.soap.rpc.Call; 32 // import org.apache.soap.rpc.Parameter; 33 // import org.apache.soap.rpc.Response; 34 import org.apache.axis.client.Call; 35 import org.apache.axis.client.Service; 36 import org.apache.axis.message.SOAPBodyElement; 37 import javax.xml.namespace.QName; 34 38 35 39 import org.w3c.dom.Node; … … 57 61 public SOAPCommunicator() { 58 62 59 call_ = new Call(); 63 60 64 // Set Encoding Style to standard SOAP encoding 61 65 //call_.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 62 66 // set Encoding Style to use literal XML 63 call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);67 //call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML); 64 68 } 65 69 66 70 public boolean configure(Element site_elem) { 67 71 72 68 73 String type = site_elem.getAttribute(GSXML.TYPE_ATT); 69 74 if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { … … 81 86 return false; 82 87 } 83 call_.setTargetObjectURI(remote_site_name_); 84 call_.setMethodName("process"); 85 88 try { 89 Service service = new Service(); 90 call_ = (Call) service.createCall(); 91 92 //call_.setTargetObjectURI(remote_site_name_); 93 //call_.setMethodName("process"); 94 call_.setTargetEndpointAddress( new java.net.URL(remote_site_address_) ); 95 // call_.setOperationStyle(org.apache.axis.enum.Style.MESSAGE_STR); 96 //call_.setOperationUse(org.apache.axis.enum.Use.LITERAL_STR); 97 //call_.setOperationName(new QName("http://soapinterop.org/", "process")); 98 } catch (Exception e) { 99 System.err.println("SOAPCommunicator.configure() Error: Exception occurred "+e); 100 return false; 101 } 86 102 return true; 87 103 } 88 104 89 90 105 public Element process(Element message) { 91 106 92 107 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 93 108 if (requests.getLength()==0) { … … 95 110 return null; 96 111 } 97 112 98 113 // if the communicator is part of a site, it needs to edit the to and from fields, otherwise it just passes the message on, as is 99 114 // for now, use local_site_name_ as the flag. … … 110 125 } 111 126 } 127 // else do nothing to the requests, just pass it on 128 129 // the soap impl needs a namespace for the top level element 130 Element message_to_send = message; 131 if (message.getNamespaceURI() == null) { 132 message_to_send = GSXML.duplicateWithNewNameNS(message.getOwnerDocument(), message, "gs3:"+message.getTagName(), "urn:foo", true); 133 //System.err.println("**"+new XMLConverter().getPrettyString(new_message)); 134 } 135 136 // do the soap query 137 Element result = null; 138 try { 139 SOAPBodyElement[] input = new SOAPBodyElement[1]; 140 input[0] = new SOAPBodyElement(message_to_send); 141 Vector output = (Vector) call_.invoke( input ); 142 SOAPBodyElement elem = (SOAPBodyElement) output.get(0); 143 result = elem.getAsDOM(); 144 } catch (Exception e) { 145 e.printStackTrace(); 146 return null; 147 } 148 149 if (local_site_name_ != null) {// have to modify the from field 150 151 NodeList responses = result.getElementsByTagName(GSXML.RESPONSE_ELEM); 152 for (int i=0;i<responses.getLength(); i++) { 153 Element e = (Element)responses.item(i); 154 String from = e.getAttribute(GSXML.FROM_ATT); 155 from = GSPath.prependLink(from, remote_site_name_); 156 e.setAttribute(GSXML.FROM_ATT, from); 157 } 158 } // else return as is 159 160 return result; 161 } 162 163 public static void main (String [] args) { 164 SOAPCommunicator comm = new SOAPCommunicator(); 165 XMLConverter converter = new XMLConverter(); 166 String message = "<site name=\"localsite\" address=\"http://kanuka.cs.waikato.ac.nz:7070/axis/services/localsite\" type=\"soap\"/>"; 167 Element site_elem = converter.getDOM(message).getDocumentElement(); 168 comm.configure(site_elem); 169 message = "<message><request type=\"describe\" to=\"\" lang=\"en\"/></message>"; 170 //message = "<message><request type=\"describe\" to=\"\" lang=\"en\"/></message>"; 171 Element request_elem = converter.getDOM(message).getDocumentElement(); 172 Element response = comm.process(request_elem); 173 174 System.err.println("response was "+converter.getPrettyString(response)); 175 } 176 /* 177 public Element process(Element message) { 178 179 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 180 if (requests.getLength()==0) { 181 // no requests 182 return null; 183 } 184 185 // if the communicator is part of a site, it needs to edit the to and from fields, otherwise it just passes the message on, as is 186 // for now, use local_site_name_ as the flag. 187 if (local_site_name_!=null) { // no local site 188 189 for (int i=0;i<requests.getLength(); i++) { 190 Element e = (Element)requests.item(i); 191 String to = e.getAttribute(GSXML.TO_ATT); 192 to = GSPath.removeFirstLink(to); // remove the server name, should check that it is present 193 e.setAttribute(GSXML.TO_ATT, to); 194 String from = e.getAttribute(GSXML.FROM_ATT); 195 from = GSPath.appendLink(from, local_site_name_); 196 e.setAttribute(GSXML.FROM_ATT, from); 197 } 198 } 112 199 // else do nothing to the message, just pass it on 113 200 … … 116 203 117 204 // Set Method Parameters - use literal xml 118 Parameter param = new Parameter("xml_in",119 org.w3c.dom.Element.class,120 message,121 Constants.NS_URI_LITERAL_XML);205 // Parameter param = new Parameter("xml_in", 206 // org.w3c.dom.Element.class, 207 // message, 208 // Constants.NS_URI_LITERAL_XML); 122 209 123 Vector param_list = new Vector ();124 param_list.addElement (param);125 call_.setParams (param_list);126 127 // Set the URL for the Web Service128 URL url = new URL(remote_site_address_);210 // Vector param_list = new Vector (); 211 // param_list.addElement (param); 212 // call_.setParams (param_list); 213 214 // // Set the URL for the Web Service 215 // URL url = new URL(remote_site_address_); 129 216 130 217 // Invoke the Service … … 167 254 } 168 255 } 169 256 */ 170 257 } 171 258 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/DefaultReceptionist.java
r7825 r9874 24 24 25 25 Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM); 26 // if it is a system request, then we don't bother with this. 27 String action = page_request.getAttribute(GSXML.ACTION_ATT); 28 if (action.equals("s")) { 29 System.err.println("HACK: don't ask for coll info if system action"); 30 return; 31 } 26 32 ///ystem.out.println("add extra info, page request="+this.converter.getString(page_request)); 27 33 // is a collection defined? … … 60 66 Element coll_about_response_message = this.mr.process(coll_about_message); 61 67 Element coll_about_response = (Element)GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM); 68 if (coll_about_response == null) { 69 return; 70 } 62 71 coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM); 63 72 if (coll_description==null) { // may be a cluster -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r9276 r9874 98 98 this.converter = new XMLConverter(); 99 99 this.doc = this.converter.newDOM(); 100 101 102 } 103 100 } 101 102 public void cleanUp() { 103 if (this.module_map != null) { 104 Iterator i = this.module_map.values().iterator(); 105 while (i.hasNext()) { 106 ((ModuleInterface)i.next()).cleanUp(); 107 } 108 } 109 } 104 110 /** site_home must be set before configure called */ 105 111 public void setSiteHome(String home) { … … 133 139 this.module_map = new HashMap(); 134 140 135 Element config = this.converter.getDOM(configFile).getDocumentElement(); 136 137 Element local_site_name = (Element)GSXML.getChildByTagName(config, GSXML.SITE_NAME_ELEM); 141 Document config_doc = this.converter.getDOM(configFile); 142 if (config_doc == null) { 143 System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath()); 144 return false; 145 } 146 Element config_elem = config_doc.getDocumentElement(); 147 148 Element local_site_name = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_NAME_ELEM); 138 149 if (local_site_name == null) { 139 150 System.err.println("MessageRouter configure error:no site name in config file"); … … 143 154 } 144 155 145 Element http_address = (Element)GSXML.getChildByTagName(config , GSXML.SITE_HTTP_ADDRESS_ELEM);156 Element http_address = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_HTTP_ADDRESS_ELEM); 146 157 if (http_address == null) { 147 158 System.err.println("MessageRouter configure error: no http address in config file"); … … 151 162 } 152 163 153 Element proxy = (Element)GSXML.getChildByTagName(config , "proxy");164 Element proxy = (Element)GSXML.getChildByTagName(config_elem, "proxy"); 154 165 if (proxy != null) { 155 166 String host = proxy.getAttribute("host"); … … 180 191 181 192 // load up the services 182 Element service_rack_list = (Element)GSXML.getChildByTagName(config , GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);193 Element service_rack_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER); 183 194 configureServices(service_rack_list); 184 195 185 196 // load up the service clusters 186 Element cluster_list = (Element)GSXML.getChildByTagName(config , GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);197 Element cluster_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER); 187 198 configureClusters(cluster_list); 188 199 … … 191 202 192 203 // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last 193 Element site_list = (Element)GSXML.getChildByTagName(config , GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);204 Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 194 205 configureSites(site_list); 195 206 … … 603 614 continue; 604 615 } 605 site_config_elem = this.converter.getDOM(configFile).getDocumentElement(); 616 Document site_config_doc = this.converter.getDOM(configFile); 617 if (site_config_doc == null) { 618 System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath()); 619 continue; 620 } 621 site_config_elem = site_config_doc.getDocumentElement(); 606 622 } 607 623 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) { … … 684 700 File init_file = new File(GSFile.collectionInitFile(this.site_home, col_name)); 685 701 if (init_file.exists()) { 686 Element init_elem = this.converter.getDOM(init_file).getDocumentElement(); 687 String coll_class_name = init_elem.getAttribute("class"); 688 if (coll_class_name.equals("")) { 689 c = new Collection(); 690 } else { 691 try { 692 c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance(); 693 } catch (Exception e) { 694 System.out.println("MessageRouter: couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection"); 695 c = new Collection(); 696 } 697 } 698 } else { 699 // use the defualt collection 702 Document init_doc = this.converter.getDOM(init_file); 703 if (init_doc != null) { 704 Element init_elem = init_doc.getDocumentElement(); 705 if (init_elem != null) { 706 String coll_class_name = init_elem.getAttribute("class"); 707 if (!coll_class_name.equals("")) { 708 try { 709 c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance(); 710 } catch (Exception e) { 711 System.out.println("MessageRouter: couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection"); 712 } 713 } 714 } 715 } 716 } 717 if (c==null) { // we haven't found anpther classname to use 700 718 c = new Collection(); 701 719 } 720 702 721 c.setCollectionName(col_name); 703 722 c.setSiteHome(this.site_home); … … 720 739 721 740 } 722 741 723 742 protected boolean activateSite(String site_name) { 724 743 System.out.println("MessageRouter:Activating site: "+site_name+"."); … … 732 751 return false; 733 752 } 734 Element config = this.converter.getDOM(configFile).getDocumentElement(); 735 736 Element site_list = (Element)GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 753 Document config_doc = this.converter.getDOM(configFile); 754 if (config_doc == null) { 755 System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath()); 756 return false; 757 } 758 Element config_elem = config_doc.getDocumentElement(); 759 760 Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 737 761 if (site_list ==null ) { 738 762 System.err.println("MessageRouter:activateSite, no sites found"); … … 789 813 790 814 System.out.println("MessageRouter: deactivating "+name); 791 this.module_map.remove(name);792 815 ModuleInterface m = (ModuleInterface)this.module_map.remove(name); 816 m.cleanUp(); // clean up any open files/connections etc - can cause trouble on windows 793 817 // also remove the xml bit from description list 794 818 if (type.equals(GSXML.COLLECTION_ELEM)) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/ModuleInterface.java
r3502 r9874 52 52 */ 53 53 abstract public Element process(Element xml_in); 54 55 /** 56 * Do any clean up necessary for deactivating the module, eg 57 * close any open file handles (gdbm in particular) or windows 58 * holds locks on them. 59 */ 60 abstract public void cleanUp(); 54 61 } 55 62 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java
r8921 r9874 50 50 } 51 51 52 public void cleanUp() {} 52 53 public void setParams(GSParams params) { 53 54 this.params = params; … … 81 82 } 82 83 83 Element config_doc = this.converter.getDOM(interface_config_file).getDocumentElement(); 84 String base_interface = config_doc.getAttribute("baseInterface"); 84 Document config_doc = this.converter.getDOM(interface_config_file); 85 if (config_doc == null) { 86 System.err.println("Receptionist: could not parse interface config file: "+interface_config_file.getPath()); 87 return false; 88 } 89 Element config_elem = config_doc.getDocumentElement(); 90 String base_interface = config_elem.getAttribute("baseInterface"); 85 91 setUpBaseInterface(base_interface); 86 setUpInterfaceOptions(config_ doc);92 setUpInterfaceOptions(config_elem); 87 93 88 94 // load up the actions 89 Element action_list = (Element)GSXML.getChildByTagName(config_ doc, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);95 Element action_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER); 90 96 NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM); 91 97 … … 109 115 } 110 116 111 this.language_list = (Element)GSXML.getChildByTagName(config_ doc, "languageList");117 this.language_list = (Element)GSXML.getChildByTagName(config_elem, "languageList"); 112 118 if (language_list == null) { 113 119 System.err.println("Receptionist: didn't find a language list in the config file!!"); … … 229 235 base_interfaces.add(base_interface); 230 236 // now see if this has a base interface 231 Element config_doc = this.converter.getDOM(base_interface_config_file).getDocumentElement(); 232 base_interface = config_doc.getAttribute("baseInterface"); 237 Document config_doc = this.converter.getDOM(base_interface_config_file); 238 if (config_doc == null) { 239 System.err.println("Receptionist: could not parse base interface config file: "+base_interface_config_file.getPath()); 240 return false; 241 } 242 Element config_elem = config_doc.getDocumentElement(); 243 base_interface = config_elem.getAttribute("baseInterface"); 233 244 } 234 245 return true; 235 246 } 236 247 237 protected boolean setUpInterfaceOptions(Element config_ doc) {238 Element option_list = (Element)GSXML.getChildByTagName(config_ doc, "optionList");248 protected boolean setUpInterfaceOptions(Element config_elem) { 249 Element option_list = (Element)GSXML.getChildByTagName(config_elem, "optionList"); 239 250 if (option_list != null) { 240 251 System.err.println("found an option list"); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
r9405 r9874 52 52 return false; 53 53 } 54 55 Element config_doc = this.converter.getDOM(interface_config_file, "utf-8").getDocumentElement(); 56 String base_interface = config_doc.getAttribute("baseInterface"); 54 Document config_doc = this.converter.getDOM(interface_config_file, "utf-8"); 55 if (config_doc == null) { 56 System.err.println("TransformingReceptionist: could not parse interface config file: "+interface_config_file.getPath()); 57 return false; 58 } 59 Element config_elem = config_doc.getDocumentElement(); 60 String base_interface = config_elem.getAttribute("baseInterface"); 57 61 setUpBaseInterface(base_interface); 58 setUpInterfaceOptions(config_ doc);59 60 Element action_list = (Element)GSXML.getChildByTagName(config_ doc, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);62 setUpInterfaceOptions(config_elem); 63 64 Element action_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER); 61 65 NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM); 62 66 … … 97 101 98 102 } 99 Element lang_list = (Element)GSXML.getChildByTagName(config_ doc, "languageList");103 Element lang_list = (Element)GSXML.getChildByTagName(config_elem, "languageList"); 100 104 if (lang_list == null) { 101 105 System.err.println("TransformingReceptionist: didn't find a language list in the config file!!"); … … 157 161 } 158 162 Document style_doc = this.converter.getDOM(new File(xslt_file), "UTF-8"); 163 if (style_doc == null) { 164 System.err.println("TransformingReceptionist: cant parse the xslt file needed, so returning the original page!"); 165 return page; 166 167 } 159 168 160 169 // look for the format element in the page response … … 166 175 // need to transform the format info 167 176 String stylesheet_file = GSFile.stylesheetFile((String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, "config_format.xsl"); 168 Document stylesheet = this.converter.getDOM(new File(stylesheet_file)); 169 Document format_doc = this.converter.newDOM(); 170 format_doc.appendChild(format_doc.importNode(format_elem, true)); 171 Element new_format = (Element)this.transformer.transform(stylesheet, format_doc); 177 Document stylesheet_doc = this.converter.getDOM(new File(stylesheet_file)); 178 if (stylesheet_doc != null) { 179 Document format_doc = this.converter.newDOM(); 180 format_doc.appendChild(format_doc.importNode(format_elem, true)); 181 Element new_format = (Element)this.transformer.transform(stylesheet_doc, format_doc); 172 182 ///ystem.err.println("new format elem="+this.converter.getPrettyString(new_format)); 173 183 174 184 // add it in to the main stylesheet 175 GSXSLT.mergeStylesheets(style_doc, new_format); 185 GSXSLT.mergeStylesheets(style_doc, new_format); 186 } else { 187 System.err.println("TransformingReceptionist: couldn't parse the config_format stylesheet, adding the format info as is"); 188 GSXSLT.mergeStylesheets(style_doc, format_elem); 189 } 176 190 ///ystem.out.println("the converted stylesheet is:"); 177 191 ///ystem.out.println(this.converter.getPrettyString(style_doc.getDocumentElement())); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java
r8969 r9874 216 216 GS3SQLSelect select = new GS3SQLSelect("build"); 217 217 select.addField("*"); 218 this.database.execute(select.toString()); 219 ResultSet results = this.database.getResultSet(); 220 if (results != null && 221 results.first()) { 218 Statement statement = this.database.createStatement(); 219 ResultSet results = statement.executeQuery(select.toString()); 220 if (results.first()) { 222 221 System.out.println("Reading all keys"); 223 222 do { … … 238 237 } while (results.next()); 239 238 } 239 statement.close(); 240 240 } 241 241 catch (SQLException ex) … … 479 479 480 480 // Update build date information 481 GS3SQLDelete remove = new GS3SQLDelete("build"); 482 // GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("buildKey", "=", "NextSeqNo")); 483 // rem 484 this.database.execute(remove.toString()); 485 486 GS3SQLInsert insert = new GS3SQLInsert("build"); 487 insert.addValue("buildKey", "NextSeqNo"); 488 insert.addValue("buildValue", Integer.toString(this.buildDocNo)); 489 this.database.execute(insert.toString()); 490 491 insert = new GS3SQLInsert("build"); 492 insert.addValue("buildKey", "lastBuildDate"); 493 insert.addValue("buildValue", getDateString(this.lastBuildDate)); 494 this.database.execute(insert.toString()); 495 481 try { 482 GS3SQLDelete remove = new GS3SQLDelete("build"); 483 // GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("buildKey", "=", "NextSeqNo")); 484 // rem 485 Statement statement = this.database.createStatement(); 486 statement.execute(remove.toString()); 487 488 GS3SQLInsert insert = new GS3SQLInsert("build"); 489 insert.addValue("buildKey", "NextSeqNo"); 490 insert.addValue("buildValue", Integer.toString(this.buildDocNo)); 491 statement.execute(insert.toString()); 492 493 insert = new GS3SQLInsert("build"); 494 insert.addValue("buildKey", "lastBuildDate"); 495 insert.addValue("buildValue", getDateString(this.lastBuildDate)); 496 statement.execute(insert.toString()); 497 statement.close(); 498 } catch (SQLException e) { 499 System.err.println("CollectionManager.endBuild(): Can't update build information: "+e); 500 } 501 496 502 // Do tail of build output 497 503 Date startDate = this.lastBuildDate.getTime(); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/Create.java
r8497 r9874 48 48 49 49 System.err.println("New collection created in "+coll_home); 50 System.err.println("Put source documents into import, set the collection's configuration in etc/collectionConfig.xml, then run gs3-build.sh to build the collection");50 System.err.println("Put source documents into import, set the collection's configuration in etc/collectionConfig.xml, then run gs3-build.sh (linux) or gs3-build (windows) to build the collection"); 51 51 } 52 52 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AZListClassifier.java
r8742 r9874 9 9 import java.sql.ResultSet; 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 12 13 import org.xml.sax.XMLReader; … … 189 190 select.setWhere(where); 190 191 191 connection.execute(select.toString());192 192 193 193 try { 194 ResultSet results = connection.getResultSet(); 195 if (results != null && results.first()) { 194 Statement statement = connection.createStatement(); 195 ResultSet results = statement.executeQuery(select.toString()); 196 if (results.first()) { 196 197 GS3SQLUpdate update = new GS3SQLUpdate("classifiers"); 197 198 update.setWhere(where); … … 206 207 207 208 action = insert; 209 classifyRef = -1; 208 210 } 209 211 action.addValue("ClassifyID", label); … … 213 215 action.addValue("NumLeafDocs", Integer.toString(noOfLeafDocs), GS3SQLField.INTEGER_TYPE); 214 216 215 connection.execute(action.toString()); 216 classifyRef = -1; 217 } 218 catch (SQLException sqlEx) { 219 System.err.println(sqlEx); 220 return -1; 221 } 222 223 // get the ClassifyRef if we don't already have it (have done a 224 // insert action above)... 225 if (classifyRef == -1) { 226 connection.execute(select.toString()); 227 228 try { 229 ResultSet results = connection.getResultSet(); 230 if (results == null || !results.first()) { 217 // do the update/insert 218 statement.execute(action.toString()); 219 220 221 // get the ClassifyRef if we don't already have it (have done a 222 // insert action above)... 223 if (classifyRef == -1) { 224 results = statement.executeQuery(select.toString()); 225 if (!results.first()) { 231 226 return -1; 232 227 } … … 234 229 classifyRef = results.getInt("ClassifyRef"); 235 230 } 236 catch (SQLException sqlEx) { 237 System.err.println(sqlEx); 231 232 statement.close(); 233 } catch (SQLException sqlEx) { 234 System.err.println("AZListClassifier.writeSQLClassifyNode(): "+sqlEx); 238 235 return -1; 239 240 }236 } 237 241 238 242 239 return classifyRef; … … 274 271 } 275 272 273 try { 274 Statement statement = connection.createStatement(); 275 276 276 List children; 277 277 … … 292 292 Iterator iterator = childDocs.iterator(); 293 293 int childOrder = 1; 294 //St 294 295 while (iterator.hasNext()) { 295 296 AZDocumentItem documentItem = (AZDocumentItem) iterator.next(); … … 301 302 insert.addValue("DocOrder", Integer.toString(childOrder), GS3SQLField.INTEGER_TYPE); 302 303 303 connection.execute(insert.toString());304 statement.execute(insert.toString()); 304 305 305 306 childOrder ++; … … 310 311 } 311 312 313 312 314 /* 313 315 else { … … 318 320 delete.setWhere(where); 319 321 320 connection.execute(delete.toString());322 statement.execute(delete.toString()); 321 323 } 322 324 … … 331 333 } 332 334 */ 335 statement.close(); 336 } catch (SQLException e) { 337 System.err.println("AZListClassifier.writeSQL(): "+e); 338 return false; 339 } 333 340 334 341 return true; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java
r8742 r9874 7 7 import java.sql.ResultSet; 8 8 import java.sql.SQLException; 9 import java.sql.Statement; 9 10 10 11 import org.greenstone.gsdl3.gs3build.doctypes.DocumentID; … … 273 274 GS3SQLInsert insert; 274 275 276 Statement statement; 277 // can we connect to the database? 278 try { 279 statement = connection.createStatement(); 280 } catch (SQLException e) { 281 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 282 return false; 283 } 284 275 285 // Get own full id 276 286 String fullId = this.id.length() > 0 ? this.prefix+"."+this.id : this.prefix; … … 283 293 select.setWhere(where); 284 294 285 connection.execute(select.toString());286 295 287 296 // update or insert the classifier as required 288 297 try { 289 ResultSet results = connection.getResultSet();290 if (results != null && results.first()) {298 ResultSet results = statement.executeQuery(select.toString()); 299 if (results.first()) { 291 300 GS3SQLUpdate update = new GS3SQLUpdate("classifiers"); 292 301 update.setWhere(where); … … 313 322 314 323 action = insert; 324 classifyRef = -1; 315 325 } 316 326 action.addValue("ClassifyID", fullId); … … 331 341 action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE); 332 342 333 connection.execute(action.toString()); 334 classifyRef = -1; 343 statement.execute(action.toString()); 335 344 } 336 345 catch (SQLException sqlEx) { 337 346 if (action == null) { 338 System.err.println( sqlEx);347 System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx); 339 348 } 340 349 else { 341 System.err.println( sqlEx + " " + action.toString());350 System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx + " " + action.toString()); 342 351 } 343 352 return false; … … 347 356 // insert action above)... 348 357 if (classifyRef == -1) { 349 connection.execute(select.toString());350 351 358 try { 352 ResultSet results = connection.getResultSet(); 353 if (results == null || !results.first()) { 354 return false; 359 ResultSet results = statement.executeQuery(select.toString()); 360 if (!results.first()) { 361 statement.close(); 362 return false; 355 363 } 356 364 357 365 classifyRef = results.getInt("ClassifyRef"); 366 358 367 } 359 368 catch (SQLException sqlEx) { 360 System.err.println( sqlEx);369 System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx); 361 370 return false; 362 371 } … … 368 377 GS3SQLDelete delete = new GS3SQLDelete("classdocuments"); 369 378 delete.setWhere(where); 370 371 connection.execute(delete.toString()); 372 } 373 379 try { 380 statement.execute(delete.toString()); 381 } catch (SQLException e) { 382 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 383 return false; 384 } 385 } 386 374 387 // post the child nodes... 375 388 Iterator iterator = this.childNodes.iterator(); … … 379 392 if (!childNode.writeSQL(connection)) { 380 393 System.out.println("Failed to write " ); 381 return false;394 return false; 382 395 } 383 396 } … … 394 407 insert.addValue("DocID", docId.toString()); 395 408 insert.addValue("DocOrder", Integer.toString(order), GS3SQLField.INTEGER_TYPE); 396 397 connection.execute(insert.toString()); 398 409 try { 410 statement.execute(insert.toString()); 411 } catch (SQLException e) { 412 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 413 return false; 414 } 399 415 order ++; 400 416 } 417 // close the statment 418 try { 419 statement.close(); 420 } catch (SQLException e) { 421 System.err.println("AbstractHierarchyNode.writeSQL(): "+e); 422 } 423 401 424 return true; 402 425 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java
r8773 r9874 14 14 { 15 15 16 public GS3SQLConnection(java.sql.Connection connection )16 public GS3SQLConnection(java.sql.Connection connection, String database) 17 17 { 18 super(connection );18 super(connection, database); 19 19 } 20 20 … … 25 25 } 26 26 27 27 public GS3SQLConnection cloneConnection() { 28 GS3SQLConnection conn = GS3SQLConnectionFactory.getGS3SQLConnection(this.database); 29 return conn; 30 } 28 31 /** 29 32 * Initialise a collection for use. … … 62 65 63 66 try { 64 statement = this.connection.createStatement();67 Statement statement = this.connection.createStatement(); 65 68 66 69 // create build history table … … 224 227 statement.execute(classData.toString()); 225 228 229 statement.close(); 226 230 // 227 231 // END OF GSDL TABLES -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java
r8745 r9874 32 32 return null; 33 33 } 34 return new SQLConnection(c );34 return new SQLConnection(c, database); 35 35 } 36 36 … … 42 42 return null; 43 43 } 44 return new GS3SQLConnection(c );44 return new GS3SQLConnection(c, database); 45 45 } 46 46 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java
r8745 r9874 10 10 { 11 11 protected Connection connection; 12 protected Statement statement; 13 14 15 public SQLConnection(java.sql.Connection connection) 12 protected String database; 13 14 public SQLConnection(java.sql.Connection connection, String database) 16 15 { 17 16 this.connection = connection; 17 this.database = database; 18 18 } 19 19 … … 21 21 if (this.connection!=null) { 22 22 try { 23 this.connection.close(); 23 this.connection.close(); 24 24 } catch (Exception e) {} 25 26 this.connection = null; 27 } 25 } 26 this.connection = null; 28 27 } 29 28 30 public boolean execute(String sql) 31 { 32 try { 33 this.statement = this.connection.createStatement(); 34 this.statement.execute(sql); 35 } 36 catch (SQLException ex) { 37 System.out.println(ex); 38 return false; 39 } 40 return true; 29 public void close() { 30 finalize(); 41 31 } 42 32 43 public Statement createStatement() 33 public Statement createStatement() throws SQLException 44 34 { 45 try { 46 return this.connection.createStatement(); 47 } 48 catch (SQLException ex) { 49 return null; 50 } 51 } 52 53 public Statement getStatement() 54 { 55 return this.statement; 56 } 57 58 public ResultSet getResultSet() 59 { 60 try { 61 return this.statement.getResultSet(); 62 } 63 catch (SQLException ex) { 64 return null; 65 } 35 return this.connection.createStatement(); 66 36 } 67 37 68 38 public boolean connectToDatabase(String database) { 39 if (this.connection != null) { 40 try { 41 this.connection.close(); 42 } catch (Exception e) {} 43 } 69 44 this.connection = GS3SQLConnectionFactory.getConnection(database); 70 45 if (this.connection == null) { 71 46 return false; 72 47 } 48 this.database = database; 73 49 return true; 74 50 } … … 76 52 public boolean dropDatabase(String database) { 77 53 try { 78 this.statement = this.connection.createStatement(); 79 this.statement.execute("DROP DATABASE "+database+";"); 54 Statement statement = this.connection.createStatement(); 55 statement.execute("DROP DATABASE "+database+";"); 56 statement.close(); 80 57 } 81 58 catch (SQLException ex){ … … 90 67 try { 91 68 String command = "CREATE DATABASE " + database; 92 this.statement = this.connection.createStatement(); 93 this.statement.execute(command); 69 Statement statement = this.connection.createStatement(); 70 statement.execute(command); 71 statement.close(); 94 72 } catch (Exception e) { 95 73 System.err.println(e); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java
r8742 r9874 9 9 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 import java.sql.ResultSet; 12 13 import java.sql.Timestamp; … … 190 191 // Query for documents using the same file... 191 192 String query = "SELECT DocID FROM files INNER JOIN filegroups ON files.FileGroupRef=filegroups.FileGroupRef WHERE (filegroups.FileGroupId=\"default\" AND files.FileLocation=\"" + this.fileSet.getFile(0).getLocation().toString() + "\")"; 192 connection.execute(query);193 194 List docs = new ArrayList();195 ResultSet results = connection.getResultSet();196 197 193 try { 198 if (results != null && 199 results.first()) 200 { do { 201 String value = results.getString("DocID"); 202 203 docs.add(value); 204 } while (results.next()); 205 206 Iterator docIterator = docs.iterator(); 207 while (docIterator.hasNext()) { 208 String docId = docIterator.next().toString(); 209 String innerQuery = "SELECT * FROM document WHERE DocID=\"" + docId + "\""; 210 connection.execute(innerQuery); 211 ResultSet innerSet = connection.getResultSet(); 212 if (innerSet != null && innerSet.first()) { 213 String docType = innerSet.getString("DocType"); 214 if (docType.equals(this.getDocumentType())) { 215 return docId; 194 Statement statement = connection.createStatement(); 195 ResultSet results = statement.executeQuery(query); 196 197 List docs = new ArrayList(); 198 199 if (results.first()) { 200 do { 201 String value = results.getString("DocID"); 202 docs.add(value); 203 } while (results.next()); 204 205 Iterator docIterator = docs.iterator(); 206 while (docIterator.hasNext()) { 207 String docId = docIterator.next().toString(); 208 String innerQuery = "SELECT * FROM document WHERE DocID=\"" + docId + "\""; 209 results = statement.executeQuery(innerQuery); 210 if (results.first()) { 211 String docType = results.getString("DocType"); 212 if (docType.equals(this.getDocumentType())) { 213 return docId; 214 } 215 } 216 216 } 217 }218 217 } 219 } 218 statement.close(); 220 219 } 221 220 catch (java.sql.SQLException sqlEx) { 222 System.err.println( sqlEx);221 System.err.println("AbstractDocument.getDuplicateID(): "+sqlEx); 223 222 } 224 223 … … 447 446 * Obtain a document from the SQL database 448 447 */ 449 public static AbstractDocument readSQL(GS3SQLConnection connection, ResultSet sqlResult)448 public static AbstractDocument readSQL(GS3SQLConnection connection, ResultSet sqlResult) 450 449 { try { 451 450 DocumentID id = new DocumentID(sqlResult.getString("DocID")); … … 454 453 // Use a factory method to create the correct subtype... 455 454 AbstractDocument document = DocumentFactory.createDocument(type, id); 456 457 455 // Append the document date information 458 456 document.indexDate = sqlResult.getTimestamp("IndexedDate"); … … 473 471 } 474 472 catch (SQLException sqlEx) { 475 System. out.println("Failure to load document: " + sqlEx);473 System.err.println("AbstractDocument.readSQL(): Failure to load document: " + sqlEx); 476 474 } 477 475 return null; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentFactory.java
r8742 r9874 2 2 3 3 import java.sql.SQLException; 4 import java.sql.Statement; 4 5 import java.sql.ResultSet; 5 6 import java.net.URL; … … 61 62 { 62 63 String query = "SELECT * FROM document WHERE DocID=\""+id.toString()+"\";"; 63 connection.execute(query);64 65 64 try { 66 ResultSet results = connection.getResultSet(); 67 if (results != null && results.first()) { 68 return AbstractDocument.readSQL(connection, results); 69 } 65 Statement statement = connection.createStatement(); 66 ResultSet results = statement.executeQuery(query); 67 68 DocumentInterface di = null; 69 if (results.first()) { 70 di = AbstractDocument.readSQL(connection, results); 71 } 72 statement.close(); 73 return di; 70 74 } 71 75 catch (SQLException sqlEx) { 72 System.err.println( sqlEx);76 System.err.println("AbstractDocument.readSQLDocument():"+sqlEx); 73 77 } 74 78 return null; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java
r8861 r9874 13 13 14 14 import java.sql.SQLException; 15 import java.sql.Statement; 15 16 import java.sql.ResultSet; 16 17 … … 68 69 select.setWhere(where); 69 70 70 this.connection.execute(select.toString()); 71 72 ResultSet results = this.connection.getResultSet(); 73 if (results != null) { 74 select = new GS3SQLSelect("filegroups"); 75 select.addField("DocID"); 76 select.setDistinct(true); 77 78 where = new GS3SQLWhere(); 79 where.setCondition(GS3SQLWhere.OR_CONDITION); 80 81 GS3SQLWhereItem whereItem = null; 82 83 try { 84 results.first(); 71 try { 72 Statement statement = connection.createStatement(); 73 ResultSet results = statement.executeQuery(select.toString()); 74 75 select = new GS3SQLSelect("filegroups"); 76 select.addField("DocID"); 77 select.setDistinct(true); 78 79 where = new GS3SQLWhere(); 80 where.setCondition(GS3SQLWhere.OR_CONDITION); 81 82 GS3SQLWhereItem whereItem = null; 83 84 results.first(); 85 85 do { 86 86 int fileGroupRef = results.getInt("FileGroupRef"); … … 90 90 while (results.next()); 91 91 select.setWhere(where); 92 results.close(); 93 94 this.connection.execute(select.toString()); 95 96 results = this.connection.getResultSet(); 92 93 results = statement.executeQuery(select.toString()); 94 97 95 results.first(); 98 96 do { … … 100 98 reply.add(docId); 101 99 } while (results.next()); 102 } 103 catch (SQLException sqlEx) 104 { System.err.println(sqlEx); 105 } 106 } 100 statement.close(); 101 } 102 catch (SQLException sqlEx) { 103 System.err.println("DocumentList.getDocumentIdsWithFile(): "+sqlEx); 104 } 105 107 106 return reply; 108 107 } … … 173 172 } 174 173 175 private List findDocumentIdsUsingFileQuery(String query) 176 { this.connection.execute(query); 177 178 try { 179 180 ResultSet results = this.connection.getResultSet(); 181 if (results == null || 182 !results.first()) { 183 return null; 184 } 174 private List findDocumentIdsUsingFileQuery(String query) { 175 176 try { 177 178 Statement statement = connection.createStatement(); 179 ResultSet results = statement.executeQuery(query); 180 181 if (!results.first()) { 182 statement.close(); 183 return null; 184 } 185 185 186 186 // get a list of group ids first and turn it into a query on filegroups … … 207 207 // structures...recreating new filegroup queries as necessary 208 208 while (queryBuffer.length() > 0) { 209 connection.execute(queryBuffer.toString());210 211 results = this.connection.getResultSet();212 if (results == null || !results.first()) {213 return null;209 results = statement.executeQuery(queryBuffer.toString()); 210 211 if (!results.first()) { 212 statement.close(); 213 return null; 214 214 } 215 215 … … 256 256 257 257 // execute the division query 258 this.connection.execute(queryBuffer.toString()); 259 260 results = this.connection.getResultSet(); 261 if (results == null || 262 !results.first()) { 263 return null; 258 results = statement.executeQuery(queryBuffer.toString()); 259 260 if (!results.first()) { 261 statement.close(); 262 return null; 264 263 } 265 264 … … 268 267 reply.add(results.getString("DocID")); 269 268 } while (results.next()); 270 269 270 statement.close(); 271 271 return reply; 272 272 } 273 273 catch (SQLException ex) { 274 System.err.println( ex);274 System.err.println("DocumentList.findDocumentIdsUsingFileQuery()"+ ex); 275 275 } 276 276 return null; … … 454 454 select.addField("*"); 455 455 456 ResultSet documents;457 456 try { 458 connection.execute(select.toString());459 documents = connection.getResultSet();460 461 if (documents.first()) 462 { do 463 { DocumentInterface document = AbstractDocument.readSQL(connection, documents);464 list.addDocument(document); 465 }466 while (documents.next());467 } 468 } 469 catch (java.sql.SQLException ex) 470 { System.out.println(ex);471 457 Statement statement = connection.createStatement(); 458 ResultSet documents = statement.executeQuery(select.toString()); 459 if (documents.first()) { 460 do { 461 DocumentInterface document = AbstractDocument.readSQL(connection, documents); 462 list.addDocument(document); 463 } 464 while (documents.next()); 465 } 466 statement.close(); 467 } 468 catch (java.sql.SQLException ex) { 469 System.out.println("DocumentList.writeSQLDocuments(): "+ex); 470 return null; 472 471 } 473 472 … … 487 486 { 488 487 private boolean hasNext; 488 private Statement statement; 489 489 private ResultSet resultSet; 490 490 private GS3SQLConnection connection; … … 498 498 499 499 try { 500 connection.execute(select.toString());501 this.resultSet = connection.getResultSet();500 this.statement = connection.createStatement(); 501 this.resultSet = statement.executeQuery(select.toString()); 502 502 this.hasNext = this.resultSet.first(); 503 503 } catch (SQLException ex) { 504 System.err.println("DocumentListIterator(): "+ex); 504 505 this.hasNext = false; 505 506 } … … 520 521 521 522 if (!this.hasNext) { 522 this.resultSet.close(); // be a good citizen & close used result sets523 this.statement.close(); // be a good citizen & close used statement 523 524 } 524 525 } catch (SQLException ex) { 526 System.err.println("DocumentList.iterator.next(): "+ex); 525 527 this.hasNext = false; 526 528 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java
r8742 r9874 19 19 update.addDate("IndexedDate", new java.sql.Timestamp(touchTime)); 20 20 update.addDate("ModifiedDate", new java.sql.Timestamp(modTime)); 21 connection.execute(update.toString()); 21 try { 22 Statement statement = connection.createStatement(); 23 statement.execute(update.toString()); 24 statement.close(); 25 } catch (SQLException e) { 26 System.err.println("DocumentSQLWriter.touchDocument() Error: "+ e); 27 return false; 28 } 22 29 System.out.println(update.toString()); 23 30 return true; … … 39 46 select.addField("*"); 40 47 select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString()))); 41 connection.execute(select.toString());42 48 43 ResultSet results = connection.getResultSet(); 44 45 if (results == null || 46 !results.first()) 47 { GS3SQLInsert insert = new GS3SQLInsert("document"); 49 Statement statement = connection.createStatement(); 50 ResultSet results = statement.executeQuery(select.toString()); 51 if (!results.first()) { // empty result 52 GS3SQLInsert insert = new GS3SQLInsert("document"); 48 53 insert.addValue("DocID", document.getID().toString()); 49 54 insert.addValue("DocType", document.getDocumentType()); … … 53 58 insert.addDate("ModifiedDate", new java.sql.Timestamp(document.getModifiedDatestamp())); 54 59 55 connection.execute(insert.toString());60 statement.execute(insert.toString()); 56 61 } 57 62 else { … … 61 66 // connection.execute(update.toString()); 62 67 } 68 statement.close(); 63 69 } 64 } catch ( Exception ex) {65 System.out.println( ex);70 } catch (SQLException ex) { 71 System.out.println("DocumentSQLWriter.writeDocument() Error:"+ex); 66 72 } 67 73 // output.println(tag); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/HTMLDocument.java
r8929 r9874 279 279 public Document getDOMDocument() 280 280 { 281 if (this.domDocument == null) {281 if (this.domDocument == null) { 282 282 URL url =(URL) this.fileSet.getFile(0).getLocation(); 283 283 this.loadDocument(url); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGPPIndexer.java
r9006 r9874 175 175 { 176 176 if (this.pass == 0) { 177 document.removeAllMetadata("gsdl3", "mg ppseqno");177 document.removeAllMetadata("gsdl3", "mgseqno"); 178 178 } 179 179 … … 188 188 String docText = null; 189 189 190 int startSeqNo = this.sectionSeqNo; 191 this.sectionSeqNo ++; 192 190 //int startSeqNo = this.sectionSeqNo; 191 //this.sectionSeqNo ++; 192 int startSeqNo = this.documentSeqNo; 193 193 194 Document domDocument = document.getDOMDocument(); 194 195 if (domDocument != null) { … … 288 289 289 290 if (this.pass == 0) { 290 document.addDocumentMetadata("gsdl3", "mg ppseqno", "dtx."+Integer.toString(startSeqNo));291 } 292 this.documentSeqNo += 1;291 document.addDocumentMetadata("gsdl3", "mgseqno", "dtx."+Integer.toString(startSeqNo)); 292 } 293 this.documentSeqNo++; 293 294 294 295 // try { … … 317 318 this.firstDocument = true; 318 319 this.documentSeqNo = 1; 319 320 this.sectionSeqNo = 1; 321 320 322 this.mgppPasses = new MGPPPassesWrapper(); 321 323 this.indexBuffer = new StringBuffer(); … … 430 432 System.out.println("Compressed dictionary successfully written"); 431 433 } else { 432 System.err.println("Error from mg_compression_dict: " + exit_value); 433 index.setError(true); 434 434 System.err.println("Error from mgpp_compression_dict: " + exit_value); 435 //index.setError(true); 435 436 return false; 436 437 } … … 444 445 } else { 445 446 System.err.println("Unable to build the perfect hash"); 446 index.setError(true);447 //index.setError(true); 447 448 return false; 448 449 } … … 456 457 } else { 457 458 System.err.println("Unable to create weights file"); 458 index.setError(true);459 //index.setError(true); 459 460 return false; 460 461 } … … 466 467 } else { 467 468 System.out.println("Unable to create inverted dictionary file"); 468 index.setError(true);469 //index.setError(true); 469 470 return false; 470 471 } … … 476 477 } else { 477 478 System.out.println("Unable to create stemmed index 1"); 478 index.setError(true);479 //index.setError(true); 479 480 return false; 480 481 } … … 485 486 } else { 486 487 System.out.println("Unable to create stemmed index 2"); 487 index.setError(true);488 //index.setError(true); 488 489 return false; 489 490 } … … 493 494 } else { 494 495 System.out.println("Unable to create stemmed index 3"); 495 index.setError(true);496 //index.setError(true); 496 497 return false; 497 498 } … … 553 554 Element default_index = doc.createElement("defaultIndex"); 554 555 default_index.setAttribute(GSXML.NAME_ATT, def_index); 556 555 557 Element base_index_name = doc.createElement("baseIndexPrefix"); 556 base_index_name.setAttribute(GSXML.NAME_ATT, "index"); //overallName); 558 base_index_name.setAttribute(GSXML.NAME_ATT, "dtx"); //overallName); 559 557 560 Element index_stem = doc.createElement("indexStem"); 558 561 index_stem.setAttribute(GSXML.NAME_ATT, "index"); … … 561 564 Element retrieve_service_elem = doc.createElement(GSXML.SERVICE_CLASS_ELEM); 562 565 Element default_level = doc.createElement("defaultLevel"); 563 default_index.setAttribute(GSXML.NAME_ATT, "Document"); 566 default_level.setAttribute(GSXML.NAME_ATT, "Document"); 567 568 Element level_list = doc.createElement("levelList"); 569 Element level = doc.createElement("level"); 570 level.setAttribute(GSXML.NAME_ATT, "Document"); 571 level_list.appendChild(level); 572 573 Element field_list = doc.createElement("fieldList"); 574 Element field = doc.createElement("field"); 575 field.setAttribute(GSXML.NAME_ATT, "ZZ"); 576 field_list.appendChild(field); 577 564 578 service_rack_list.appendChild(search_service_elem); 565 579 service_rack_list.appendChild(retrieve_service_elem); … … 568 582 search_service_elem.appendChild(index_list); 569 583 search_service_elem.appendChild(default_index); 584 search_service_elem.appendChild(level_list); 570 585 search_service_elem.appendChild(default_level); 586 search_service_elem.appendChild(field_list); // do we need this?? 571 587 search_service_elem.appendChild(base_index_name); 572 588 search_service_elem.appendChild(index_stem); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java
r8742 r9874 8 8 9 9 import java.sql.SQLException; 10 import java.sql.Statement; 10 11 import java.sql.ResultSet; 11 12 … … 275 276 } else { 276 277 // TODO: raise an error! 277 System.out.println("Error: METSDescri iptive: unrecognised tag "+childName);278 System.out.println("Error: METSDescriptive: unrecognised tag "+childName); 278 279 } 279 280 } … … 375 376 select.setWhere(where); 376 377 377 connection.execute(select.toString());378 379 378 try { 379 Statement statement = connection.createStatement(); 380 ResultSet resultSet = statement.executeQuery(select.toString()); 380 381 GS3SQLAction action; 381 382 382 ResultSet resultSet = connection.getResultSet(); 383 384 if (resultSet != null && 385 resultSet.first()) { 383 if (resultSet.first()) { 386 384 // the node already exists - no need to do anything as such 387 385 GS3SQLUpdate update = new GS3SQLUpdate("metadata"); … … 389 387 action = update; 390 388 } 391 else 392 { // Set result set to null, just in case next() didn't work above... 393 resultSet = null; 394 395 // It is a new node and needs writing 396 action = new GS3SQLInsert("metadata"); 397 398 action.addValue("DocID", document.getID().toString()); 399 action.addValue("MetaID", this.ID); 400 } 389 else { // Set result set to null, just in case first() didn't work above... 390 // It is a new node and needs writing 391 action = new GS3SQLInsert("metadata"); 392 393 action.addValue("DocID", document.getID().toString()); 394 action.addValue("MetaID", this.ID); 395 } 401 396 402 397 // always set the group identifier … … 404 399 405 400 // execute the action as required 406 connection.execute(action.toString()); 407 408 // create a new resultset if necessary 409 if (resultSet == null) { 410 // now execute the select statement again to get the new identifier 411 // 'MetadataRef' 412 // System.out.println(select.toString()); 413 connection.execute(select.toString()); 414 415 resultSet = connection.getResultSet(); 416 resultSet.first(); 417 } 418 419 // get the reference for this item... 420 sqlId = resultSet.getInt("MetadataRef"); 401 statement.execute(action.toString()); 402 403 // get the resultSet again 404 // now execute the select statement again to get the new identifier 405 // 'MetadataRef' 406 // System.out.println(select.toString()); 407 resultSet = statement.executeQuery(select.toString()); 408 409 if (resultSet.first()) { 410 // get the reference for this item... 411 sqlId = resultSet.getInt("MetadataRef"); 412 } 413 statement.close(); 421 414 } 422 415 catch (SQLException sql){ 423 System.out.println(sql); 416 System.err.println("METSDescriptive.writeSQL(): "+sql); 417 } 418 if (sqlId == -1) { 419 return false; 424 420 } 425 421 … … 471 467 select.setWhere(where); 472 468 473 connection.execute(select.toString()); 474 475 // parse through the namespaces, calling the namespace class to create instances 476 // as it will 477 ResultSet namespaceSet = connection.getResultSet(); 478 if (namespaceSet != null && namespaceSet.first()) { 469 Statement statement = connection.createStatement(); 470 ResultSet namespaceSet = statement.executeQuery(select.toString()); 471 472 // parse through the namespaces, calling the namespace class to create instances as it will 473 if (namespaceSet.first()) { 479 474 do { 480 475 METSNamespace namespace = METSNamespace.readSQL(connection, namespaceSet); … … 483 478 } 484 479 else { 485 System. out.println("Null namespace output");480 System.err.println("Null namespace output"); 486 481 } 487 482 } 488 483 while (namespaceSet.next()); 489 484 } 490 485 statement.close(); 491 486 return descriptive; 492 487 } 493 488 catch (SQLException sqlEx){ 494 System. out.println(sqlEx);489 System.err.println("METSDescriptive.readSQL(): "+sqlEx); 495 490 System.exit(1); 496 491 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java
r8742 r9874 9 9 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 import java.sql.ResultSet; 12 13 … … 236 237 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 237 238 select.setWhere(new GS3SQLWhere(whereItem)); 238 connection.execute(select.toString()); 239 239 240 240 // start going through the matching metadata blocks 241 241 try { 242 ResultSet resultSet = connection.getResultSet(); 243 resultSet.first(); 244 do { 245 METSDescriptive descriptive = METSDescriptive.readSQL(document, connection, resultSet); 246 if (descriptive != null) { 247 set.addDescriptive(descriptive); 248 } 249 else { 250 System.out.println("Null descriptive"); 251 } 252 } while (resultSet.next()); 242 Statement statement = connection.createStatement(); 243 ResultSet resultSet = statement.executeQuery(select.toString()); 244 if (resultSet.first()) { 245 do { 246 METSDescriptive descriptive = METSDescriptive.readSQL(document, connection, resultSet); 247 if (descriptive != null) { 248 set.addDescriptive(descriptive); 249 } 250 else { 251 System.out.println("Null descriptive"); 252 } 253 } while (resultSet.next()); 254 } 255 statement.close(); 253 256 } 254 257 catch (SQLException sqlEx) { 255 System. out.println(sqlEx);258 System.err.println("METSDescriptiveSet.readSQL(): "+sqlEx); 256 259 System.exit(1); 257 260 } 258 261 262 259 263 return set; 260 264 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java
r8742 r9874 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 475 476 select.setWhere(where); 476 477 477 connection.execute(select.toString()); 478 Statement statement = null; 479 ResultSet resultSet = null; 478 480 479 481 // Do the actual writing 480 482 GS3SQLAction action; 481 483 482 ResultSet resultSet = connection.getResultSet();483 484 try { 484 if (resultSet == null ||485 !resultSet.first()) {486 resultSet = null;485 statement = connection.createStatement(); 486 resultSet = statement.executeQuery(select.toString()); 487 if (!resultSet.first()) { 487 488 488 489 GS3SQLInsert insert = new GS3SQLInsert("divisions"); … … 499 500 GS3SQLUpdate update = new GS3SQLUpdate("divisions"); 500 501 GS3SQLWhere updateWhere = 501 new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), 502 GS3SQLField.INTEGER_TYPE)); 502 new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE)); 503 503 update.setWhere(updateWhere); 504 504 action = update; … … 515 515 action.addValue("UserLabel", this.userLabel); 516 516 517 if (!connection.execute(action.toString())){ 517 try { 518 statement.execute(action.toString()); 519 } catch (SQLException e) { 520 System.err.println("METSDivision.writeSQL(): "+e); 518 521 return false; 519 522 } 520 523 521 524 // if doing a fresh item, get the new structure reference... 522 if ( resultSet == null){525 if (sqlRef == -1){ 523 526 // get the new structure reference 524 connection.execute(select.toString());525 526 // get the sql reference for the division527 527 try { 528 528 // read in the structure reference 529 resultSet = connection.getResultSet();530 if (resultSet == null) {531 return false;529 resultSet = statement.executeQuery(select.toString()); 530 if (resultSet.first()) { 531 sqlRef = resultSet.getInt("DivisionRef"); 532 532 } 533 resultSet.first();534 sqlRef = resultSet.getInt("DivisionRef");535 resultSet.close();536 resultSet = null;537 533 } 538 534 catch (SQLException sqlex) { 539 System.err.println(" Unable to retrieve reference for Division " + sqlex);535 System.err.println("METSDIVISION.writeSQL(): Unable to retrieve reference for Division " + sqlex); 540 536 return false; 541 537 } 542 538 } 543 // close the open resultSet, as we don't need it any longer...544 else {545 try {546 resultSet.close();547 }548 catch (SQLException sql) {549 System.err.println(sql + " " + select.toString());550 }551 }552 539 553 540 // delete the old file/metadata references 554 GS3SQLWhere referenceWhere = 555 new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), 556 GS3SQLField.INTEGER_TYPE)); 557 558 GS3SQLDelete delete = new GS3SQLDelete("divisionfilerefs"); 559 delete.setWhere(referenceWhere); 560 connection.execute(delete.toString()); 561 562 delete = new GS3SQLDelete("divisionmetarefs"); 563 delete.setWhere(referenceWhere); 564 connection.execute(delete.toString()); 565 566 // write the new file references 567 if (this.fileRefs.size() > 0){ 568 Iterator iterator = this.fileRefs.iterator(); 569 570 while (iterator.hasNext()) { 571 GS3SQLInsert fileinsert = new GS3SQLInsert("divisionfilerefs"); 572 fileinsert.addValue("DocID", docId.toString()); 573 fileinsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 574 fileinsert.addValue("DivisionType", "Group"); 575 fileinsert.addValue("FileID", iterator.next().toString()); 576 connection.execute(fileinsert.toString()); 577 } 578 } 579 580 // write the metadata references 581 if (this.metadataRefs.size() > 0){ 582 Iterator iterator = this.metadataRefs.iterator(); 583 584 while (iterator.hasNext()) { 585 GS3SQLInsert metainsert = new GS3SQLInsert("divisionmetarefs"); 586 metainsert.addValue("DocID", docId.toString()); 587 metainsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 588 metainsert.addValue("DivisionType", "Group"); 589 metainsert.addValue("MetaID", iterator.next().toString()); 590 connection.execute(metainsert.toString()); 591 } 592 } 593 541 try { 542 GS3SQLWhere referenceWhere = 543 new GS3SQLWhere(new GS3SQLWhereItem("DivisionRef", "=", Integer.toString(sqlRef), 544 GS3SQLField.INTEGER_TYPE)); 545 546 GS3SQLDelete delete = new GS3SQLDelete("divisionfilerefs"); 547 delete.setWhere(referenceWhere); 548 549 statement.execute(delete.toString()); 550 551 delete = new GS3SQLDelete("divisionmetarefs"); 552 delete.setWhere(referenceWhere); 553 statement.execute(delete.toString()); 554 555 // write the new file references 556 if (this.fileRefs.size() > 0){ 557 Iterator iterator = this.fileRefs.iterator(); 558 559 while (iterator.hasNext()) { 560 GS3SQLInsert fileinsert = new GS3SQLInsert("divisionfilerefs"); 561 fileinsert.addValue("DocID", docId.toString()); 562 fileinsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 563 fileinsert.addValue("DivisionType", "Group"); 564 fileinsert.addValue("FileID", iterator.next().toString()); 565 statement.execute(fileinsert.toString()); 566 } 567 } 568 569 // write the metadata references 570 if (this.metadataRefs.size() > 0){ 571 Iterator iterator = this.metadataRefs.iterator(); 572 573 while (iterator.hasNext()) { 574 GS3SQLInsert metainsert = new GS3SQLInsert("divisionmetarefs"); 575 metainsert.addValue("DocID", docId.toString()); 576 metainsert.addValue("DivisionRef", Integer.toString(sqlRef), GS3SQLField.INTEGER_TYPE); 577 metainsert.addValue("DivisionType", "Group"); 578 metainsert.addValue("MetaID", iterator.next().toString()); 579 statement.execute(metainsert.toString()); 580 } 581 } 582 statement.close(); 583 } catch (SQLException e) { 584 System.err.println("METSDIVISION.writeSQL(): "+e); 585 return false; 586 } 594 587 // write out any children in turn 595 588 Iterator groups = this.children.values().iterator(); … … 633 626 select.setWhere(where); 634 627 635 connection.execute(select.toString()); 628 Statement statement = connection.createStatement(); 629 ResultSet childSet = statement.executeQuery(select.toString()); 636 630 637 631 // circulate through to obtain further children 638 ResultSet childSet = connection.getResultSet();639 632 if (childSet.first()) 640 633 { … … 645 638 while (childSet.next()); 646 639 } 647 648 640 select = new GS3SQLSelect("divisionfilerefs"); 649 641 select.addField("*"); … … 652 644 select.setWhere(where); 653 645 654 connection.execute(select.toString()); 655 656 ResultSet fileSet = connection.getResultSet(); 657 if (fileSet != null && fileSet.first()){ 646 ResultSet fileSet = statement.executeQuery(select.toString()); 647 648 if (fileSet.first()){ 658 649 do { 659 650 String reference = fileSet.getString("FileID"); … … 662 653 while (fileSet.next()); 663 654 } 664 655 665 656 select = new GS3SQLSelect("divisionmetarefs"); 666 657 select.addField("*"); … … 669 660 select.setWhere(where); 670 661 671 connection.execute(select.toString()); 672 673 ResultSet metaSet = connection.getResultSet(); 674 if (metaSet != null && metaSet.first()){ 662 ResultSet metaSet = statement.executeQuery(select.toString()); 663 664 if (metaSet.first()){ 675 665 do { 676 666 String reference = metaSet.getString("MetaID"); … … 680 670 } 681 671 672 statement.close(); 682 673 return division; 683 674 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java
r8742 r9874 11 11 import java.sql.ResultSet; 12 12 import java.sql.SQLException; 13 import java.sql.Statement; 13 14 14 15 import org.w3c.dom.Document; … … 201 202 where.add(whereItem); 202 203 select.setWhere(where); 203 connection.execute(select.toString()); 204 205 Statement statement = null; 204 206 205 207 // if not, then make an insert action 206 208 try { 207 ResultSet results = connection.getResultSet();208 if (results == null ||209 209 statement = connection.createStatement(); 210 ResultSet results = statement.executeQuery(select.toString()); 211 if (!results.first()){ 210 212 GS3SQLInsert insert = new GS3SQLInsert("files"); 211 213 … … 223 225 } 224 226 catch (SQLException ex){ 225 System.err.println( ex);227 System.err.println("METSFile.writeSQL(): "+ex); 226 228 return false; 227 229 } … … 230 232 action.addValue("MIMEType", this.MIMEType); 231 233 232 return connection.execute(action.toString()); 234 try { 235 statement.execute(action.toString()); 236 statement.close(); 237 238 } catch (SQLException e) { 239 System.err.println("METSFile.writeSQL():"+e); 240 return false; 241 } 242 return true; 233 243 } 234 244 … … 248 258 } 249 259 catch (SQLException ex){ 250 System.out.println( ex);260 System.out.println("METSFile.readSQL(): "+ex); 251 261 } 252 262 catch (java.net.MalformedURLException urlEx){ 253 System.out.println( urlEx);263 System.out.println("METSFile.readSQL(): "+urlEx); 254 264 } 255 265 return null; … … 309 319 } catch (java.net.MalformedURLException ex) { 310 320 // TODO: raise error 311 System.err.println( ex);321 System.err.println("METSFile.parse_flocateXML(): "+ex); 312 322 } 313 323 return thisFilePos; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java
r8742 r9874 8 8 9 9 import java.sql.SQLException; 10 import java.sql.Statement; 10 11 import java.sql.ResultSet; 11 12 … … 271 272 { 272 273 int sqlId = -1; 273 274 274 // check if this node is in the database already 275 275 GS3SQLSelect select = new GS3SQLSelect("filegroups"); … … 281 281 select.setWhere(where); 282 282 283 connection.execute(select.toString()); 284 285 ResultSet selectResult = connection.getResultSet(); 283 ResultSet results = null; 284 Statement statement = null; 286 285 287 286 try { 288 if (selectResult == null || 289 !selectResult.first()) { 287 statement = connection.createStatement(); 288 results = statement.executeQuery(select.toString()); 289 if (!results.first()) { 290 290 GS3SQLInsert insert = new GS3SQLInsert("filegroups"); 291 291 … … 295 295 insert.addValue("ParentType", parentIsSection ? SECTION_PARENT : GROUP_PARENT); 296 296 297 if (!connection.execute(insert.toString())) { 298 return false; 299 } 297 statement.execute(insert.toString()); 300 298 } 301 299 else { … … 304 302 } 305 303 catch (SQLException ex){ 306 System.err.println( ex);304 System.err.println("METSFileGroup.writeSQL(): "+ex); 307 305 return false; 308 306 } 309 307 310 308 // get the filegroup reference now 311 connection.execute(select.toString());312 313 309 try { 314 ResultSet results = connection.getResultSet(); 315 if (results == null) { 310 results = statement.executeQuery(select.toString()); 311 if (results.first()) { 312 sqlId = results.getInt("FileGroupRef"); 313 } else { 314 statement.close(); 316 315 return false; 317 316 } 318 results.first(); 319 sqlId = results.getInt("FileGroupRef"); 320 } 321 catch (SQLException sqlex) { 322 System.out.println(sqlex); 317 statement.close(); 318 } catch (SQLException sqlex) { 319 System.err.println("METSFileGroup.writeSQL(): "+sqlex); 323 320 return false; 324 321 } 325 326 322 // iterate over the child groups 327 323 Iterator childIter = childGroups.iterator(); … … 330 326 331 327 if (!fileGroup.writeSQL(document, Integer.toString(sqlId), false, connection)){ 328 System.err.println("METSFileGroup.writeSQL(): Couldn't write FileGroup"); 332 329 return false; 333 330 } … … 337 334 childIter = children.iterator(); 338 335 while (childIter.hasNext()){ 339 METSFile file = (METSFile) childIter.next(); 340 336 METSFile file = (METSFile) childIter.next(); 341 337 if (!file.writeSQL(sqlId, connection)){ 338 System.err.println("METSFileGroup.writeSQL(): Couldn't write File"); 342 339 return false; 343 340 } … … 371 368 select.setWhere(where); 372 369 373 connection.execute(select.toString());370 Statement statement = connection.createStatement(); 374 371 375 372 // parse through the child groups 376 ResultSet childSet = connection.getResultSet();373 ResultSet childSet = statement.executeQuery(select.toString()); 377 374 if (childSet.first()) { 378 375 do { … … 384 381 while (childSet.next()); 385 382 } 386 387 383 // now scan for file members 388 384 select = new GS3SQLSelect("files"); 389 385 select.addField("*"); 390 whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), 391 GS3SQLField.INTEGER_TYPE); 386 whereItem = new GS3SQLWhereItem("FileGroupRef", "=", Integer.toString(groupRef), GS3SQLField.INTEGER_TYPE); 392 387 where = new GS3SQLWhere(whereItem); 393 388 select.setWhere(where); 394 connection.execute(select.toString()); 395 396 ResultSet childFileSet = connection.getResultSet(); 397 if (childFileSet != null && childFileSet.first()) { 389 ResultSet childFileSet = statement.executeQuery(select.toString()); 390 if (childFileSet.first()) { 398 391 do { 399 392 METSFile file = METSFile.readSQL(connection, childFileSet); … … 404 397 while (childFileSet.next()); 405 398 } 406 399 statement.close(); 407 400 return group; 408 401 } 409 402 catch (SQLException sqlEx){ 410 System. out.println(sqlEx);403 System.err.println("METSFileGroup.readSQL(): "+sqlEx); 411 404 System.exit(1); 412 405 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java
r8742 r9874 16 16 17 17 import java.sql.SQLException; 18 import java.sql.Statement; 18 19 import java.sql.ResultSet; 19 20 … … 232 233 insert.addValue("FileSecID", "test"); // TODO: remove magic string 233 234 234 if (!connection.execute(insert.toString())){ 235 Statement statement = null; 236 try { 237 statement = connection.createStatement(); 238 statement.execute(insert.toString()); 239 } catch (SQLException e) { 240 System.err.println("METSFileSet.writeSQL(): "+e); 235 241 return false; 236 242 } … … 246 252 247 253 try { 248 connection.execute(select.toString());249 250 ResultSet set = connection.getResultSet();251 set.first();252 int sectionRef = set.getInt("FileSectionRef");253 254 this.reference = Integer.toString(sectionRef);254 ResultSet set = statement.executeQuery(select.toString()); 255 if (set.first()) { 256 int sectionRef = set.getInt("FileSectionRef"); 257 258 this.reference = Integer.toString(sectionRef); 259 } 260 statement.close(); 255 261 } 256 262 catch (SQLException ex){ 257 System.out.println( ex);263 System.out.println("METSFileSet.writeSQL(): "+ex); 258 264 return false; 259 265 } 260 266 } 261 267 268 if (this.reference == null) { 269 return false; 270 } 262 271 // write out the children 263 272 while (groups.hasNext()){ … … 281 290 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 282 291 select.setWhere(new GS3SQLWhere(whereItem)); 283 connection.execute(select.toString()); 292 293 Statement statement = null; 284 294 285 295 // Get the identifier for this file set, etc. 286 ResultSet sections = connection.getResultSet(); 287 int fileSetRef; 296 int fileSetRef = -1; 288 297 try { 289 sections.first(); 290 fileSetRef = sections.getInt("FileSectionRef"); 291 set.reference = Integer.toString(fileSetRef); 298 statement = connection.createStatement(); 299 ResultSet sections = statement.executeQuery(select.toString()); 300 if (sections.first()) { 301 fileSetRef = sections.getInt("FileSectionRef"); 302 set.reference = Integer.toString(fileSetRef); 303 } else { 304 statement.close(); 305 return null; 306 } 307 292 308 } 293 309 catch (SQLException ex){ 294 System. out.println(ex);310 System.err.println("METSFileSet.readSQL() "+ex); 295 311 return null; 296 312 } 297 298 313 // Get child file groups 299 314 select = new GS3SQLSelect("filegroups"); … … 307 322 where.add(whereItem); 308 323 select.setWhere(where); 309 connection.execute(select.toString());310 311 324 // start going through the matching file groups 312 325 try { 313 ResultSet resultSet = connection.getResultSet(); 314 resultSet.first(); 315 do { 316 METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet); 317 if (filegroup != null) { 318 set.addGroup(filegroup); 319 } 320 } while (resultSet.next()); 326 ResultSet resultSet = statement.executeQuery(select.toString()); 327 if (resultSet.first()) { 328 do { 329 METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet); 330 if (filegroup != null) { 331 set.addGroup(filegroup); 332 } 333 } while (resultSet.next()); 334 } 335 statement.close(); 321 336 } 322 337 catch (SQLException sqlEx) { 323 System.out.println( sqlEx);338 System.out.println("METSFileSet.readSQL(): "+sqlEx); 324 339 System.exit(1); 325 340 } 326 327 341 return set; 328 342 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSNamespace.java
r8742 r9874 6 6 import java.util.Iterator; 7 7 import java.sql.SQLException; 8 import java.sql.Statement; 8 9 import java.sql.ResultSet; 9 10 … … 150 151 151 152 // Execute the action 152 connection.execute(action.toString()); 153 153 Statement statement = null; 154 try { 155 statement = connection.createStatement(); 156 statement.execute(action.toString()); 157 } catch (SQLException e) { 158 System.err.println("METSNamespace.writeSQL(): "+e); 159 return false; 160 } 154 161 // then get the namespace reference number if needsbe... 155 162 if (this.id == null) { … … 161 168 where.add(where); 162 169 try { 163 connection.execute(select.toString());164 165 ResultSet result = connection.getResultSet();166 result.last();167 this.id = Integer.toString(result.getInt("NamespaceRef"));170 ResultSet result = statement.executeQuery(select.toString()); 171 if (result.last()) { 172 this.id = Integer.toString(result.getInt("NamespaceRef")); 173 } 174 statement.close(); 168 175 } 169 176 catch (SQLException sqlex){ 170 177 this.id = null; 171 System.err.println( sqlex);178 System.err.println("METSNamespace.writeSQL(): "+sqlex); 172 179 return false; 173 180 } … … 201 208 select.setWhere(where); 202 209 203 connection.execute(select.toString()); 204 205 ResultSet valuesSet = connection.getResultSet(); 206 if (valuesSet != null && valuesSet.first()) { 210 Statement statement = connection.createStatement(); 211 ResultSet valuesSet = statement.executeQuery(select.toString()); 212 if (valuesSet.first()) { 207 213 do { 208 214 String label = valuesSet.getString("Label"); … … 213 219 while (valuesSet.next()); 214 220 } 215 221 statement.close(); 216 222 return namespace; 217 223 } 218 224 catch (java.net.MalformedURLException urlEx){ 219 System. out.println(urlEx);225 System.err.println("METSNamespace.readSQL(): "+urlEx); 220 226 } 221 227 catch (SQLException sqlEx){ 222 System. out.println(sqlEx);228 System.err.println("METSNamespace.readSQL(): "+sqlEx); 223 229 } 224 230 return null; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructure.java
r8742 r9874 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 180 181 { 181 182 int sqlRef = -1; 182 ResultSet results; 183 183 ResultSet results = null; 184 Statement statement = null; 185 184 186 // Prepare query to see if this structure has already been written 185 187 GS3SQLSelect select = new GS3SQLSelect("structure"); … … 190 192 where.add(item); 191 193 select.setWhere(where); 192 194 193 195 // attempt to execute the query & get the current structure's reference 194 196 try { 195 connection.execute(select.toString()); 196 results = connection.getResultSet(); 197 if (results != null && 198 results.first()){ 197 statement = connection.createStatement(); 198 results = statement.executeQuery(select.toString()); 199 if (results.first()){ 199 200 sqlRef = results.getInt("structureRef"); 200 201 } 201 else {202 results = null;203 }204 205 if (results != null) {206 results.close();207 }208 202 } 209 203 catch (SQLException sqlEx) { 210 System.err.print( sqlEx);204 System.err.print("METSStructure.writeSQL(): "+sqlEx); 211 205 return false; 212 206 } 213 207 214 208 // insert a new structure if it wasn't there previously 215 if ( results == null) {209 if (sqlRef == -1) { 216 210 GS3SQLInsert insert = new GS3SQLInsert("structure"); 217 211 insert.addValue("DocID", document.getID().toString()); … … 220 214 insert.addValue("Label", this.label); 221 215 222 if (!connection.execute(insert.toString())) { 216 try { 217 statement.execute(insert.toString()); 218 219 // get the new structure reference by re-running the original select object 220 results = statement.executeQuery(select.toString()); 221 if (results.first()) { 222 sqlRef = results.getInt("StructureRef"); 223 } 224 } catch (SQLException sqlEx) { 225 System.err.print("METSStructure.writeSQL(): "+sqlEx); 223 226 return false; 224 227 } 225 228 226 // get the new structure reference by re-running the original select object227 connection.execute(select.toString());228 229 try {230 results = connection.getResultSet();231 results.first();232 sqlRef = results.getInt("StructureRef");233 }234 catch (SQLException sql) {235 System.err.println(sql);236 return false;237 }238 229 } 239 230 else { … … 244 235 update.addValue("Label", this.label); 245 236 246 connection.execute(update.toString()); 247 } 248 237 try { 238 statement.execute(update.toString()); 239 } catch (SQLException sqlEx) { 240 System.err.print("METSStructure.writeSQL(): "+sqlEx); 241 return false; 242 } 243 } 244 245 // close the statement 246 try { 247 statement.close(); 248 } catch (SQLException e) { 249 System.err.println("METSStructure.writeSQL(): "+e); 250 } 249 251 // write out the child groups (Divisions) now... 250 252 Iterator groups = this.children.values().iterator(); … … 296 298 select.setWhere(where); 297 299 298 connection.execute(select.toString()); 300 Statement statement = connection.createStatement(); 301 ResultSet divisionSet = statement.executeQuery(select.toString()); 299 302 300 303 // parse through the divisions 301 ResultSet divisionSet = connection.getResultSet(); 302 if (divisionSet != null && divisionSet.first()) { 304 if (divisionSet.first()) { 303 305 do { 304 306 METSDivision division = METSDivision.readSQL(connection, divisionSet); … … 309 311 while (divisionSet.next()); 310 312 } 311 313 statement.close(); 312 314 return structure; 313 315 } 314 catch (SQLException sqlEx) 315 { System.out.println(sqlEx + " " + select.toString());316 catch (SQLException sqlEx) { 317 System.err.println("METSStructure.readSQL(): "+ sqlEx + " " + select.toString()); 316 318 System.exit(1); 317 319 } 318 320 return null; 319 321 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java
r8742 r9874 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 157 158 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 158 159 select.setWhere(new GS3SQLWhere(whereItem)); 159 connection.execute(select.toString()); 160 160 161 161 // start going through the matching metadata blocks 162 162 try { 163 ResultSet resultSet = connection.getResultSet(); 164 resultSet.first(); 165 do { 166 METSStructure structure = METSStructure.readSQL(document, connection, resultSet); 167 if (structure != null) { 168 set.addStructure(structure); 169 } 170 } while (resultSet.next()); 163 Statement statement = connection.createStatement(); 164 ResultSet resultSet = statement.executeQuery(select.toString()); 165 if (resultSet.first()) { 166 do { 167 METSStructure structure = METSStructure.readSQL(document, connection, resultSet); 168 if (structure != null) { 169 set.addStructure(structure); 170 } 171 } while (resultSet.next()); 172 } 173 statement.close(); 171 174 } 172 175 catch (SQLException sqlEx) { 173 System. out.println(sqlEx);176 System.err.println("METSStructureSet.readSQL(): "+sqlEx); 174 177 System.exit(1); 175 178 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/SimpleNamespace.java
r8742 r9874 9 9 10 10 import java.sql.SQLException; 11 import java.sql.Statement; 11 12 import java.sql.ResultSet; 12 13 … … 281 282 } 282 283 284 Statement statement = null; 285 ResultSet results = null; 283 286 try { 287 statement = connection.createStatement(); 284 288 if (this.id == null) { 285 289 GS3SQLSelect select = new GS3SQLSelect("namespaces"); 286 290 select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("MetadataRef", "=", Integer.toString(parentId), GS3SQLField.INTEGER_TYPE))); 287 291 select.addField("NamespaceRef"); 288 connection.execute(select.toString()); 289 290 ResultSet results = connection.getResultSet(); 291 results.first(); 292 sqlId = Integer.toString(results.getInt("NamespaceRef")); 292 results = statement.executeQuery(select.toString()); 293 if (results.first()) { 294 sqlId = Integer.toString(results.getInt("NamespaceRef")); 295 } else { 296 statement.close(); 297 return false; 298 } 293 299 } 294 300 else { … … 300 306 GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("NamespaceRef", "=", sqlId, GS3SQLField.INTEGER_TYPE)); 301 307 delete.setWhere(where); 302 connection.execute(delete.toString());308 statement.execute(delete.toString()); 303 309 304 310 // write out the metadata for this namespace … … 316 322 insert.addValue("Label", thisKey); 317 323 insert.addValue("Value", value); 318 connection.execute(insert.toString()); 319 } 320 } 324 statement.execute(insert.toString()); 325 } 326 } 327 statement.close(); 321 328 } 322 329 catch (SQLException sql) { 323 System.out.println( sql);330 System.out.println("SimpleNamespace.writeSQL(): "+sql); 324 331 } 325 332 return true; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java
r8869 r9874 12 12 public class NotifierManager { 13 13 14 public NotifierManager() { 15 } 14 public NotifierManager() { 15 } 16 17 public void detectEvents(CollectionManager collManager) { 18 String notifyHost = collManager.getNotifyHost(); 19 if (notifyHost == null) 20 return; 16 21 17 public void detectEvents(CollectionManager collManager) { 18 String notifyHost = collManager.getNotifyHost(); 19 if (notifyHost == null) 20 return; 21 22 System.out.println("detecting events"); 23 24 String collectionName = collManager.getCollectionName(); 25 String host = "http://localhost:8080/soap/servlet/rpcrouter"; 26 27 String lastBuild = dateToSqlString(collManager.getBuildDate()); 28 System.out.println("last build was " + lastBuild); 29 Statement statement = collManager.getDatabase().createStatement(); 22 System.out.println("detecting events"); 23 24 String collectionName = collManager.getCollectionName(); 25 String host = "http://localhost:8080/soap/servlet/rpcrouter"; 26 27 String lastBuild = dateToSqlString(collManager.getBuildDate()); 28 System.out.println("last build was " + lastBuild); 30 29 try { 30 Statement statement = collManager.getDatabase().createStatement(); 31 31 // detect all new documents. A document is new if and only if 32 32 // AccessionDate >= CollectionLastRebuiltDate 33 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 34 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document"); 35 36 // detect modified documents. A document is modified if and only if 37 // AccessionDate < CollectionLastRebuiltDate (ie, it is not new) and 38 // IndexedDate >= CollectionLastRebuiltDate 39 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND IndexedDate >= " + lastBuild); 40 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified"); 41 42 // TODO deleted docs? 33 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 34 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document"); 35 36 // detect modified documents. A document is modified if and only if 37 // AccessionDate < CollectionLastRebuiltDate (ie, it is not new) and 38 // IndexedDate >= CollectionLastRebuiltDate 39 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND IndexedDate >= " + lastBuild); 40 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified"); 41 42 statement.close(); 43 // TODO deleted docs? 43 44 } catch (SQLException e) { 44 45 45 // TODO Auto-generated catch block 46 e.printStackTrace(); 46 47 } 47 48 48 } 49 49 50 /** 50 51 * @param collName … … 58 59 * @throws SQLException 59 60 */ 60 61 62 63 64 65 66 67 61 private void notify(String collName, String hostURL, String notifyHost, ResultSet results, GS3SQLConnection database, Date date, String eventType) { 62 try { 63 System.out.println("notifyHost is " + notifyHost); 64 URL url = new URL("http://" + notifyHost + "/alerting/service"); 65 System.out.println("trying to send to " + url); 66 67 while(results.next()) { 68 System.out.println(eventType + ": " + results.getString("DocID")); 68 69 69 70 String documentID = results.getString("DocID"); 70 71 71 72 try { 72 73 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // TODO what about proxies? 73 74 conn.setUseCaches(false); … … 112 113 e1.printStackTrace(); 113 114 } 114 115 116 117 118 115 } 116 } catch (SQLException e) { 117 // TODO Auto-generated catch block 118 e.printStackTrace(); 119 } catch (MalformedURLException e) { 119 120 // TODO Auto-generated catch block 120 121 e.printStackTrace(); 121 122 } 122 123 } 123 124 124 125 /** … … 129 130 private String getDocumentTitle(String documentID, GS3SQLConnection database) { 130 131 System.out.println("getting title for document " + documentID + " from database"); 131 Statement statement = database.createStatement();132 132 133 ResultSet results;134 133 try { 134 Statement statement = database.createStatement(); 135 135 String sqlString = "SELECT mdvalues.value " + 136 137 138 139 140 141 142 143 144 145 results = statement.executeQuery(sqlString);146 if (results. next()) {136 "FROM structure s JOIN divisions d ON (s.structureref = d.parentref) " + 137 " JOIN divisionmetarefs USING (divisionref) " + 138 " JOIN metadata m USING (metaid) " + 139 " JOIN namespaces USING (metadataref) " + 140 " JOIN mdvalues USING (namespaceref) " + 141 " WHERE mdvalues.label = 'Title' AND s.docid = '" + documentID + "'" + 142 " AND s.structureType = 'Whole Document' " + 143 " AND d.parenttype = 'Structure' " + 144 " AND m.docID = s.docid;"; 145 ResultSet results = statement.executeQuery(sqlString); 146 if (results.first()) { 147 147 String title = results.getString("value"); 148 148 System.out.println("title is " + title); 149 149 return title; 150 150 } 151 statement.close(); 151 152 } catch (SQLException e) { 152 153 e.printStackTrace(); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/HTMLTidy.java
r8710 r9874 93 93 handler.setContentHandler(this); 94 94 handler.setProperty("http://xml.org/sax/properties/lexical-handler", commentHandler); 95 handler.parse(file.to String());95 handler.parse(file.toURI().toString()); 96 96 } 97 97 catch (java.io.IOException io) 98 98 { 99 System.out.println(io); 99 100 } 100 101 catch (org.xml.sax.SAXException saxEx) -
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. -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java
r9000 r9874 20 20 21 21 // Greenstone classes 22 import org.greenstone.g dbm.*;22 import org.greenstone.gsdl3.core.GSException; 23 23 import org.greenstone.gsdl3.util.GSXML; 24 24 import org.greenstone.gsdl3.util.GSFile; … … 27 27 import org.greenstone.gsdl3.util.GS2MacroResolver; 28 28 import org.greenstone.gsdl3.util.GSConstants; 29 29 import org.greenstone.gsdl3.util.GDBMWrapper; 30 import org.greenstone.gsdl3.util.DBInfo; 30 31 // XML classes 31 32 import org.w3c.dom.Document; … … 66 67 } 67 68 68 69 public void cleanUp() { 70 super.cleanUp(); 71 this.gdbm_src.closeDatabase(); 72 } 69 73 /** configure this service */ 70 74 public boolean configure(Element info, Element extra_info) … … 146 150 // assumes only one value per metadata 147 151 protected Element getMetadataList(String node_id, boolean all_metadata, 148 ArrayList metadata_names) { 152 ArrayList metadata_names) 153 throws GSException { 149 154 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 150 155 DBInfo info = this.gdbm_src.getInfo(node_id); … … 281 286 * <nodeContent>text content or other elements</nodeContent> 282 287 */ 283 abstract protected Element getNodeContent(String doc_id) ;288 abstract protected Element getNodeContent(String doc_id) throws GSException; 284 289 285 290 protected String getMetadata(String node_id, DBInfo info, -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS3DocumentRetrieve.java
r9000 r9874 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; … … 62 63 // set up a macro resolver 63 64 } 64 65 66 public void cleanUp() { 67 super.cleanUp(); 68 this.database.closeConnection(); 69 } 65 70 66 71 /** configure this service */ … … 109 114 } 110 115 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 116 /** returns the id of the root node of the document containing node node_id. . may be the same as node_id */ 119 117 protected String getRootId(String node_id) { … … 150 148 // assumes only one value per metadata 151 149 protected Element getMetadataList(String node_id, boolean all_metadata, 152 ArrayList metadata_names) { 150 ArrayList metadata_names) 151 throws GSException { 153 152 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 154 153 … … 215 214 * <nodeContent>text content or other elements</nodeContent> 216 215 */ 217 abstract protected Element getNodeContent(String doc_id) ;216 abstract protected Element getNodeContent(String doc_id) throws GSException; 218 217 219 218 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractMGPPSearch.java
r9280 r9874 112 112 { 113 113 this.mgpp_src = new MGPPWrapper(); 114 } 115 116 public void cleanUp() { 117 super.cleanUp(); 118 this.mgpp_src.unloadIndexData(); 114 119 } 115 120 … … 331 336 } else if (name.equals(RANK_PARAM)) { 332 337 String [] vals1 = {RANK_PARAM_RANK, RANK_PARAM_NONE }; 333 String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang), getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang , "MGPPSearch")};338 String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang), getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang)}; 334 339 335 340 param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param."+RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1, vals1_texts ); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractMGSearch.java
r9280 r9874 77 77 } 78 78 79 public void cleanUp() { 80 super.cleanUp(); 81 this.mg_src.unloadIndexData(); 82 } 79 83 public boolean configure(Element info, Element extra_info) 80 84 { … … 201 205 this.mg_src.runQuery(basedir, textdir, query); 202 206 MGQueryResult mqr = this.mg_src.getQueryResult(); 207 if (mqr.isClear()) { 208 // something has gone wrong 209 GSXML.addError(this.doc, result, "Couldn't query the mg database", GSXML.ERROR_TYPE_SYSTEM); 210 return result; 211 } 203 212 long totalDocs = mqr.getTotalDocs(); 204 213 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GATEServices.java.tmp
r6501 r9874 226 226 227 227 annotated_text = "<nodeContent>" + annotated_text + "</nodeContent>"; 228 Element annotated_content = this.converter.getDOM(annotated_text).getDocumentElement(); 229 doc_node.replaceChild(doc_node.getOwnerDocument().importNode(annotated_content, true), content); 230 } 228 Document annotated_content_doc = this.converter.getDOM(annotated_text); 229 if (annotated_content_doc != null) { 230 Element annotated_content = annotated_content_doc.getDocumentElement(); 231 doc_node.replaceChild(doc_node.getOwnerDocument().importNode(annotated_content, true), content); 232 } else { 233 System.err.println("GATEServices.processGatePOSTag Error: Couldn't parse annotated text for doc node "+i); 234 } 235 } 231 236 232 237 result.appendChild(this.doc.importNode(doc_node_list, true)); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Browse.java
r8959 r9874 20 20 21 21 // Greenstone classes 22 import org.greenstone.gdbm.*;23 22 import org.greenstone.gsdl3.util.OID; 24 23 import org.greenstone.gsdl3.util.GSXML; … … 26 25 import org.greenstone.gsdl3.util.MacroResolver; 27 26 import org.greenstone.gsdl3.util.GS2MacroResolver; 28 27 import org.greenstone.gsdl3.util.GDBMWrapper; 28 import org.greenstone.gsdl3.util.DBInfo; 29 29 // XML classes 30 30 import org.w3c.dom.Document; … … 54 54 this.gdbm_src = new GDBMWrapper(); 55 55 this.macro_resolver = new GS2MacroResolver(this.gdbm_src); 56 } 57 58 public void cleanUp() { 59 super.cleanUp(); 60 this.gdbm_src.closeDatabase(); 56 61 } 57 62 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java
r8959 r9874 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; … … 47 48 public GS2MGPPRetrieve() { 48 49 this.mgpp_src = new MGPPWrapper(); 50 } 51 52 public void cleanUp() { 53 super.cleanUp(); 54 this.mgpp_src.unloadIndexData(); 49 55 } 50 56 … … 79 85 * <nodeContent>text content or other elements</nodeContent> 80 86 */ 81 protected Element getNodeContent(String doc_id) {87 protected Element getNodeContent(String doc_id) throws GSException { 82 88 String lang = "en"; // ********** 83 89 long doc_num = this.gdbm_src.OID2Docnum(doc_id); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java
r9002 r9874 21 21 // Greenstone classes 22 22 import org.greenstone.gsdl3.util.*; 23 import org.greenstone.gdbm.*;24 23 25 24 // XML classes … … 43 42 { 44 43 this.gdbm_src = new GDBMWrapper(); 44 } 45 46 public void cleanUp() { 47 super.cleanUp(); 48 this.gdbm_src.closeDatabase(); 45 49 } 46 50 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java
r8959 r9874 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; … … 44 45 public GS2MGRetrieve() { 45 46 this.mg_src = new MGWrapper(); 47 } 48 49 public void cleanUp() { 50 super.cleanUp(); 51 this.mg_src.unloadIndexData(); 46 52 } 47 53 … … 80 86 * <nodeContent>text content or other elements</nodeContent> 81 87 */ 82 protected Element getNodeContent(String doc_id) {88 protected Element getNodeContent(String doc_id) throws GSException { 83 89 String lang = "en"; // ********** 84 90 long doc_num = this.gdbm_src.OID2Docnum(doc_id); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java
r9002 r9874 21 21 // Greenstone classes 22 22 import org.greenstone.gsdl3.util.*; 23 import org.greenstone.gdbm.*;24 23 25 24 // XML classes … … 43 42 { 44 43 this.gdbm_src = new GDBMWrapper(); 44 } 45 public void cleanUp() { 46 super.cleanUp(); 47 this.gdbm_src.closeDatabase(); 45 48 } 46 49 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Browse.java
r8959 r9874 52 52 } 53 53 54 public void cleanUp() { 55 super.cleanUp(); 56 this.database.closeConnection(); 57 } 58 54 59 public boolean configure(Element info, Element extra_info) 55 60 { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPRetrieve.java
r8959 r9874 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; … … 47 48 } 48 49 50 public void cleanUp() { 51 super.cleanUp(); 52 this.mgpp_src.unloadIndexData(); 53 } 54 49 55 /** configure this service */ 50 56 public boolean configure(Element info, Element extra_info) 51 57 { 58 // Do generic configuration 59 if (!super.configure(info, extra_info)) { 60 return false; 61 } 62 52 63 // Do specific configuration 53 64 System.out.println("Configuring GS3MGPPRetrieve..."); … … 66 77 // The location of the MGPP text files 67 78 mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + 68 File.separatorChar + GSFile.collectionTextPath(this. cluster_name);79 File.separatorChar + GSFile.collectionTextPath(this.index_stem); 69 80 70 // Do generic configuration 71 return super.configure(info, extra_info); 72 81 return true; 73 82 } 74 83 … … 77 86 * <nodeContent>text content or other elements</nodeContent> 78 87 */ 79 protected Element getNodeContent(String doc_id) {88 protected Element getNodeContent(String doc_id) throws GSException { 80 89 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) { 81 90 // if we have a whole doc id, and the document is hierarchical, -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPSearch.java
r9002 r9874 50 50 { 51 51 this.database = new SQLQuery(); 52 } 53 54 public void cleanUp() { 55 super.cleanUp(); 56 this.database.closeConnection(); 52 57 } 53 58 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java
r9001 r9874 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; … … 42 43 private String mg_textdir = null; 43 44 private String default_index = null; 45 44 46 public GS3MGRetrieve() { 45 47 this.mg_src = new MGWrapper(); 48 } 49 50 public void cleanUp() { 51 super.cleanUp(); 52 this.mg_src.unloadIndexData(); 46 53 } 47 54 … … 86 93 * <nodeContent>text content or other elements</nodeContent> 87 94 */ 88 protected Element getNodeContent(String doc_id) {95 protected Element getNodeContent(String doc_id) throws GSException { 89 96 90 97 if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) { … … 111 118 } catch (Exception e) { 112 119 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"; 120 throw new GSException("Couldn't get document content for id: "+ doc_int+"\n"+e.getMessage()); 121 //doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n"; 114 122 } 115 123 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGSearch.java
r9002 r9874 50 50 { 51 51 this.database = new SQLQuery(); 52 } 53 54 public void cleanUp() { 55 super.cleanUp(); 56 this.database.closeConnection(); 52 57 } 53 58 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaProxy.java
r8158 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.gdbm.*;5 4 import org.greenstone.gsdl3.util.*; 6 5 … … 406 405 doc_node.setAttribute(GSXML.NODE_ID_ATT, doc_id); 407 406 408 Element content_element = this.converter.getDOM(processed_content.toString()).getDocumentElement(); 409 doc_node.appendChild(this.doc.importNode(content_element, true)); 410 407 Document content_doc = this.converter.getDOM(processed_content.toString()); 408 if (content_doc != null) { 409 Element content_element = content_doc.getDocumentElement(); 410 doc_node.appendChild(this.doc.importNode(content_element, true)); 411 } else { 412 System.err.println("IViaProxy.getDocument Error: Couldn't parse the node content"); 413 } 411 414 return doc_node; 412 415 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java
r9289 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.g dbm.*;4 import org.greenstone.gsdl3.core.GSException; 5 5 import org.greenstone.gsdl3.util.*; 6 6 … … 61 61 62 62 /** gets a document by sending a request to iVia, then processes it and creates a documentNode around the text */ 63 protected Element getNodeContent(String doc_id) { 63 protected Element getNodeContent(String doc_id) 64 throws GSException { 64 65 65 66 String url_string = ivia_server_url+"/cgi-bin/view_record?theme=gsdl3&record_id="+doc_id; … … 67 68 StringBuffer buffer = new StringBuffer(); 68 69 try { 69 BufferedReader reader = makeConnection(url_string);70 BufferedReader reader = Misc.makeHttpConnection(url_string); 70 71 String line; 71 72 while((line = reader.readLine())!= null) { 72 73 buffer.append(line); 73 74 } 74 } catch (Exception e) { 75 System.err.println("IViaRetrieve Error:exception happened"); 76 e.printStackTrace(); 77 } 78 75 } catch (java.net.MalformedURLException e) { 76 throw new GSException("Malformed URL: "+url_string, GSXML.ERROR_TYPE_SYSTEM); 77 } catch (java.io.IOException e) { 78 throw new GSException("IOException during connection to "+url_string+": "+e.toString(),GSXML.ERROR_TYPE_SYSTEM); 79 } 80 79 81 String node_content = buffer.toString(); 80 82 … … 99 101 processed_content.append("</nodeContent>"); 100 102 101 Element content_element = this.converter.getDOM(processed_content.toString()).getDocumentElement(); 103 Document content_doc = this.converter.getDOM(processed_content.toString()); 104 if (content_doc == null) { 105 System.err.println("IViaRetrieve.getNodeContent Error: Couldn't parse node content"); 106 System.err.println(processed_content.toString()); 107 return null; 108 } 109 110 Element content_element = content_doc.getDocumentElement(); 102 111 103 112 return (Element)this.doc.importNode(content_element,true); … … 169 178 } 170 179 171 protected BufferedReader makeConnection(String url_string) {172 BufferedReader reader = null;173 try {174 URL url = new URL(url_string);175 HttpURLConnection connection = (HttpURLConnection)url.openConnection();176 InputStream input = connection.getInputStream();177 reader = new BufferedReader(new InputStreamReader(input));178 } catch (java.net.MalformedURLException e) {179 System.err.println("IViaRetrieve: Malformed URL: "+url_string);180 } catch (java.io.IOException e) {181 System.err.println("IViaRetrieve Error: An error occurred during IO to url "+url_string);182 }183 return reader;184 }185 186 180 protected String translateId(String oid){ 187 181 int p = oid.lastIndexOf('.'); … … 215 209 protected Element getMetadataList (String doc_id, 216 210 boolean all_metadata, 217 ArrayList metadata_names){ 211 ArrayList metadata_names) 212 throws GSException { 218 213 219 214 Element meta_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); … … 236 231 String url_string = ivia_server_url+"/cgi-bin/view_record_set?theme=gsdl3&record_id_list="+doc_id+"&field_list="+field_list.toString(); 237 232 try { 238 BufferedReader reader = makeConnection(url_string);233 BufferedReader reader = Misc.makeHttpConnection(url_string); 239 234 String line; 240 235 while ((line = reader.readLine()) != null) { … … 249 244 GSXML.addMetadata(this.doc, meta_list, name, value); 250 245 } 251 } catch (Exception e) { 252 System.err.println("IViaRetrieve Error:exception happened"); 253 e.printStackTrace(); 246 } catch (java.net.MalformedURLException e) { 247 throw new GSException("Malformed URL: "+url_string, GSXML.ERROR_TYPE_SYSTEM); 248 } catch (java.io.IOException e) { 249 throw new GSException("IOException: "+e.toString(), GSXML.ERROR_TYPE_SYSTEM); 254 250 } 255 251 return meta_list; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaSearch.java
r9273 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.gdbm.*;5 4 import org.greenstone.gsdl3.util.*; 6 5 … … 14 13 import java.util.HashMap; 15 14 import java.io.File; 16 import java.io.InputStream;17 15 import java.io.BufferedReader; 18 import java.io.InputStreamReader;19 import java.io.IOException;20 import java.net.HttpURLConnection;21 import java.net.URLConnection;22 import java.net.URL;23 16 import java.net.Authenticator; 24 import java.net.MalformedURLException;25 17 26 18 /** 27 19 * 28 20 * @author <a href="mailto:[email protected]">Katherine Don</a> 29 * @version $Revision$ 30 * Modified by <a href="mailto:[email protected]">Chi-Yu Huang</a> 21 * @author <a href="mailto:[email protected]">Chi-Yu Huang</a> 31 22 */ 32 23 … … 109 100 String results_num = null; 110 101 String doc_ids = null; 102 BufferedReader reader = null; 111 103 try { 112 104 ///system.err.println("IViaSearch, sending "+url_string); 113 BufferedReader reader = makeConnection(url_string);105 reader = Misc.makeHttpConnection(url_string); 114 106 results_num = reader.readLine(); 115 107 doc_ids = reader.readLine(); 116 } catch (Exception e) { 117 System.err.println("IViaSearch.TextQuery Error: exception happened during query"); 118 e.printStackTrace(); 108 } catch (java.net.MalformedURLException e) { 109 GSXML.addError(this.doc, result, "Malformed URL: "+url_string); 110 return result; 111 } catch (java.io.IOException e) { 112 GSXML.addError(this.doc, result, "IOException during connection to "+url_string+": "+e.toString()); 119 113 return result; 120 114 } … … 124 118 } else { 125 119 System.err.println("IViaSearch.TextQuery Error: badly formatted results line: "+results_num); 120 GSXML.addError(this.doc, result, "Error: badly formatted result from IVia server: "+results_num); 126 121 return result; 127 122 } … … 130 125 } else { 131 126 System.err.println("IViaSearch.TextQuery Error: badly formatted docs line: "+doc_ids); 127 GSXML.addError(this.doc, result, "Error: badly formatted result from IVia server: "+doc_ids); 132 128 return result; 133 129 } … … 150 146 } 151 147 152 protected BufferedReader makeConnection(String url_string) {153 BufferedReader reader = null;154 try {155 URL url = new URL(url_string);156 HttpURLConnection connection = (HttpURLConnection)url.openConnection();157 InputStream input = connection.getInputStream();158 reader = new BufferedReader(new InputStreamReader(input));159 } catch (java.net.MalformedURLException e) {160 System.err.println("IViaSearch Error: Malformed URL: "+url_string);161 } catch (java.io.IOException e) {162 System.err.println("IViaSearch Error: An error occurred during IO to url "+url_string);163 }164 return reader;165 }166 148 167 149 /** -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/LuceneSearch.java
r9272 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.gdbm.*;5 4 import org.greenstone.gsdl3.util.*; 6 5 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MapRetrieve.java
r6694 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.gdbm.*;5 4 import org.greenstone.gsdl3.util.*; 6 5 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MapSearch.java
r9286 r9874 20 20 21 21 // Greenstone classes 22 import org.greenstone.gdbm.*;23 22 import org.greenstone.gsdl3.util.*; 24 23 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ModuleWrapper.java
r3621 r9874 100 100 101 101 } 102 103 public void cleanUp() {} 104 102 105 /** The all-args constructor */ 103 106 public ModuleWrapper(String in,String out, ModuleInterface inner){ -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/PhindPhraseBrowse.java
r6490 r9874 56 56 this.mgpp_src.setCase(true); 57 57 } 58 59 public void cleanUp() { 60 super.cleanUp(); 61 this.mgpp_src.unloadIndexData(); 62 } 63 58 64 /** configure the service module 59 65 * … … 89 95 90 96 Document dom = this.converter.getDOM(app_info); 97 if (dom==null) { 98 System.err.println("PhindPhraseBrowse.configure Error: Couldn't parse applet info"); 99 return false; 100 } 91 101 Element app_elem = dom.getDocumentElement(); 92 102 applet_description.appendChild(this.doc.importNode(app_elem, true)); 93 103 94 104 return true; 95 105 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceRack.java
r9426 r9874 95 95 setClusterName(coll_name); 96 96 } 97 98 public void cleanUp() {} 97 99 98 100 /** sets the site home */ … … 144 146 145 147 Document doc = this.converter.getDOM(xml_in); 146 148 if (doc == null) { 149 System.err.println("ServiceRack.process(String) Error: Couldn't parse request"); 150 System.err.println(xml_in); 151 return null; 152 } 147 153 Element res = process(doc.getDocumentElement()); 148 154 return this.converter.getString(res); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/Visualizer.java
r8347 r9874 75 75 76 76 Document dom = converter.getDOM(app_info); 77 if (dom == null) { 78 System.err.println("Visualizer.configure Error: Couldn't parse applet info"); 79 return false; 80 } 77 81 Element app_elem = dom.getDocumentElement(); 78 82 applet_description.appendChild(this.doc.importNode(app_elem, true)); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/Dictionary.java
r9424 r9874 47 47 this.raw = ResourceBundle.getBundle(this.resource, this.locale); 48 48 } catch (Exception e) { 49 System.err.println("Dictionary: couldn't locate a resource bundle for "+resource);49 //System.err.println("Dictionary: couldn't locate a resource bundle for "+resource); 50 50 } 51 51 } … … 70 70 this.raw = ResourceBundle.getBundle(this.resource, this.locale); 71 71 } catch (Exception ex) { 72 System.err.println("Dictionary: couldn't locate a resource bundle for "+resource);72 //System.err.println("Dictionary: couldn't locate a resource bundle for "+resource); 73 73 } 74 74 … … 129 129 } 130 130 catch (Exception e) { 131 System.err.println("Dictionary Error: couldn't find string for key:" + key +" in resource "+this.resource);131 //System.err.println("Dictionary Error: couldn't find string for key:" + key +" in resource "+this.resource); 132 132 return null; 133 133 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java
r8962 r9874 20 20 21 21 import java.util.ArrayList; 22 import org.greenstone.gdbm.GDBMWrapper;23 import org.greenstone.gdbm.DBInfo;24 22 25 23 public class GS2MacroResolver -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java
r9425 r9874 20 20 21 21 import java.io.File; 22 import org.apache.soap.encoding.soapenc.Base64; 22 //import org.apache.soap.encoding.soapenc.Base64; 23 import org.apache.axis.encoding.Base64; 23 24 import java.io.BufferedInputStream; 24 25 import java.io.BufferedOutputStream; … … 161 162 162 163 /** text path (for doc retrieval) relative to collectionBaseDir */ 163 static public String collectionTextPath(String collection_name) {164 static public String collectionTextPath(String index_stem) { 164 165 return "index"+File.separatorChar+"text"+File.separatorChar+ 165 collection_name;166 index_stem; 166 167 } 167 168 168 169 /** index path (for querying) relative to collectionBaseDir */ 169 static public String collectionIndexPath(String collection_name,170 static public String collectionIndexPath(String index_stem, 170 171 String index_name) { 171 172 return "index"+File.separatorChar+index_name+File.separatorChar+ 172 collection_name;173 index_stem; 173 174 } 174 175 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java
r9261 r9874 99 99 public static final String PARAM_IGNORE_POS_ATT = "ignore"; 100 100 public static final String CLASSIFIER_CONTENT_ATT = "content"; 101 101 public static final String ERROR_TYPE_ATT = "type"; 102 102 103 // document stuff 103 104 public static final String DOC_TYPE_ATT = "docType"; … … 173 174 public static final String COMM_TYPE_SOAP_JAVA = "soap"; 174 175 176 // error types 177 public static final String ERROR_TYPE_SYNTAX = "syntax"; 178 public static final String ERROR_TYPE_SYSTEM = "system"; 179 public static final String ERROR_TYPE_INVALID_ID = "invalid_id"; 180 public static final String ERROR_TYPE_OTHER = "other"; 181 175 182 // some system wide param names 176 183 public static final String SUBSET_PARAM = "subset"; … … 279 286 } 280 287 288 /** add an error message, unknown error type */ 289 public static boolean addError(Document owner, Element doc, String text) { 290 return addError(owner, doc, text, ERROR_TYPE_OTHER); 291 } 281 292 /** add an error message */ 282 public static boolean addError(Document owner, Element doc, String text) { 293 public static boolean addError(Document owner, Element doc, String text, 294 String error_type) { 283 295 284 296 Element content = owner.createElement(ERROR_ELEM); 297 content.setAttribute(ERROR_TYPE_ATT, error_type); 285 298 Text t = owner.createTextNode(text); 286 299 content.appendChild(t); … … 291 304 /** add an error message */ 292 305 public static boolean addError(Document owner, Element doc, Throwable error) { 293 error.printStackTrace(); 294 return addError(owner, doc, error.toString()); 306 return addError(owner, doc, error, ERROR_TYPE_OTHER); 307 } 308 309 /** add an error message */ 310 public static boolean addError(Document owner, Element doc, 311 Throwable error, String error_type) { 312 error.printStackTrace(); 313 return addError(owner, doc, error.toString(), error_type); 295 314 } 296 315 … … 402 421 } 403 422 423 public static NodeList getChildrenByTagName(Node n, String name) { 424 MyNodeList node_list = new MyNodeList(); 425 Node child = n.getFirstChild(); 426 while (child!=null) { 427 if (child.getNodeName().equals(name)) { 428 node_list.addNode(child); 429 } 430 child = child.getNextSibling(); 431 } 432 return node_list; 433 } 434 404 435 405 436 /** Duplicates an element, but gives it a new name */ … … 407 438 String element_name, boolean with_attributes) 408 439 { 409 Element duplicate = owner.createElement(element_name); 410 440 return duplicateWithNewNameNS(owner, element, element_name, null, with_attributes); 441 } 442 443 /** Duplicates an element, but gives it a new name */ 444 public static Element duplicateWithNewNameNS(Document owner, 445 Element element, 446 String element_name, 447 String namespace_uri, 448 boolean with_attributes) 449 { 450 Element duplicate; 451 if (namespace_uri == null) { 452 duplicate = owner.createElement(element_name); 453 } else { 454 duplicate = owner.createElementNS(namespace_uri, element_name); 455 } 411 456 // Copy element attributes 412 457 if (with_attributes) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/Misc.java
r7444 r9874 1 /* 2 * Misc.java 3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 1 19 2 20 package org.greenstone.gsdl3.util; 3 4 21 5 22 import java.util.HashMap; … … 8 25 import java.util.Iterator; 9 26 import java.util.Properties; 27 import java.io.InputStream; 28 import java.io.BufferedReader; 29 import java.io.InputStreamReader; 30 import java.io.IOException; 31 import java.net.HttpURLConnection; 32 import java.net.URL; 33 import java.net.URLConnection; 10 34 11 35 /** contains miscellaneous functions */ … … 31 55 } 32 56 57 public static BufferedReader makeHttpConnection(String url_string) 58 throws java.net.MalformedURLException, java.io.IOException { 59 BufferedReader reader = null; 60 URL url = new URL(url_string); 61 HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 62 InputStream input = connection.getInputStream(); 63 reader = new BufferedReader(new InputStreamReader(input)); 64 return reader; 65 } 66 33 67 } 68 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/SQLQuery.java
r8746 r9874 6 6 import java.sql.ResultSet; 7 7 import java.sql.SQLException; 8 import java.sql.Statement; 8 9 9 10 import java.util.ArrayList; … … 17 18 18 19 public boolean setDatabase(String db_name) { 19 try {20 connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name);21 20 connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name); 21 try { 22 22 23 // test the connection 23 24 String query = "select * from "+GSSQL.DOCUMENT_TABLE+GSSQL.END; 24 if (!connection.execute(query)) { 25 //connection.close(); 26 connection = null; 27 return false; 28 } 25 Statement s = connection.createStatement(); 26 s.execute(query); 27 s.close(); 29 28 return true; 30 29 } catch (Exception e) { 31 System.err.println("SQLQuery.setDatabase Exception"); 32 return false; 30 System.err.println("SQLQuery.setDatabase():"+e); 31 } 32 closeConnection(); 33 return false; 34 } 35 36 public void closeConnection() { 37 if (connection != null) { 38 connection.close(); 39 connection=null; 33 40 } 34 41 } … … 48 55 GSSQL.END; 49 56 50 connection.execute(query);57 Statement statement = null; 51 58 ResultSet results = null; 52 59 String doc_id = null; 53 60 String meta_id = null; 54 61 try { 55 results = connection.getResultSet(); 56 results.first(); 57 doc_id = results.getString(GSSQL.DOCUMENT_ID); 58 meta_id = results.getString(GSSQL.METADATA_ID); 59 } catch (java.sql.SQLException e) { 60 61 System.err.println("SQLQuery.MGNum2OID() Error: "+e.getMessage()); 62 return null; 63 } 64 System.out.println("doc id ="+doc_id+", meta id = "+meta_id); 62 statement = connection.createStatement(); 63 results = statement.executeQuery(query); 64 if (results.first()) { 65 doc_id = results.getString(GSSQL.DOCUMENT_ID); 66 meta_id = results.getString(GSSQL.METADATA_ID); 67 } else { 68 statement.close(); 69 return null; 70 } 71 } catch (java.sql.SQLException e) { 72 System.err.println("SQLQuery.MGNum2OID(): "+e); 73 return null; 74 } 65 75 66 76 // now get division label … … 73 83 GSSQL.END; 74 84 75 connection.execute(query);85 76 86 String short_label = null; 77 87 try { 78 results = connection.getResultSet(); 79 results.first(); 80 short_label = results.getString(GSSQL.SHORT_LABEL); 81 82 } catch (java.sql.SQLException e) { 88 results = statement.executeQuery(query); 89 if (results.first()) { 90 short_label = results.getString(GSSQL.SHORT_LABEL); 91 } else { 92 statement.close(); 93 return null; 94 } 95 statement.close(); 96 } catch (SQLException e) { 83 97 84 98 System.err.println("SQLQuery.MGNum2OID() Error: "+e.getMessage()); 85 99 return null; 86 100 } 87 88 ///ystem.out.println("short label = "+short_label); 89 90 System.out.println("final doc_id = "+GS3OID.createOID(doc_id, short_label)); 101 91 102 return GS3OID.createOID(doc_id, short_label); 92 103 } 93 104 94 105 public String OID2MGNum(String oid) { 95 System.out.println("converting oid "+oid+" to mg num");96 106 String id = getDocumentMetadata(oid, "gsdl3.mgseqno"); 97 System.out.println("mg id = "+id);98 107 return id; 99 108 … … 113 122 " and "+ GSSQL.STRUCTURE_ID +GSSQL.EQUALS_QUOTE + "Section" + GSSQL.QUOTE + 114 123 GSSQL.END; 115 116 connection.execute(query); 117 ResultSet results = null; 118 try { 119 results = connection.getResultSet(); 120 if (results.next()) { 121 return true; 122 } 124 boolean is_hierarchical = false; 125 try { 126 Statement statement = connection.createStatement(); 127 ResultSet results = statement.executeQuery(query); 128 is_hierarchical = results.first(); 129 statement.close(); 123 130 } catch (java.sql.SQLException e) { 124 131 return false; 125 132 } 126 127 return false;133 134 return is_hierarchical; 128 135 } 129 136 … … 131 138 public String getClassifierMetadata(String oid, String full_meta_name) { 132 139 133 if (full_meta_name.equals("Title") || full_meta_name.equals("numleafdocs")) { 134 // get the description 135 String field_name=""; 136 if (full_meta_name.equals("Title")) { 137 field_name = GSSQL.DESCRIPTION; 138 } else { 139 field_name = GSSQL.NUM_LEAF_DOCUMENTS; 140 } 141 142 String query = "select "+ field_name+ 143 " from " + GSSQL.CLASSIFIER_TABLE + 144 " where " + GSSQL.CLASSIFIER_ID + GSSQL.EQUALS_QUOTE + oid + GSSQL.QUOTE + 145 GSSQL.END; 140 if (!full_meta_name.equals("Title") && !full_meta_name.equals("numleafdocs")) { 141 return null; 142 } 143 // get the description 144 String field_name=""; 145 if (full_meta_name.equals("Title")) { 146 field_name = GSSQL.DESCRIPTION; 147 } else { 148 field_name = GSSQL.NUM_LEAF_DOCUMENTS; 149 } 150 151 String query = "select "+ field_name+ 152 " from " + GSSQL.CLASSIFIER_TABLE + 153 " where " + GSSQL.CLASSIFIER_ID + GSSQL.EQUALS_QUOTE + oid + GSSQL.QUOTE + 154 GSSQL.END; 155 156 String value = null; 157 try { 158 Statement statement = connection.createStatement(); 159 ResultSet results = statement.executeQuery(query); 160 if (results.first()) { 161 value = results.getString(field_name); 162 } 163 statement.close(); 164 } catch (java.sql.SQLException e) { 146 165 147 connection.execute(query); 148 ResultSet results = null; 149 String value = null; 150 try { 151 results = connection.getResultSet(); 152 results.first(); 153 value = results.getString(field_name); 154 } catch (java.sql.SQLException e) { 155 156 System.err.println("SQLQuery.getClassifierMetadata() Error: "+e.getMessage()); 157 return null; 158 } 159 return value; 160 161 } else return null; 162 166 System.err.println("SQLQuery.getClassifierMetadata() Error: "+e.getMessage()); 167 return null; 168 } 169 return value; 170 163 171 } 164 172 … … 172 180 section_id = GS3OID.getSectionLabel(oid); 173 181 } 174 System.out.println("getDocChildren: oid = "+oid+", doc id = "+doc_id+", sec id ="+section_id);175 182 // int sep_index = oid.indexOf("."); 176 183 // if (sep_index != -1) { … … 186 193 GSSQL.END; 187 194 188 connection.execute(query);189 195 ResultSet results = null; 196 Statement statement = null; 190 197 String div_ref = null; 191 198 try { 192 results = connection.getResultSet(); 193 results.first(); 194 div_ref = results.getString(GSSQL.DIVISION_REF); 199 statement = connection.createStatement(); 200 results = statement.executeQuery(query); 201 if (results.first()) { 202 div_ref = results.getString(GSSQL.DIVISION_REF); 203 } else { 204 statement.close(); 205 return null; 206 } 195 207 } catch (java.sql.SQLException e) { 196 208 … … 206 218 " and "+GSSQL.PARENT_REF+GSSQL.EQUALS_QUOTE+div_ref+GSSQL.QUOTE+ 207 219 GSSQL.END; 208 connection.execute(query); 209 results = null; 210 try { 211 results = connection.getResultSet(); 220 try { 221 results = statement.executeQuery(query); 212 222 while (results.next()) { 213 223 String id = results.getString(GSSQL.SHORT_LABEL); 214 224 children.add(GS3OID.createOID(doc_id, id)); 215 225 } 226 statement.close(); 216 227 } catch (java.sql.SQLException e) { 217 228 … … 243 254 GSSQL.END; 244 255 245 connection.execute(query); 246 ResultSet results = null; 247 try { 248 results = connection.getResultSet(); 256 try { 257 Statement statement = connection.createStatement(); 258 ResultSet results = statement.executeQuery(query); 249 259 while (results.next()) { 250 260 String id = results.getString(GSSQL.CLASSIFIER_ID); 251 261 children.add(id); 252 262 } 253 } catch (java.sql.SQLException e) { 254 263 statement.close(); 264 } catch (java.sql.SQLException e) { 265 255 266 System.err.println("SQLQuery.getClassifierChildren Error: "+e.getMessage()); 256 267 return null; … … 260 271 261 272 public ArrayList getClassifierDocChildren(String oid) { 262 System.out.println("in getclassifierdocchildren");263 273 ArrayList children = new ArrayList(); 264 274 … … 269 279 " order by "+GSSQL.CLASS_DOCUMENT_TABLE+GSSQL.DOT+GSSQL.DOCUMENT_ORDER+ 270 280 GSSQL.END; 271 System.out.println("query="+query); 272 connection.execute(query); 273 ResultSet results = null; 274 try { 275 results = connection.getResultSet(); 281 try { 282 Statement statement = connection.createStatement(); 283 ResultSet results = statement.executeQuery(query); 276 284 while (results.next()) { 277 285 String id = results.getString(GSSQL.DOCUMENT_ID); … … 283 291 return null; 284 292 } 285 // now check for documents286 293 287 294 return children; … … 302 309 // } 303 310 304 System.out.println("get meta for "+oid+", doc id = "+doc_id+"sec id = "+section_id);305 311 306 312 // get the metadata block id … … 314 320 GSSQL.END; 315 321 316 connection.execute(query);322 Statement statement = null; 317 323 ResultSet results = null; 318 324 String meta_id = null; 319 325 try { 320 results = connection.getResultSet(); 321 results.first(); 322 meta_id = results.getString(GSSQL.METADATA_ID); 326 statement = connection.createStatement(); 327 results = statement.executeQuery(query); 328 if (results.first()) { 329 meta_id = results.getString(GSSQL.METADATA_ID); 330 } else { 331 statement.close(); 332 return null; 333 } 323 334 } catch (java.sql.SQLException e) { 324 335 … … 326 337 return null; 327 338 } 328 System.err.println("metadata block id = "+meta_id); 329 339 330 340 // now get the list of namespace refs for the right namespace 331 341 int sep_index = full_meta_name.indexOf('.'); … … 337 347 meta_name = full_meta_name.substring(sep_index+1); 338 348 } 339 System.out.println("orig meta = "+full_meta_name+", ns = "+meta_ns+", name="+meta_name);340 349 341 350 query = "select * "+ … … 347 356 " and "+GSSQL.NAMESPACE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+GSSQL.EQUALS+GSSQL.METADATA_VALUE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+ 348 357 GSSQL.END; 349 System.out.println("query="+query); 350 connection.execute(query); 358 351 359 String meta_value = null; 352 360 try { 353 results = connection.getResultSet(); 361 statement = connection.createStatement(); 362 results = statement.executeQuery(query); 354 363 while (results.next()) { 355 364 String m_name = results.getString(GSSQL.LABEL); … … 359 368 } 360 369 } 370 statement.close(); 361 371 } catch (java.sql.SQLException e) { 362 372 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/XMLConverter.java
r8923 r9874 158 158 String nodeName = xmlNode.getNodeName(); 159 159 160 if (nodeType == Node.DOCUMENT_NODE) { 161 return getString(((Document)xmlNode).getDocumentElement(), depth, pretty); 162 } 160 163 // Handle Element nodes 161 164 if (nodeType == Node.ELEMENT_NODE) { -
trunk/gsdl3/src/packages/mg/java/org/greenstone/mg/MGQueryResult.java
r3794 r9874 53 53 } 54 54 55 public boolean isClear() { 56 return (total_num_docs_ == 0 && docs_.isEmpty() && terms_.isEmpty()); 57 } 55 58 56 59 /** returns the result as a String - useful for printing out results */ -
trunk/gsdl3/src/packages/mg/jni/MGWrapperImpl.c
r8920 r9874 315 315 316 316 /* Check that the index was loaded successfully */ 317 assert(qd != NULL); 317 if (qd==NULL) { 318 return NULL; 319 } 320 /*assert(qd != NULL);*/ 318 321 319 322 /* Get the document position and length in the text file */ … … 372 375 jthrowable exc; 373 376 374 /* Make sure an index has been specified */ 375 index_path = data->queryInfo->index; 376 assert(index_path != NULL); 377 378 /* Obtain C versions of the two string parameters */ 379 base_dir = (*j_env)->GetStringUTFChars(j_env, j_base_dir, NULL); 380 if (base_dir == NULL) { 381 return; 382 } 383 text_path = (*j_env)->GetStringUTFChars(j_env, j_text_path, NULL); 384 if (text_path == NULL) { 385 (*j_env)->ReleaseStringUTFChars(j_env, j_base_dir, base_dir); 386 return; 387 } 388 389 /* Load the appropriate index for satisfying this request */ 390 qd = loadIndexData((char*) base_dir, (char*) index_path, (char*) text_path); 391 392 /* The C text strings are no longer needed */ 393 (*j_env)->ReleaseStringUTFChars(j_env, j_base_dir, base_dir); 394 (*j_env)->ReleaseStringUTFChars(j_env, j_text_path, text_path); 395 396 /* Check that the index was loaded successfully */ 397 assert(qd != NULL); 398 399 /* Remove anything hanging around from last time */ 400 FreeQueryDocs(qd); 401 377 /* First of all, clear the previous result */ 402 378 /* The result to write to */ 403 379 result_ptr = (*j_env)->GetObjectField(j_env, j_obj, FID_query_result); … … 411 387 return; 412 388 } 389 390 /* Make sure an index has been specified */ 391 index_path = data->queryInfo->index; 392 assert(index_path != NULL); 393 394 /* Obtain C versions of the two string parameters */ 395 base_dir = (*j_env)->GetStringUTFChars(j_env, j_base_dir, NULL); 396 if (base_dir == NULL) { 397 return; 398 } 399 text_path = (*j_env)->GetStringUTFChars(j_env, j_text_path, NULL); 400 if (text_path == NULL) { 401 (*j_env)->ReleaseStringUTFChars(j_env, j_base_dir, base_dir); 402 return; 403 } 404 405 /* Load the appropriate index for satisfying this request */ 406 qd = loadIndexData((char*) base_dir, (char*) index_path, (char*) text_path); 407 408 /* The C text strings are no longer needed */ 409 (*j_env)->ReleaseStringUTFChars(j_env, j_base_dir, base_dir); 410 (*j_env)->ReleaseStringUTFChars(j_env, j_text_path, text_path); 411 412 /* Check that the index was loaded successfully */ 413 if (qd == NULL) { 414 return; 415 } 416 /*assert(qd != NULL);*/ 417 418 /* Remove anything hanging around from last time */ 419 FreeQueryDocs(qd); 413 420 414 421 /* Obtain a C version of the query string */ -
trunk/gsdl3/src/packages/mg/src/images/WIN32.MAK
r3921 r9874 156 156 157 157 mostlyclean: 158 rm -f *$o _*.c _*.o *._c *._o core core.* 158 if exist *$o del *$o 159 if exist _*.c del _*.c 160 if exist _*.o del _*.o 161 if exist *._c del *._c 162 if exist *._o del *._o 163 if exist core del core 164 if exist core.* del core.* 159 165 160 166 clean: mostlyclean 161 rm -f $(EXEC)167 if exist *$e del *$e 162 168 163 169 distclean: clean 164 rm -f ansi2knr 165 rm -f Makefile 166 170 del ansi2knr 171 167 172 maintainer-clean: distclean 168 173 @echo "This command is intended only for maintainers to use;" -
trunk/gsdl3/src/packages/mg/src/text/win32.mak
r7585 r9874 237 237 clean: 238 238 if exist *$o del *$o 239 if exist $(EXEC) del $(EXEC)239 if exist *$e del *$e 240 240 if exist libmgtextin.lib del libmgtextin.lib 241 241 if exist libmgpass.lib del libmgpass.lib -
trunk/gsdl3/src/packages/mg/winMake.bat
r6416 r9874 29 29 cd ..\.. 30 30 31 cd java\org\greenstone\mg 32 call winMake.bat %1 33 cd ..\..\..\.. 34 31 35 cd jni 32 36 %MAKE% %MAKE_OPTIONS% win32.mak %1 … … 40 44 41 45 :done 46 47
Note:
See TracChangeset
for help on using the changeset viewer.