Changeset 9874 for trunk/gsdl3/src


Ignore:
Timestamp:
2005-05-16T11:02:50+12:00 (19 years ago)
Author:
kjdon
Message:

merged from branch ant-install-branch: merge 1

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  
    1717 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1818 */
     19
    1920package org.greenstone.gsdl3;
    2021
    2122import org.greenstone.gsdl3.core.*;
     23import org.greenstone.gsdl3.util.GSXML;
    2224import org.w3c.dom.Element;
    2325import java.io.File;
     
    3032 *
    3133 * @author <a href="mailto:[email protected]">Katherine Don</a>
    32  * @version $Revision$
    3334 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a>
    3435 */
    3536
    36 public class SOAPServer
    37     implements ModuleInterface {
    38  
     37public class SOAPServerlocalsite
     38{
    3939    private String config_file_name = "SOAPServer.cfg";
    4040   
     
    4343 
    4444  /** The no-args constructor */
    45     public SOAPServer() {
     45    public SOAPServer@sitename@() {
    4646    // find out gsdl3home
    4747    URL url = ClassLoader.getSystemResource(config_file_name);
     
    5454        return;
    5555    }
    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";
    5757   
    5858    File site_file = new File(site_home);
     
    6666    }
    6767   
    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;
    7889    }
    7990
     
    92103    return null;
    93104    }
    94 
     105   
    95106}
    96107
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/Action.java

    r8832 r9874  
    5252    public String process(String xml_in) {
    5353       
    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());
    5761    return this.converter.getString(result);
    5862    }
     
    115119    }
    116120
     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    }
    117132}
    118133
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java

    r9007 r9874  
    209209        // Process the document structure retrieve message
    210210        Element ds_response_message = (Element) this.mr.process(ds_message);
    211        
     211        if (processErrorElements(ds_response_message, page_response)) {
     212        return result;
     213        }
     214
    212215        // get the info and print out
    213216        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     
    309312    doc_list.appendChild(doc_node);
    310313    Element dm_response_message = (Element) this.mr.process(dm_message);
     314    if (processErrorElements(dm_response_message, page_response)) {
     315        return result;
     316    }
    311317
    312318    String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     
    348354    System.err.println("request = "+converter.getString(dc_message));
    349355    Element dc_response_message = (Element) this.mr.process(dc_message);
     356    if (processErrorElements(dc_response_message, page_response)) {
     357        return result;
     358    }
     359
    350360    Element dc_response_doc_list = (Element) GSXML.getNodeByPath(dc_response_message, path);
    351361
     
    536546    HashMap params = GSXML.extractParams(cgi_param_list, false);
    537547   
    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);
    540553    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
    541554        System.err.println("DocumentAction: invalid service, not doing highlighting");
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java

    r8575 r9874  
    126126        horizontal_at_top = true;
    127127    }
    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) {
    129130        // 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";
    132133           
    133     }
     134    //}
    134135
    135136    // get the browse structure for the selected node
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java

    r9264 r9874  
    6060    String to = GSPath.appendLink(collection, service_name);
    6161   
    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   
    6997    // also get the format stuff now if there is some
    7098    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
    88144    HashSet metadata_names = new HashSet();
    89145    metadata_names.add("Title");
     
    98154        extractMetadataNames(format_elem, metadata_names);
    99155    }
    100 
    101     // do the query
    102     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     // paramList
    107     HashMap service_params = (HashMap)params.get("s1");
    108     if (service_params == null) { // no query
    109         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 query
    117         Element mr_query_response = (Element)this.mr.process(mr_query_message);
    118 
    119     //. check for errors
    120     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 response
    133         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 response
    141         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 elem
    145     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 found
    150     if (document_list == null) {
    151         return page_response;
    152     }
    153156   
    154157    // 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   
    165160    // do the metadata request on the filtered list
    166161    Element mr_metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     
    176171    mr_metadata_request.appendChild(dm_param_list);
    177172   
    178    
    179173    // add in the doc node list too
    180174    mr_metadata_request.appendChild(filtered_doc_list);
    181175
    182176    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   
    187184    if (query_result_document_list != null) {
    188185        page_response.appendChild(this.doc.importNode(query_result_document_list, true));
    189186    }
    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));
    192189    return page_response;
    193190    }
    194191
    195192    /** 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
    208199        return (Element)this.doc.importNode(orig_doc_list, true);
    209200    }
    210201   
    211     String hits_pp = (String)params.get("hitsPerPage");
     202    hits_pp = (String)params.get("hitsPerPage");
    212203    int hits = 20;
    213204    if (hits_pp != null && !hits_pp.equals("")) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r5403 r9874  
    101101    }
    102102    // 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    }
    104108    return coll_config_elem;
    105109
     
    116120        return null;
    117121    }
    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    }
    120127    return build_config_elem;
    121128    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r9433 r9874  
    3434import java.io.File;
    3535import java.util.HashMap;
     36import java.util.Iterator;
    3637
    3738/* ServiceCluster - a groups of services that are related in some way
     
    9192    }
    9293
     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    }
    93101    public void setClusterName(String name) {
    94102    this.cluster_name = name;   
     
    139147
    140148    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    }
    141153   
    142154    // get the appropriate service cluster element
     
    147159    return this.configure(sc);
    148160    }
    149  
     161    
    150162   
    151163    public boolean configure(Element service_cluster_info) {
     
    159171        }
    160172    }
    161 
     173   
    162174    // get the display info
    163175    Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
     
    528540    }
    529541   
    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();
    531549    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);
    532550    if (cluster_config_elem == null) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/Communicator.java

    r4035 r9874  
    4848    converter_ = new XMLConverter();
    4949    }
     50    public void cleanUp() {}
    5051
    5152    public void setLocalSiteName(String name) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java

    r4035 r9874  
    2626import java.net.MalformedURLException;
    2727import 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;
     34import org.apache.axis.client.Call;
     35import org.apache.axis.client.Service;
     36import org.apache.axis.message.SOAPBodyElement;
     37import javax.xml.namespace.QName;
    3438
    3539import org.w3c.dom.Node;
     
    5761    public SOAPCommunicator() {
    5862   
    59     call_ = new Call();
     63
    6064    // Set Encoding Style to standard SOAP encoding
    6165    //call_.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    6266    // set Encoding Style to use literal XML
    63     call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
     67    //call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
    6468    }
    6569       
    6670    public boolean configure(Element site_elem) {
    6771
     72   
    6873    String type = site_elem.getAttribute(GSXML.TYPE_ATT);
    6974    if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) {
     
    8186        return false;
    8287    }
    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    }
    86102    return true;
    87103    }
    88104
    89 
    90105    public Element process(Element message) {
    91 
     106   
    92107    NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
    93108    if (requests.getLength()==0) {
     
    95110        return null;
    96111    }
    97    
     112
    98113    // 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
    99114    // for now, use local_site_name_ as the flag.
     
    110125        }
    111126    }
     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    }
    112199    // else do nothing to the message, just pass it on
    113200   
     
    116203
    117204        // 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);
    122209                       
    123         Vector param_list = new Vector ();
    124         param_list.addElement (param);
    125         call_.setParams (param_list);
    126        
    127         //  Set the URL for the Web Service
    128         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_);
    129216       
    130217        // Invoke the Service
     
    167254    }
    168255    }
    169    
     256    */
    170257}
    171258
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/DefaultReceptionist.java

    r7825 r9874  
    2424   
    2525    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    }
    2632    ///ystem.out.println("add extra info, page request="+this.converter.getString(page_request));
    2733    // is a collection defined?
     
    6066        Element coll_about_response_message = this.mr.process(coll_about_message);
    6167        Element coll_about_response = (Element)GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
     68        if (coll_about_response == null) {
     69        return;
     70        }
    6271        coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
    6372        if (coll_description==null) { // may be a cluster
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r9276 r9874  
    9898    this.converter = new XMLConverter();
    9999    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    }
    104110    /** site_home must be set before configure called */
    105111    public void setSiteHome(String home) {
     
    133139    this.module_map = new HashMap();
    134140
    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) {
     143System.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);
    138149    if (local_site_name == null) {
    139150        System.err.println("MessageRouter configure error:no site name in config file");
     
    143154    }
    144155   
    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);
    146157    if (http_address == null) {
    147158        System.err.println("MessageRouter configure error: no http address  in config file");
     
    151162    }
    152163
    153     Element proxy = (Element)GSXML.getChildByTagName(config, "proxy");
     164    Element proxy = (Element)GSXML.getChildByTagName(config_elem, "proxy");
    154165    if (proxy != null) {
    155166        String host = proxy.getAttribute("host");
     
    180191                     
    181192    // 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);
    183194    configureServices(service_rack_list);
    184195   
    185196    // 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);   
    187198    configureClusters(cluster_list);
    188199
     
    191202
    192203    // 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);
    194205    configureSites(site_list);
    195206   
     
    603614                    continue;
    604615                }
    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();
    606622                }
    607623                if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     
    684700    File init_file = new File(GSFile.collectionInitFile(this.site_home, col_name));
    685701    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
    700718        c = new Collection();
    701719    }
     720   
    702721    c.setCollectionName(col_name);
    703722    c.setSiteHome(this.site_home);
     
    720739   
    721740    }
    722 
     741   
    723742    protected boolean activateSite(String site_name) {
    724743    System.out.println("MessageRouter:Activating site: "+site_name+".");
     
    732751        return false;
    733752    }
    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);
    737761    if (site_list ==null ) {
    738762        System.err.println("MessageRouter:activateSite, no sites found");
     
    789813
    790814        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
    793817        // also remove the xml bit from description list
    794818        if (type.equals(GSXML.COLLECTION_ELEM)) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/ModuleInterface.java

    r3502 r9874  
    5252   */
    5353    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();
    5461}   
    5562                                                                           
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java

    r8921 r9874  
    5050    }
    5151   
     52    public void cleanUp() {}
    5253    public void setParams(GSParams params) {
    5354    this.params = params;
     
    8182    }
    8283   
    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");
    8591    setUpBaseInterface(base_interface);
    86     setUpInterfaceOptions(config_doc);
     92    setUpInterfaceOptions(config_elem);
    8793
    8894    // 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);
    9096    NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM);
    9197
     
    109115    }
    110116
    111     this.language_list = (Element)GSXML.getChildByTagName(config_doc, "languageList");
     117    this.language_list = (Element)GSXML.getChildByTagName(config_elem, "languageList");
    112118    if (language_list == null) {
    113119        System.err.println("Receptionist: didn't find a language list in the config file!!");
     
    229235        base_interfaces.add(base_interface);
    230236        // 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");
    233244    }
    234245    return true;
    235246    }
    236247
    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");
    239250    if (option_list != null) {
    240251        System.err.println("found an option list");
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r9405 r9874  
    5252        return false;
    5353    }
    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");
    5761    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);
    6165    NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM);
    6266
     
    97101       
    98102    }
    99     Element lang_list = (Element)GSXML.getChildByTagName(config_doc, "languageList");
     103    Element lang_list = (Element)GSXML.getChildByTagName(config_elem, "languageList");
    100104    if (lang_list == null) {
    101105        System.err.println("TransformingReceptionist: didn't find a language list in the config file!!");
     
    157161    }
    158162    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    }
    159168
    160169    // look for the format element in the page response
     
    166175        // need to transform the format info
    167176        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);
    172182        ///ystem.err.println("new format elem="+this.converter.getPrettyString(new_format));
    173183       
    174184        // 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        }
    176190        ///ystem.out.println("the converted stylesheet is:");
    177191        ///ystem.out.println(this.converter.getPrettyString(style_doc.getDocumentElement()));
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java

    r8969 r9874  
    216216      GS3SQLSelect select = new GS3SQLSelect("build");
    217217      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()) {
    222221    System.out.println("Reading all keys");
    223222    do {
     
    238237    } while (results.next());
    239238      }
     239      statement.close();
    240240    }
    241241    catch (SQLException ex)
     
    479479   
    480480    // 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   
    496502    // Do tail of build output
    497503    Date startDate = this.lastBuildDate.getTime();
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/Create.java

    r8497 r9874  
    4848
    4949    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");
    5151    }
    5252
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AZListClassifier.java

    r8742 r9874  
    99import java.sql.ResultSet;
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112
    1213import org.xml.sax.XMLReader;
     
    189190    select.setWhere(where);
    190191
    191     connection.execute(select.toString());
    192192
    193193    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()) {
    196197    GS3SQLUpdate update = new GS3SQLUpdate("classifiers");
    197198    update.setWhere(where);
     
    206207
    207208    action = insert;
     209    classifyRef = -1;
    208210      }
    209211      action.addValue("ClassifyID", label);
     
    213215      action.addValue("NumLeafDocs", Integer.toString(noOfLeafDocs), GS3SQLField.INTEGER_TYPE);
    214216
    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()) {
    231226      return -1;
    232227    }
     
    234229    classifyRef = results.getInt("ClassifyRef");
    235230      }
    236       catch (SQLException sqlEx) {
    237     System.err.println(sqlEx);
     231     
     232      statement.close();
     233    }  catch (SQLException sqlEx) {
     234    System.err.println("AZListClassifier.writeSQLClassifyNode(): "+sqlEx);
    238235    return -1;
    239       }
    240     }
     236    }
     237 
    241238
    242239    return classifyRef;
     
    274271    }
    275272
     273    try {
     274    Statement statement = connection.createStatement();
     275   
    276276    List children;
    277277   
     
    292292        Iterator iterator = childDocs.iterator();
    293293    int childOrder = 1;
     294    //St
    294295    while (iterator.hasNext()) {
    295296      AZDocumentItem documentItem = (AZDocumentItem) iterator.next();
     
    301302      insert.addValue("DocOrder", Integer.toString(childOrder), GS3SQLField.INTEGER_TYPE);   
    302303
    303       connection.execute(insert.toString());
     304      statement.execute(insert.toString());
    304305
    305306      childOrder ++;
     
    310311    }
    311312
     313   
    312314    /*
    313315    else {
     
    318320      delete.setWhere(where);
    319321
    320       connection.execute(delete.toString());
     322      statement.execute(delete.toString());
    321323    }
    322324
     
    331333    }
    332334    */
     335    statement.close();
     336    } catch (SQLException e) {
     337    System.err.println("AZListClassifier.writeSQL(): "+e);
     338    return false;
     339    }
    333340
    334341    return true;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java

    r8742 r9874  
    77import java.sql.ResultSet;
    88import java.sql.SQLException;
     9import java.sql.Statement;
    910
    1011import org.greenstone.gsdl3.gs3build.doctypes.DocumentID;
     
    273274    GS3SQLInsert insert;
    274275
     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   
    275285    // Get own full id
    276286    String fullId = this.id.length() > 0 ? this.prefix+"."+this.id : this.prefix;
     
    283293    select.setWhere(where);
    284294
    285     connection.execute(select.toString());
    286295
    287296    // update or insert the classifier as required
    288297    try {
    289       ResultSet results = connection.getResultSet();
    290       if (results != null && results.first()) {
     298      ResultSet results = statement.executeQuery(select.toString());
     299      if (results.first()) {
    291300    GS3SQLUpdate update = new GS3SQLUpdate("classifiers");
    292301    update.setWhere(where);
     
    313322
    314323    action = insert;
     324    classifyRef = -1;
    315325      }
    316326      action.addValue("ClassifyID", fullId);
     
    331341      action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE);
    332342
    333       connection.execute(action.toString());
    334       classifyRef = -1;
     343      statement.execute(action.toString());
    335344    }
    336345    catch (SQLException sqlEx) {
    337346      if (action == null) {
    338     System.err.println(sqlEx);
     347    System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx);
    339348      }
    340349      else {
    341     System.err.println(sqlEx + " " + action.toString());
     350    System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx + " " + action.toString());
    342351      }
    343352      return false;
     
    347356    // insert action above)...
    348357    if (classifyRef == -1) {
    349       connection.execute(select.toString());
    350      
    351358      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;
    355363    }
    356364   
    357365    classifyRef = results.getInt("ClassifyRef");
     366   
    358367      }
    359368      catch (SQLException sqlEx) {
    360     System.err.println(sqlEx);
     369    System.err.println("AbstractHierarchyNode.writeSQL(): "+sqlEx);
    361370    return false;
    362371      }
     
    368377      GS3SQLDelete delete = new GS3SQLDelete("classdocuments");
    369378      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   
    374387    // post the child nodes...
    375388    Iterator iterator = this.childNodes.iterator();
     
    379392      if (!childNode.writeSQL(connection)) {
    380393      System.out.println("Failed to write " );
    381     return false;
     394      return false;
    382395      }
    383396    }
     
    394407      insert.addValue("DocID", docId.toString());
    395408      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      }
    399415      order ++;
    400416    }
     417    // close the statment
     418    try {
     419    statement.close();
     420    } catch (SQLException e) {
     421    System.err.println("AbstractHierarchyNode.writeSQL(): "+e);
     422    }
     423
    401424    return true;
    402425  }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java

    r8773 r9874  
    1414{
    1515
    16     public GS3SQLConnection(java.sql.Connection connection)
     16    public GS3SQLConnection(java.sql.Connection connection, String database)
    1717    {
    18     super(connection);
     18    super(connection, database);
    1919    }
    2020   
     
    2525  }
    2626   
    27 
     27    public GS3SQLConnection cloneConnection() {
     28    GS3SQLConnection conn = GS3SQLConnectionFactory.getGS3SQLConnection(this.database);
     29    return conn;
     30    }
    2831  /**
    2932   *  Initialise a collection for use.
     
    6265     
    6366    try {
    64       statement = this.connection.createStatement();
     67      Statement statement = this.connection.createStatement();
    6568
    6669      // create build history table
     
    224227      statement.execute(classData.toString());
    225228
     229      statement.close();
    226230      //
    227231      // END OF GSDL TABLES
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java

    r8745 r9874  
    3232        return null;
    3333    }
    34     return new SQLConnection(c);
     34    return new SQLConnection(c, database);
    3535    }
    3636
     
    4242        return null;
    4343    }
    44     return new GS3SQLConnection(c);
     44    return new GS3SQLConnection(c, database);
    4545    }
    4646
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java

    r8745 r9874  
    1010{
    1111    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)
    1615    {
    1716    this.connection = connection;
     17    this.database = database;
    1818    }
    1919   
     
    2121    if (this.connection!=null) {
    2222        try {
    23         this.connection.close();
     23        this.connection.close();       
    2424        } catch (Exception e) {}
    25        
    26         this.connection = null;
    27     }
     25    }   
     26    this.connection = null;   
    2827    }
    2928   
    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();
    4131    }
    4232   
    43     public Statement createStatement()
     33    public Statement createStatement() throws SQLException
    4434    {
    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();
    6636    }
    6737   
    6838    public boolean connectToDatabase(String database) {
     39    if (this.connection != null) {
     40        try {
     41        this.connection.close();
     42        } catch (Exception e) {}
     43    }
    6944    this.connection = GS3SQLConnectionFactory.getConnection(database);
    7045    if (this.connection == null) {
    7146        return false;
    7247    }
     48    this.database = database;
    7349    return true;
    7450    }
     
    7652    public boolean dropDatabase(String database) {
    7753    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();
    8057    }
    8158    catch (SQLException ex){
     
    9067    try {
    9168        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();
    9472    } catch (Exception e) {
    9573        System.err.println(e);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java

    r8742 r9874  
    99
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112import java.sql.ResultSet;
    1213import java.sql.Timestamp;
     
    190191    // Query for documents using the same file...
    191192    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 
    197193    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        }
    216216        }
    217       }
    218217    }
    219       }
     218    statement.close();
    220219    }
    221220    catch (java.sql.SQLException sqlEx) {
    222       System.err.println(sqlEx);
     221      System.err.println("AbstractDocument.getDuplicateID(): "+sqlEx);
    223222    }
    224223
     
    447446   *  Obtain a document from the SQL database
    448447   */
    449   public static AbstractDocument readSQL(GS3SQLConnection connection, ResultSet sqlResult)
     448    public static AbstractDocument readSQL(GS3SQLConnection connection, ResultSet sqlResult)
    450449  { try {
    451450      DocumentID id = new DocumentID(sqlResult.getString("DocID"));
     
    454453      // Use a factory method to create the correct subtype...
    455454      AbstractDocument document = DocumentFactory.createDocument(type, id);
    456 
    457455      // Append the document date information
    458456      document.indexDate    = sqlResult.getTimestamp("IndexedDate");
     
    473471    }
    474472    catch (SQLException sqlEx) {
    475       System.out.println("Failure to load document: " + sqlEx);
     473      System.err.println("AbstractDocument.readSQL(): Failure to load document: " + sqlEx);
    476474    }
    477475    return null;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentFactory.java

    r8742 r9874  
    22
    33import java.sql.SQLException;
     4import java.sql.Statement;
    45import java.sql.ResultSet;
    56import java.net.URL;
     
    6162  {
    6263    String query = "SELECT * FROM document WHERE DocID=\""+id.toString()+"\";";
    63     connection.execute(query);
    64 
    6564    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;
    7074    }
    7175    catch (SQLException sqlEx) {
    72       System.err.println(sqlEx);
     76      System.err.println("AbstractDocument.readSQLDocument():"+sqlEx);
    7377    }
    7478    return null;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java

    r8861 r9874  
    1313
    1414import java.sql.SQLException;
     15import java.sql.Statement;
    1516import java.sql.ResultSet;
    1617
     
    6869    select.setWhere(where);
    6970
    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();
    8585    do {
    8686      int fileGroupRef = results.getInt("FileGroupRef");
     
    9090    while (results.next());
    9191    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   
    9795    results.first();
    9896    do {
     
    10098      reply.add(docId);
    10199    } 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   
    107106    return reply;
    108107  }
     
    173172  }
    174173
    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    }
    185185     
    186186      // get a list of group ids first and turn it into a query on filegroups
     
    207207      // structures...recreating new filegroup queries as necessary
    208208      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;
    214214    }
    215215   
     
    256256     
    257257      // 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;
    264263      }
    265264
     
    268267    reply.add(results.getString("DocID"));
    269268      } while (results.next());
    270 
     269     
     270      statement.close();
    271271      return reply;
    272272    }
    273273    catch (SQLException ex) {
    274       System.err.println(ex);
     274      System.err.println("DocumentList.findDocumentIdsUsingFileQuery()"+ ex);
    275275    }
    276276    return null;
     
    454454    select.addField("*");
    455455   
    456     ResultSet documents;
    457456    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       return null;
     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;
    472471    }
    473472
     
    487486{
    488487  private boolean hasNext;
     488  private Statement statement;
    489489  private ResultSet resultSet;
    490490  private GS3SQLConnection connection;
     
    498498
    499499    try {
    500       connection.execute(select.toString());
    501       this.resultSet = connection.getResultSet();
     500    this.statement = connection.createStatement();
     501      this.resultSet = statement.executeQuery(select.toString());
    502502      this.hasNext = this.resultSet.first();
    503503    } catch (SQLException ex) {
     504      System.err.println("DocumentListIterator(): "+ex);
    504505      this.hasNext = false;
    505506    }
     
    520521
    521522      if (!this.hasNext) {
    522     this.resultSet.close(); // be a good citizen & close used result sets
     523      this.statement.close(); // be a good citizen & close used statement
    523524      }
    524525    } catch (SQLException ex) {
     526    System.err.println("DocumentList.iterator.next(): "+ex);
    525527      this.hasNext = false;
    526528    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java

    r8742 r9874  
    1919    update.addDate("IndexedDate", new java.sql.Timestamp(touchTime));
    2020    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    }
    2229    System.out.println(update.toString());
    2330    return true;
     
    3946    select.addField("*");
    4047    select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString())));
    41     connection.execute(select.toString());
    4248   
    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");
    4853      insert.addValue("DocID", document.getID().toString());
    4954      insert.addValue("DocType", document.getDocumentType());
     
    5358      insert.addDate("ModifiedDate", new java.sql.Timestamp(document.getModifiedDatestamp()));
    5459
    55       connection.execute(insert.toString());
     60      statement.execute(insert.toString());
    5661    }
    5762    else {
     
    6166      //      connection.execute(update.toString());
    6267    }
     68    statement.close();
    6369      }
    64     } catch (Exception ex) {
    65     System.out.println(ex);
     70    } catch (SQLException ex) {
     71    System.out.println("DocumentSQLWriter.writeDocument() Error:"+ex);
    6672    }
    6773    //    output.println(tag);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/HTMLDocument.java

    r8929 r9874  
    279279    public Document getDOMDocument()
    280280    {   
    281     if (this.domDocument == null) {
     281      if (this.domDocument == null) {
    282282      URL     url =(URL) this.fileSet.getFile(0).getLocation();
    283283      this.loadDocument(url);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGPPIndexer.java

    r9006 r9874  
    175175    {
    176176    if (this.pass == 0) {
    177         document.removeAllMetadata("gsdl3", "mgppseqno");
     177        document.removeAllMetadata("gsdl3", "mgseqno");
    178178    }
    179179
     
    188188    String docText = null;
    189189   
    190     int startSeqNo = this.sectionSeqNo;
    191     this.sectionSeqNo ++;
    192    
     190    //int startSeqNo = this.sectionSeqNo;
     191    //this.sectionSeqNo ++;
     192    int startSeqNo = this.documentSeqNo;
     193
    193194    Document domDocument = document.getDOMDocument();
    194195    if (domDocument != null) {
     
    288289
    289290    if (this.pass == 0) {   
    290         document.addDocumentMetadata("gsdl3", "mgppseqno", "dtx."+Integer.toString(startSeqNo));
    291     }
    292     this.documentSeqNo += 1;
     291        document.addDocumentMetadata("gsdl3", "mgseqno", "dtx."+Integer.toString(startSeqNo));
     292    }
     293    this.documentSeqNo++;
    293294   
    294295//  try {
     
    317318    this.firstDocument = true;
    318319    this.documentSeqNo = 1;
    319    
     320    this.sectionSeqNo = 1;
     321
    320322    this.mgppPasses = new MGPPPassesWrapper();
    321323    this.indexBuffer = new StringBuffer();
     
    430432        System.out.println("Compressed dictionary successfully written");
    431433        } 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);
    435436        return false;
    436437        }
     
    444445        } else {
    445446        System.err.println("Unable to build the perfect hash");
    446         index.setError(true);
     447        //index.setError(true);
    447448        return false;
    448449        }
     
    456457        } else {
    457458        System.err.println("Unable to create weights file");
    458         index.setError(true);
     459        //index.setError(true);
    459460        return false;
    460461        }
     
    466467        } else {
    467468        System.out.println("Unable to create inverted dictionary file");
    468         index.setError(true);
     469        //index.setError(true);
    469470        return false;
    470471        }
     
    476477        } else {
    477478        System.out.println("Unable to create stemmed index 1");
    478         index.setError(true);
     479        //index.setError(true);
    479480        return false;
    480481        }
     
    485486        } else {
    486487        System.out.println("Unable to create stemmed index 2");
    487         index.setError(true);
     488        //index.setError(true);
    488489        return false;
    489490        }
     
    493494        } else {
    494495        System.out.println("Unable to create stemmed index 3");
    495         index.setError(true);
     496        //index.setError(true);
    496497        return false;
    497498        }
     
    553554    Element default_index = doc.createElement("defaultIndex");
    554555    default_index.setAttribute(GSXML.NAME_ATT, def_index);
     556
    555557    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
    557560    Element index_stem = doc.createElement("indexStem");
    558561    index_stem.setAttribute(GSXML.NAME_ATT, "index");
     
    561564    Element retrieve_service_elem = doc.createElement(GSXML.SERVICE_CLASS_ELEM);
    562565    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
    564578    service_rack_list.appendChild(search_service_elem);
    565579    service_rack_list.appendChild(retrieve_service_elem);
     
    568582    search_service_elem.appendChild(index_list);
    569583    search_service_elem.appendChild(default_index);
     584    search_service_elem.appendChild(level_list);
    570585    search_service_elem.appendChild(default_level);
     586search_service_elem.appendChild(field_list); // do we need this??
    571587    search_service_elem.appendChild(base_index_name);
    572588    search_service_elem.appendChild(index_stem);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java

    r8742 r9874  
    88
    99import java.sql.SQLException;
     10import java.sql.Statement;
    1011import java.sql.ResultSet;
    1112
     
    275276        } else {
    276277        // TODO: raise an error!
    277         System.out.println("Error: METSDescriiptive: unrecognised tag "+childName);
     278        System.out.println("Error: METSDescriptive: unrecognised tag "+childName);
    278279        }
    279280    }
     
    375376    select.setWhere(where);
    376377   
    377     connection.execute(select.toString());
    378    
    379378    try {
     379        Statement statement = connection.createStatement();
     380        ResultSet resultSet = statement.executeQuery(select.toString());
    380381        GS3SQLAction action;
    381382       
    382         ResultSet resultSet = connection.getResultSet();
    383        
    384         if (resultSet != null &&
    385         resultSet.first()) {
     383        if (resultSet.first()) {
    386384        // the node already exists - no need to do anything as such
    387385        GS3SQLUpdate update = new GS3SQLUpdate("metadata");
     
    389387        action = update;
    390388        }
    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        }
    401396       
    402397        // always set the group identifier
     
    404399       
    405400        // 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();
    421414    }
    422415    catch (SQLException sql){
    423         System.out.println(sql);
     416        System.err.println("METSDescriptive.writeSQL(): "+sql);
     417    }
     418    if (sqlId == -1) {
     419        return false;
    424420    }
    425421   
     
    471467        select.setWhere(where);
    472468       
    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()) {
    479474        do {
    480475            METSNamespace namespace = METSNamespace.readSQL(connection, namespaceSet);
     
    483478            }
    484479            else {
    485             System.out.println("Null namespace output");
     480            System.err.println("Null namespace output");
    486481            }
    487482        }
    488483        while (namespaceSet.next());
    489484        }
    490        
     485        statement.close();
    491486        return descriptive;
    492487    }
    493488    catch (SQLException sqlEx){
    494         System.out.println(sqlEx);
     489        System.err.println("METSDescriptive.readSQL(): "+sqlEx);
    495490        System.exit(1);
    496491    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java

    r8742 r9874  
    99
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112import java.sql.ResultSet;
    1213
     
    236237    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
    237238    select.setWhere(new GS3SQLWhere(whereItem));
    238     connection.execute(select.toString());
    239    
     239
    240240    // start going through the matching metadata blocks
    241241    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();
    253256    }
    254257    catch (SQLException sqlEx) {
    255         System.out.println(sqlEx);
     258        System.err.println("METSDescriptiveSet.readSQL(): "+sqlEx);
    256259        System.exit(1);
    257260    }
    258261   
     262   
    259263    return set;
    260264    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java

    r8742 r9874  
    1010
    1111import java.sql.SQLException;
     12import java.sql.Statement;
    1213import java.sql.ResultSet;
    1314
     
    475476    select.setWhere(where);
    476477   
    477     connection.execute(select.toString());
     478    Statement statement = null;
     479    ResultSet resultSet = null;
    478480   
    479481    // Do the actual writing
    480482    GS3SQLAction action;
    481483   
    482     ResultSet resultSet = connection.getResultSet();
    483484    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()) {
    487488       
    488489        GS3SQLInsert insert = new GS3SQLInsert("divisions");
     
    499500        GS3SQLUpdate update = new GS3SQLUpdate("divisions");
    500501        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));
    503503        update.setWhere(updateWhere);
    504504        action = update;
     
    515515    action.addValue("UserLabel", this.userLabel);
    516516   
    517     if (!connection.execute(action.toString())){
     517    try {
     518        statement.execute(action.toString());
     519    } catch (SQLException e) {
     520        System.err.println("METSDivision.writeSQL(): "+e);
    518521        return false;
    519522    }
    520523   
    521524    // if doing a fresh item, get the new structure reference...
    522     if (resultSet == null){
     525    if (sqlRef == -1){
    523526        // get the new structure reference
    524         connection.execute(select.toString());
    525        
    526         // get the sql reference for the division
    527527        try {
    528528        // 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");
    532532        }
    533         resultSet.first();
    534         sqlRef = resultSet.getInt("DivisionRef");
    535         resultSet.close();
    536         resultSet = null;
    537533        }
    538534        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);
    540536        return false;
    541537        }
    542538    }
    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     }
    552539   
    553540    // 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    }
    594587    // write out any children in turn
    595588    Iterator groups = this.children.values().iterator();
     
    633626        select.setWhere(where);
    634627
    635         connection.execute(select.toString());
     628        Statement statement = connection.createStatement();
     629        ResultSet childSet = statement.executeQuery(select.toString());
    636630     
    637631        // circulate through to obtain further children
    638         ResultSet childSet = connection.getResultSet();
    639632        if (childSet.first())
    640633        {
     
    645638            while (childSet.next());
    646639        }
    647 
    648640        select = new GS3SQLSelect("divisionfilerefs");
    649641        select.addField("*");
     
    652644        select.setWhere(where);
    653645
    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()){
    658649        do {
    659650            String reference = fileSet.getString("FileID");
     
    662653        while (fileSet.next()); 
    663654        }
    664 
     655       
    665656        select = new GS3SQLSelect("divisionmetarefs");
    666657        select.addField("*");
     
    669660        select.setWhere(where);
    670661
    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()){
    675665        do {
    676666            String reference = metaSet.getString("MetaID");
     
    680670        }
    681671       
     672        statement.close();
    682673        return division;
    683674    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java

    r8742 r9874  
    1111import java.sql.ResultSet;
    1212import java.sql.SQLException;
     13import java.sql.Statement;
    1314
    1415import org.w3c.dom.Document;
     
    201202    where.add(whereItem);
    202203    select.setWhere(where);
    203     connection.execute(select.toString());
     204
     205    Statement statement = null;
    204206   
    205207    // if not, then make an insert action
    206208    try {
    207         ResultSet results = connection.getResultSet();
    208         if (results == null ||
    209         !results.first()){
     209        statement = connection.createStatement();
     210        ResultSet results = statement.executeQuery(select.toString());
     211        if (!results.first()){
    210212        GS3SQLInsert insert = new GS3SQLInsert("files");
    211213       
     
    223225    }
    224226    catch (SQLException ex){
    225         System.err.println(ex);
     227        System.err.println("METSFile.writeSQL(): "+ex);
    226228        return false;
    227229    }
     
    230232    action.addValue("MIMEType", this.MIMEType);
    231233   
    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;
    233243    }
    234244   
     
    248258    }
    249259    catch (SQLException ex){
    250         System.out.println(ex);
     260        System.out.println("METSFile.readSQL(): "+ex);
    251261    }
    252262    catch (java.net.MalformedURLException urlEx){
    253         System.out.println(urlEx);
     263        System.out.println("METSFile.readSQL(): "+urlEx);
    254264    }
    255265    return null;
     
    309319    } catch (java.net.MalformedURLException ex) {
    310320        // TODO: raise error
    311         System.err.println(ex);
     321        System.err.println("METSFile.parse_flocateXML(): "+ex);
    312322    }
    313323    return thisFilePos;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java

    r8742 r9874  
    88
    99import java.sql.SQLException;
     10import java.sql.Statement;
    1011import java.sql.ResultSet;
    1112
     
    271272    {
    272273    int sqlId = -1;
    273    
    274274    // check if this node is in the database already
    275275    GS3SQLSelect select = new GS3SQLSelect("filegroups");
     
    281281    select.setWhere(where);
    282282   
    283     connection.execute(select.toString());
    284    
    285     ResultSet selectResult = connection.getResultSet();
     283    ResultSet results = null;
     284    Statement statement = null;
    286285   
    287286    try {
    288         if (selectResult == null ||
    289         !selectResult.first()) {
     287        statement = connection.createStatement();
     288        results = statement.executeQuery(select.toString());
     289        if (!results.first()) {
    290290        GS3SQLInsert insert = new GS3SQLInsert("filegroups");
    291291       
     
    295295        insert.addValue("ParentType", parentIsSection ? SECTION_PARENT : GROUP_PARENT);
    296296       
    297         if (!connection.execute(insert.toString())) {
    298             return false;
    299         }
     297        statement.execute(insert.toString());
    300298        }
    301299        else {
     
    304302    }
    305303    catch (SQLException ex){
    306         System.err.println(ex);
     304        System.err.println("METSFileGroup.writeSQL(): "+ex);
    307305        return false;
    308306    }
    309307   
    310308    // get the filegroup reference now
    311     connection.execute(select.toString());
    312    
    313309    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();
    316315        return false;
    317316        }
    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);
    323320        return false;
    324321    }
    325    
    326322    // iterate over the child groups
    327323    Iterator childIter = childGroups.iterator();
     
    330326       
    331327        if (!fileGroup.writeSQL(document, Integer.toString(sqlId), false, connection)){
     328        System.err.println("METSFileGroup.writeSQL(): Couldn't write FileGroup");
    332329        return false;
    333330        }
     
    337334    childIter = children.iterator();
    338335    while (childIter.hasNext()){
    339         METSFile file = (METSFile) childIter.next();
    340        
     336        METSFile file = (METSFile) childIter.next();       
    341337        if (!file.writeSQL(sqlId, connection)){
     338        System.err.println("METSFileGroup.writeSQL(): Couldn't write File");
    342339        return false;
    343340        }
     
    371368        select.setWhere(where);
    372369       
    373         connection.execute(select.toString());
     370        Statement statement = connection.createStatement();
    374371       
    375372        // parse through the child groups
    376         ResultSet childSet = connection.getResultSet();
     373        ResultSet childSet = statement.executeQuery(select.toString());
    377374        if (childSet.first()) {
    378375        do {
     
    384381        while (childSet.next());
    385382        }
    386        
    387383        // now scan for file members
    388384        select = new GS3SQLSelect("files");
    389385        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);
    392387        where = new GS3SQLWhere(whereItem);
    393388        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()) {
    398391        do {
    399392            METSFile file = METSFile.readSQL(connection, childFileSet);
     
    404397        while (childFileSet.next());
    405398        }
    406        
     399        statement.close();
    407400        return group;
    408401    }
    409402    catch (SQLException sqlEx){
    410         System.out.println(sqlEx);
     403        System.err.println("METSFileGroup.readSQL(): "+sqlEx);
    411404        System.exit(1);
    412405    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java

    r8742 r9874  
    1616
    1717import java.sql.SQLException;
     18import java.sql.Statement;
    1819import java.sql.ResultSet;
    1920
     
    232233        insert.addValue("FileSecID", "test"); // TODO: remove magic string
    233234       
    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);
    235241        return false;
    236242        }
     
    246252       
    247253        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();
    255261        }
    256262        catch (SQLException ex){
    257         System.out.println(ex);
     263        System.out.println("METSFileSet.writeSQL(): "+ex);
    258264        return false;
    259265        }
    260266    }
    261267   
     268    if (this.reference == null) {
     269        return false;
     270    }
    262271    // write out the children
    263272    while (groups.hasNext()){
     
    281290    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
    282291    select.setWhere(new GS3SQLWhere(whereItem));
    283     connection.execute(select.toString());
     292
     293    Statement statement = null;
    284294   
    285295    // Get the identifier for this file set, etc.
    286     ResultSet sections = connection.getResultSet();
    287     int fileSetRef;
     296    int fileSetRef = -1;
    288297    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       
    292308    }
    293309    catch (SQLException ex){
    294         System.out.println(ex);
     310        System.err.println("METSFileSet.readSQL() "+ex);
    295311        return null;
    296312    }
    297    
    298313    // Get child file groups
    299314    select = new GS3SQLSelect("filegroups");
     
    307322    where.add(whereItem);
    308323    select.setWhere(where);
    309     connection.execute(select.toString());
    310    
    311324    // start going through the matching file groups
    312325    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();
    321336    }
    322337    catch (SQLException sqlEx) {
    323         System.out.println(sqlEx);
     338        System.out.println("METSFileSet.readSQL(): "+sqlEx);
    324339        System.exit(1);
    325340    }
    326    
    327341    return set;
    328342    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSNamespace.java

    r8742 r9874  
    66import java.util.Iterator;
    77import java.sql.SQLException;
     8import java.sql.Statement;
    89import java.sql.ResultSet;
    910
     
    150151
    151152    // 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    }
    154161    // then get the namespace reference number if needsbe...
    155162    if (this.id == null) {
     
    161168        where.add(where);
    162169        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();
    168175        }
    169176        catch (SQLException sqlex){
    170177        this.id = null;
    171         System.err.println(sqlex);
     178        System.err.println("METSNamespace.writeSQL(): "+sqlex);
    172179        return false;
    173180        }
     
    201208        select.setWhere(where);
    202209
    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()) {
    207213        do {
    208214            String label = valuesSet.getString("Label");
     
    213219        while (valuesSet.next());
    214220        }
    215 
     221        statement.close();
    216222        return namespace;
    217223    }
    218224    catch (java.net.MalformedURLException urlEx){
    219         System.out.println(urlEx);
     225        System.err.println("METSNamespace.readSQL(): "+urlEx);
    220226    }
    221227    catch (SQLException sqlEx){
    222         System.out.println(sqlEx);
     228        System.err.println("METSNamespace.readSQL(): "+sqlEx);
    223229    }   
    224230    return null;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructure.java

    r8742 r9874  
    1010
    1111import java.sql.SQLException;
     12import java.sql.Statement;
    1213import java.sql.ResultSet;
    1314
     
    180181    {
    181182    int sqlRef = -1;
    182     ResultSet results;
    183 
     183    ResultSet results = null;
     184    Statement statement = null;
     185   
    184186    // Prepare query to see if this structure has already been written
    185187    GS3SQLSelect select = new GS3SQLSelect("structure");
     
    190192    where.add(item);
    191193    select.setWhere(where);
    192 
     194   
    193195    // attempt to execute the query & get the current structure's reference
    194196    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()){
    199200        sqlRef = results.getInt("structureRef");
    200201        }
    201         else {
    202         results = null;
    203         }
    204        
    205         if (results != null) {
    206         results.close();
    207         }
    208202    }
    209203    catch (SQLException sqlEx) {
    210         System.err.print(sqlEx);
     204        System.err.print("METSStructure.writeSQL(): "+sqlEx);
    211205        return false;
    212206    }
    213207   
    214208    // insert a new structure if it wasn't there previously
    215     if (results == null) {
     209    if (sqlRef == -1) {
    216210        GS3SQLInsert insert = new GS3SQLInsert("structure");
    217211        insert.addValue("DocID", document.getID().toString());
     
    220214        insert.addValue("Label", this.label);
    221215       
    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);
    223226        return false;
    224227        }
    225228       
    226         // get the new structure reference by re-running the original select object
    227         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         }
    238229    }
    239230    else {
     
    244235        update.addValue("Label", this.label);
    245236       
    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    }
    249251    // write out the child groups (Divisions) now...   
    250252    Iterator groups = this.children.values().iterator();
     
    296298        select.setWhere(where);
    297299
    298         connection.execute(select.toString());
     300        Statement statement = connection.createStatement();
     301        ResultSet divisionSet = statement.executeQuery(select.toString());
    299302
    300303        // parse through the divisions
    301         ResultSet divisionSet = connection.getResultSet();
    302         if (divisionSet != null && divisionSet.first()) {
     304        if (divisionSet.first()) {
    303305        do {
    304306            METSDivision division = METSDivision.readSQL(connection, divisionSet);
     
    309311        while (divisionSet.next());
    310312        }
    311 
     313        statement.close();
    312314        return structure;
    313315    }
    314     catch (SQLException sqlEx)
    315         { System.out.println(sqlEx + " " + select.toString());
     316    catch (SQLException sqlEx) {
     317        System.err.println("METSStructure.readSQL(): "+ sqlEx + " " + select.toString());
    316318        System.exit(1);
    317         }
     319    }
    318320    return null;
    319321    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java

    r8742 r9874  
    1010
    1111import java.sql.SQLException;
     12import java.sql.Statement;
    1213import java.sql.ResultSet;
    1314
     
    157158    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
    158159    select.setWhere(new GS3SQLWhere(whereItem));
    159     connection.execute(select.toString());
    160 
     160   
    161161    // start going through the matching metadata blocks
    162162    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();
    171174    }
    172175    catch (SQLException sqlEx) {
    173         System.out.println(sqlEx);
     176        System.err.println("METSStructureSet.readSQL(): "+sqlEx);
    174177        System.exit(1);
    175178    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/SimpleNamespace.java

    r8742 r9874  
    99
    1010import java.sql.SQLException;
     11import java.sql.Statement;
    1112import java.sql.ResultSet;
    1213
     
    281282    }
    282283   
     284    Statement statement = null;
     285    ResultSet results = null;
    283286    try {
     287        statement = connection.createStatement();
    284288        if (this.id == null) {
    285289        GS3SQLSelect select = new GS3SQLSelect("namespaces");
    286290        select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("MetadataRef", "=", Integer.toString(parentId), GS3SQLField.INTEGER_TYPE)));
    287291        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        }
    293299        }
    294300        else {
     
    300306        GS3SQLWhere where = new GS3SQLWhere(new GS3SQLWhereItem("NamespaceRef", "=", sqlId, GS3SQLField.INTEGER_TYPE));
    301307        delete.setWhere(where);
    302         connection.execute(delete.toString());
     308        statement.execute(delete.toString());
    303309       
    304310        // write out the metadata for this namespace
     
    316322            insert.addValue("Label", thisKey);
    317323            insert.addValue("Value", value);
    318             connection.execute(insert.toString());
    319         }
    320         }
     324            statement.execute(insert.toString());
     325        }
     326        }
     327        statement.close();
    321328    }
    322329    catch (SQLException sql) {
    323         System.out.println(sql);
     330        System.out.println("SimpleNamespace.writeSQL(): "+sql);
    324331    }
    325332    return true;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java

    r8869 r9874  
    1212public class NotifierManager {
    1313
    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;
    1621   
    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);
    3029        try {
     30        Statement statement = collManager.getDatabase().createStatement();
    3131            // detect all new documents. A document is new if and only if
    3232            // 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?
    4344        } catch (SQLException e) {
    44             // TODO Auto-generated catch block
    45             e.printStackTrace();
     45        // TODO Auto-generated catch block
     46        e.printStackTrace();
    4647        }
    47     }
    48 
     48    }
     49   
    4950    /**
    5051     * @param collName
     
    5859     * @throws SQLException
    5960     */
    60     private void notify(String collName, String hostURL, String notifyHost, ResultSet results, GS3SQLConnection database, Date date, String eventType) {
    61         try {
    62             System.out.println("notifyHost is " + notifyHost);
    63             URL url = new URL("http://" + notifyHost + "/alerting/service");
    64             System.out.println("trying to send to " + url);
    65            
    66             while(results.next()) {
    67                 System.out.println(eventType + ": " + results.getString("DocID"));
     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"));
    6869               
    6970                String documentID = results.getString("DocID");
    7071               
    71                 try {
     72        try {
    7273                    HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // TODO what about proxies?
    7374                    conn.setUseCaches(false);
     
    112113                    e1.printStackTrace();
    113114                }
    114             }
    115         } catch (SQLException e) {
    116             // TODO Auto-generated catch block
    117             e.printStackTrace();
    118         } catch (MalformedURLException e) {
     115        }
     116    } catch (SQLException e) {
     117        // TODO Auto-generated catch block
     118        e.printStackTrace();
     119    } catch (MalformedURLException e) {
    119120            // TODO Auto-generated catch block
    120121            e.printStackTrace();
    121122        }
    122     }
     123    }
    123124
    124125    /**
     
    129130    private String getDocumentTitle(String documentID, GS3SQLConnection database) {
    130131        System.out.println("getting title for document " + documentID + " from database");
    131         Statement statement = database.createStatement();
    132132
    133         ResultSet results;
    134133        try {
     134        Statement statement = database.createStatement();
    135135            String sqlString = "SELECT mdvalues.value " +
    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             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()) {
    147147                String title = results.getString("value");
    148148                System.out.println("title is " + title);
    149149                return title;
    150150            }
     151        statement.close();
    151152        } catch (SQLException e) {
    152153            e.printStackTrace();
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/HTMLTidy.java

    r8710 r9874  
    9393        handler.setContentHandler(this);
    9494        handler.setProperty("http://xml.org/sax/properties/lexical-handler", commentHandler);
    95         handler.parse(file.toString());
     95        handler.parse(file.toURI().toString());
    9696    }
    9797    catch (java.io.IOException io)
    9898        {
     99        System.out.println(io);
    99100        }
    100101    catch (org.xml.sax.SAXException saxEx)
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java

    r9288 r9874  
    2323// Greenstone classes
    2424//import org.greenstone.gdbm.*;
     25import org.greenstone.gsdl3.core.GSException;
    2526import org.greenstone.gsdl3.util.GSXML;
    2627import org.greenstone.gsdl3.util.GSPath;
     
    165166    Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    166167    if (param_list == null) {
    167         System.err.println("AbstractDocumentRetrieve, DocumentMetadataRetrieve Error: missing paramList.\n");
    168         return result;  // Return the empty result
     168        GSXML.addError(this.doc, result, "DocumentMetadataRetrieve: missing "+ GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX);
     169        return result; 
    169170    }
    170171
     
    190191    }
    191192   
    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
    195199    // Get the documents
    196200    Element request_node_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    197201    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);
    199203        return result;
    200204    }
    201205   
    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   
    203220    for (int i = 0; i < request_nodes.getLength(); i++) {
    204221        Element request_node = (Element) request_nodes.item(i);
    205222        String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
    206223       
    207         // Add the document to the results list
    208         Element new_node = (Element)this.doc.importNode(request_node, false);
    209         node_list.appendChild(new_node);
    210 
    211224        if (external_id) {
    212225        // can we have .pr etc extensions with external ids?
     
    219232        continue;
    220233        }
    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        }
    224244    }
    225245   
     
    240260
    241261    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     }
    247262
    248263    // Get the parameters of the request
    249264    Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    250265    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
    254288    Element extid_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTID_PARAM);
    255289    boolean external_id = false;
     
    308342    if (want_descendants)
    309343        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);
    325348        if (external_id) {
    326349        doc_id = translateExternalId(doc_id);
     
    433456    }
    434457
    435     // Get the parameters of the request - no parameters at this stage
     458    // Get the parameters of the request
    436459    Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    437460    Element extid_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTID_PARAM);
     
    473496        continue;
    474497        }
    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        }
    478506    }
    479507    return result;
     
    594622    }
    595623
    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    }
    598629   
    599630    /** 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
    602637    /** returns the document type of the doc that the specified node
    603638    belongs to. should be one of
     
    605640    GSXML.DOC_TYPE_PAGED,
    606641    GSXML.DOC_TYPE_HIERARCHY
     642    default implementation: return DOC_TYPE_SIMPLE
    607643    */
    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    }
    616666
    617667    /** get the metadata for the doc node doc_id
     
    621671    abstract protected Element getMetadataList(String doc_id,
    622672                           boolean all_metadata,
    623                            ArrayList metadata_names);
     673                           ArrayList metadata_names) throws GSException;
    624674    /** returns the content of a node
    625      * shoudl return a nodeContent element:
     675     * should return a nodeContent element:
    626676     * <nodeContent>text content or other elements</nodeContent>
     677     * can return
    627678     */
    628     abstract protected Element getNodeContent(String doc_id);
     679    abstract protected Element getNodeContent(String doc_id) throws GSException;
    629680
    630681    /** returns the structural information asked for.
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java

    r9000 r9874  
    2020
    2121// Greenstone classes
    22 import org.greenstone.gdbm.*;
     22import org.greenstone.gsdl3.core.GSException;
    2323import org.greenstone.gsdl3.util.GSXML;
    2424import org.greenstone.gsdl3.util.GSFile;
     
    2727import org.greenstone.gsdl3.util.GS2MacroResolver;
    2828import org.greenstone.gsdl3.util.GSConstants;
    29 
     29import org.greenstone.gsdl3.util.GDBMWrapper;
     30import org.greenstone.gsdl3.util.DBInfo;
    3031// XML classes
    3132import org.w3c.dom.Document;
     
    6667    }
    6768
    68 
     69    public void cleanUp() {
     70    super.cleanUp();
     71    this.gdbm_src.closeDatabase();
     72    }
    6973    /** configure this service */
    7074    public boolean configure(Element info, Element extra_info)
     
    146150    // assumes only one value per metadata
    147151    protected Element getMetadataList(String node_id, boolean all_metadata,
    148                       ArrayList metadata_names) {
     152                      ArrayList metadata_names) 
     153    throws GSException {
    149154    Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    150155    DBInfo info = this.gdbm_src.getInfo(node_id);
     
    281286     * <nodeContent>text content or other elements</nodeContent>
    282287     */
    283     abstract protected Element getNodeContent(String doc_id);
     288    abstract protected Element getNodeContent(String doc_id) throws GSException;
    284289
    285290    protected String getMetadata(String node_id, DBInfo info,
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS3DocumentRetrieve.java

    r9000 r9874  
    2020
    2121// Greenstone classes
     22import org.greenstone.gsdl3.core.GSException;
    2223import org.greenstone.gsdl3.util.GSXML;
    2324import org.greenstone.gsdl3.util.GSFile;
     
    6263    // set up a macro resolver
    6364    }
    64 
     65   
     66    public void cleanUp() {
     67    super.cleanUp();
     68    this.database.closeConnection();
     69    }
    6570
    6671    /** configure this service */
     
    109114    }
    110115   
    111     /** if an id is not a greenstone id (an external id) then translate
    112     it to a greenstone one*/
    113     protected String translateExternalId(String node_id){
    114     // dont have this yet
    115     return node_id;
    116     }
    117 
    118116    /** returns the id of the root node of the document containing node node_id. . may be the same as node_id */
    119117    protected String getRootId(String node_id) {
     
    150148    // assumes only one value per metadata
    151149    protected Element getMetadataList(String node_id, boolean all_metadata,
    152                       ArrayList metadata_names) {
     150                      ArrayList metadata_names)   
     151    throws GSException {
    153152    Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    154153
     
    215214     * <nodeContent>text content or other elements</nodeContent>
    216215     */
    217     abstract protected Element getNodeContent(String doc_id);
     216    abstract protected Element getNodeContent(String doc_id) throws GSException;
    218217
    219218}   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractMGPPSearch.java

    r9280 r9874  
    112112    {
    113113    this.mgpp_src = new MGPPWrapper();
     114    }
     115
     116    public void cleanUp() {
     117    super.cleanUp();
     118    this.mgpp_src.unloadIndexData();
    114119    }
    115120
     
    331336    } else if (name.equals(RANK_PARAM)) {
    332337        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)};
    334339       
    335340        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  
    7777    }
    7878
     79    public void cleanUp() {
     80    super.cleanUp();
     81    this.mg_src.unloadIndexData();
     82    }
    7983    public boolean configure(Element info, Element extra_info)
    8084    {
     
    201205    this.mg_src.runQuery(basedir, textdir, query);
    202206    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    }
    203212    long totalDocs = mqr.getTotalDocs();
    204213
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GATEServices.java.tmp

    r6501 r9874  
    226226
    227227        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    }   
    231236
    232237    result.appendChild(this.doc.importNode(doc_node_list, true));
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Browse.java

    r8959 r9874  
    2020
    2121// Greenstone classes
    22 import org.greenstone.gdbm.*;
    2322import org.greenstone.gsdl3.util.OID;
    2423import org.greenstone.gsdl3.util.GSXML;
     
    2625import org.greenstone.gsdl3.util.MacroResolver;
    2726import org.greenstone.gsdl3.util.GS2MacroResolver;
    28 
     27import org.greenstone.gsdl3.util.GDBMWrapper;
     28import org.greenstone.gsdl3.util.DBInfo;
    2929// XML classes
    3030import org.w3c.dom.Document;
     
    5454    this.gdbm_src = new GDBMWrapper();
    5555    this.macro_resolver = new GS2MacroResolver(this.gdbm_src);
     56    }
     57
     58    public void cleanUp() {
     59    super.cleanUp();
     60    this.gdbm_src.closeDatabase();
    5661    }
    5762
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java

    r8959 r9874  
    2121// Greenstone classes
    2222import org.greenstone.mgpp.*;
     23import org.greenstone.gsdl3.core.GSException;
    2324import org.greenstone.gsdl3.util.GSFile;
    2425import org.greenstone.gsdl3.util.GSXML;
     
    4748    public GS2MGPPRetrieve() {
    4849    this.mgpp_src = new MGPPWrapper();
     50    }
     51
     52    public void cleanUp() {
     53    super.cleanUp();
     54    this.mgpp_src.unloadIndexData();
    4955    }
    5056
     
    7985     * <nodeContent>text content or other elements</nodeContent>
    8086     */
    81     protected Element getNodeContent(String doc_id) {
     87    protected Element getNodeContent(String doc_id) throws GSException {
    8288    String lang = "en"; //  **********
    8389    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java

    r9002 r9874  
    2121// Greenstone classes
    2222import org.greenstone.gsdl3.util.*;
    23 import org.greenstone.gdbm.*;
    2423
    2524// XML classes
     
    4342    {
    4443    this.gdbm_src = new GDBMWrapper();
     44    }
     45
     46    public void cleanUp() {
     47    super.cleanUp();
     48    this.gdbm_src.closeDatabase();
    4549    }
    4650
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java

    r8959 r9874  
    2121// Greenstone classes
    2222import org.greenstone.mg.*;
     23import org.greenstone.gsdl3.core.GSException;
    2324import org.greenstone.gsdl3.util.GSFile;
    2425import org.greenstone.gsdl3.util.GSXML;
     
    4445    public GS2MGRetrieve() {
    4546    this.mg_src = new MGWrapper();
     47    }
     48
     49    public void cleanUp() {
     50    super.cleanUp();
     51    this.mg_src.unloadIndexData();
    4652    }
    4753
     
    8086     * <nodeContent>text content or other elements</nodeContent>
    8187     */
    82     protected Element getNodeContent(String doc_id) {
     88    protected Element getNodeContent(String doc_id) throws GSException {
    8389    String lang = "en"; //  **********
    8490    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java

    r9002 r9874  
    2121// Greenstone classes
    2222import org.greenstone.gsdl3.util.*;
    23 import org.greenstone.gdbm.*;
    2423
    2524// XML classes
     
    4342    {
    4443    this.gdbm_src = new GDBMWrapper();
     44    }
     45    public void cleanUp() {
     46    super.cleanUp();
     47    this.gdbm_src.closeDatabase();
    4548    }
    4649
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Browse.java

    r8959 r9874  
    5252    }
    5353
     54    public void cleanUp() {
     55    super.cleanUp();
     56    this.database.closeConnection();
     57    }
     58   
    5459    public boolean configure(Element info, Element extra_info)
    5560    {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPRetrieve.java

    r8959 r9874  
    2121// Greenstone classes
    2222import org.greenstone.mgpp.*;
     23import org.greenstone.gsdl3.core.GSException;
    2324import org.greenstone.gsdl3.util.GSFile;
    2425import org.greenstone.gsdl3.util.GSXML;
     
    4748    }
    4849
     50    public void cleanUp() {
     51    super.cleanUp();
     52    this.mgpp_src.unloadIndexData();
     53    }
     54
    4955    /** configure this service */
    5056    public boolean configure(Element info, Element extra_info)
    5157    {
     58    // Do generic configuration
     59    if (!super.configure(info, extra_info)) {
     60        return false;
     61    }
     62
    5263    // Do specific configuration
    5364    System.out.println("Configuring GS3MGPPRetrieve...");
     
    6677    // The location of the MGPP text files
    6778    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);
    6980
    70     // Do generic configuration
    71     return super.configure(info, extra_info);
    72  
     81    return true;
    7382    }
    7483   
     
    7786     * <nodeContent>text content or other elements</nodeContent>
    7887     */
    79     protected Element getNodeContent(String doc_id) {
     88    protected Element getNodeContent(String doc_id) throws GSException {
    8089    if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {
    8190        // if we have a whole doc id, and the document is hierarchical,
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPSearch.java

    r9002 r9874  
    5050    {
    5151    this.database = new SQLQuery();
     52    }
     53
     54    public void cleanUp() {
     55    super.cleanUp();
     56    this.database.closeConnection();
    5257    }
    5358
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java

    r9001 r9874  
    2121// Greenstone classes
    2222import org.greenstone.mg.*;
     23import org.greenstone.gsdl3.core.GSException;
    2324import org.greenstone.gsdl3.util.GSFile;
    2425import org.greenstone.gsdl3.util.GSXML;
     
    4243    private String mg_textdir = null;
    4344    private String default_index = null;
     45   
    4446    public GS3MGRetrieve() {
    4547    this.mg_src = new MGWrapper();
     48    }
     49
     50    public void cleanUp() {
     51    super.cleanUp();
     52    this.mg_src.unloadIndexData();
    4653    }
    4754
     
    8693     * <nodeContent>text content or other elements</nodeContent>
    8794     */
    88     protected Element getNodeContent(String doc_id) {
     95    protected Element getNodeContent(String doc_id) throws GSException {
    8996
    9097    if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {
     
    111118    } catch (Exception e) {
    112119        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";
    114122    }
    115123   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGSearch.java

    r9002 r9874  
    5050    {
    5151    this.database = new SQLQuery();
     52    }
     53
     54    public void cleanUp() {
     55    super.cleanUp();
     56    this.database.closeConnection();
    5257    }
    5358
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaProxy.java

    r8158 r9874  
    22
    33// Greenstone classes
    4 import org.greenstone.gdbm.*;
    54import org.greenstone.gsdl3.util.*;
    65
     
    406405    doc_node.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    407406   
    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    }
    411414    return doc_node;
    412415   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java

    r9289 r9874  
    22
    33// Greenstone classes
    4 import org.greenstone.gdbm.*;
     4import org.greenstone.gsdl3.core.GSException;
    55import org.greenstone.gsdl3.util.*;
    66
     
    6161       
    6262    /** 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 {
    6465
    6566    String url_string = ivia_server_url+"/cgi-bin/view_record?theme=gsdl3&record_id="+doc_id;
     
    6768    StringBuffer buffer = new StringBuffer();
    6869    try {
    69         BufferedReader reader = makeConnection(url_string);
     70        BufferedReader reader = Misc.makeHttpConnection(url_string);
    7071            String line;
    7172        while((line = reader.readLine())!= null) {
    7273        buffer.append(line);
    7374        }
    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
    7981    String node_content = buffer.toString();
    8082
     
    99101    processed_content.append("</nodeContent>");
    100102       
    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();
    102111
    103112    return (Element)this.doc.importNode(content_element,true);
     
    169178    }
    170179
    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 
    186180    protected String translateId(String oid){
    187181    int p = oid.lastIndexOf('.');
     
    215209    protected Element getMetadataList (String doc_id,
    216210                       boolean all_metadata,
    217                        ArrayList metadata_names){
     211                       ArrayList metadata_names)
     212    throws GSException {
    218213   
    219214    Element meta_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     
    236231    String url_string = ivia_server_url+"/cgi-bin/view_record_set?theme=gsdl3&record_id_list="+doc_id+"&field_list="+field_list.toString();
    237232    try {
    238         BufferedReader reader = makeConnection(url_string);
     233        BufferedReader reader = Misc.makeHttpConnection(url_string);
    239234        String line;
    240235        while  ((line = reader.readLine()) != null) {
     
    249244        GSXML.addMetadata(this.doc, meta_list, name, value);
    250245        }
    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);
    254250    }
    255251    return meta_list;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaSearch.java

    r9273 r9874  
    22
    33// Greenstone classes
    4 import org.greenstone.gdbm.*;
    54import org.greenstone.gsdl3.util.*;
    65
     
    1413import java.util.HashMap;
    1514import java.io.File;
    16 import java.io.InputStream;
    1715import 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;
    2316import java.net.Authenticator;
    24 import java.net.MalformedURLException;
    2517
    2618/**
    2719 *
    2820 * @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>
    3122 */
    3223
     
    109100    String results_num = null;
    110101    String doc_ids = null;
     102    BufferedReader reader = null;
    111103    try {
    112104        ///system.err.println("IViaSearch, sending "+url_string);
    113         BufferedReader reader = makeConnection(url_string);
     105        reader = Misc.makeHttpConnection(url_string);
    114106        results_num = reader.readLine();
    115107        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());
    119113        return result;
    120114    }
     
    124118    } else {
    125119        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);
    126121        return result;
    127122    }
     
    130125    } else {
    131126        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);
    132128        return result;
    133129    }
     
    150146    }
    151147     
    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     }
    166148
    167149    /**
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/LuceneSearch.java

    r9272 r9874  
    22
    33// Greenstone classes
    4 import org.greenstone.gdbm.*;
    54import org.greenstone.gsdl3.util.*;
    65
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MapRetrieve.java

    r6694 r9874  
    22
    33// Greenstone classes
    4 import org.greenstone.gdbm.*;
    54import org.greenstone.gsdl3.util.*;
    65
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MapSearch.java

    r9286 r9874  
    2020
    2121// Greenstone classes
    22 import org.greenstone.gdbm.*;
    2322import org.greenstone.gsdl3.util.*;
    2423
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ModuleWrapper.java

    r3621 r9874  
    100100
    101101  }
     102 
     103  public void cleanUp() {}
     104 
    102105  /** The all-args constructor */
    103106  public ModuleWrapper(String in,String out, ModuleInterface inner){
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/PhindPhraseBrowse.java

    r6490 r9874  
    5656    this.mgpp_src.setCase(true);
    5757    }
     58
     59    public void cleanUp() {
     60    super.cleanUp();
     61    this.mgpp_src.unloadIndexData();
     62    }
     63
    5864    /** configure the service module
    5965     *
     
    8995   
    9096    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    }
    91101    Element app_elem = dom.getDocumentElement();
    92102    applet_description.appendChild(this.doc.importNode(app_elem, true));
    93    
     103
    94104    return true;
    95105    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceRack.java

    r9426 r9874  
    9595    setClusterName(coll_name);
    9696    }
     97
     98    public void cleanUp() {}
    9799   
    98100    /** sets the site home */
     
    144146   
    145147    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    }
    147153    Element res = process(doc.getDocumentElement());
    148154    return this.converter.getString(res);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/Visualizer.java

    r8347 r9874  
    7575       
    7676    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    }
    7781    Element app_elem = dom.getDocumentElement();
    7882    applet_description.appendChild(this.doc.importNode(app_elem, true));
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/Dictionary.java

    r9424 r9874  
    4747        this.raw = ResourceBundle.getBundle(this.resource, this.locale);
    4848    } 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);
    5050    }
    5151    }
     
    7070        this.raw = ResourceBundle.getBundle(this.resource, this.locale);
    7171    } 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);
    7373    }
    7474   
     
    129129    }
    130130    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);
    132132        return null;
    133133    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java

    r8962 r9874  
    2020
    2121import java.util.ArrayList;
    22 import org.greenstone.gdbm.GDBMWrapper;
    23 import org.greenstone.gdbm.DBInfo;
    2422
    2523public class GS2MacroResolver
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java

    r9425 r9874  
    2020
    2121import java.io.File;
    22 import org.apache.soap.encoding.soapenc.Base64;
     22//import org.apache.soap.encoding.soapenc.Base64;
     23import org.apache.axis.encoding.Base64;
    2324import java.io.BufferedInputStream;
    2425import java.io.BufferedOutputStream;
     
    161162   
    162163    /** text path (for doc retrieval) relative to collectionBaseDir */
    163     static public String collectionTextPath(String collection_name) {
     164    static public String collectionTextPath(String index_stem) {
    164165    return "index"+File.separatorChar+"text"+File.separatorChar+
    165         collection_name;
     166        index_stem;
    166167    }
    167168
    168169    /** index path (for querying) relative to collectionBaseDir */
    169     static public String collectionIndexPath(String collection_name,
     170    static public String collectionIndexPath(String index_stem,
    170171                         String index_name) {
    171172    return "index"+File.separatorChar+index_name+File.separatorChar+
    172         collection_name;
     173        index_stem;
    173174    }
    174175   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r9261 r9874  
    9999    public static final String PARAM_IGNORE_POS_ATT = "ignore";
    100100    public static final String CLASSIFIER_CONTENT_ATT = "content";
    101    
     101    public static final String ERROR_TYPE_ATT = "type";
     102
    102103    // document stuff
    103104    public static final String DOC_TYPE_ATT = "docType";
     
    173174    public static final String COMM_TYPE_SOAP_JAVA = "soap";
    174175   
     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
    175182    // some system wide param names
    176183    public static final String SUBSET_PARAM = "subset";
     
    279286    }
    280287 
     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    }
    281292    /** 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) {
    283295
    284296    Element content = owner.createElement(ERROR_ELEM);
     297    content.setAttribute(ERROR_TYPE_ATT, error_type);
    285298    Text t = owner.createTextNode(text);
    286299    content.appendChild(t);
     
    291304    /** add an error message */
    292305    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);
    295314    }
    296315
     
    402421    }
    403422       
     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   
    404435
    405436    /** Duplicates an element, but gives it a new name */
     
    407438                           String element_name, boolean with_attributes)
    408439    {
    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    }
    411456    // Copy element attributes
    412457    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 */
    119
    220package org.greenstone.gsdl3.util;
    3 
    421
    522import java.util.HashMap;
     
    825import java.util.Iterator;
    926import java.util.Properties;
     27import java.io.InputStream;
     28import java.io.BufferedReader;
     29import java.io.InputStreamReader;
     30import java.io.IOException;
     31import java.net.HttpURLConnection;
     32import java.net.URL;
     33import java.net.URLConnection;
    1034
    1135/** contains miscellaneous functions */
     
    3155    }
    3256
     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
    3367}
     68
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/SQLQuery.java

    r8746 r9874  
    66import java.sql.ResultSet;
    77import java.sql.SQLException;
     8import java.sql.Statement;
    89
    910import java.util.ArrayList;
     
    1718
    1819    public boolean setDatabase(String db_name) {
    19     try {
    20         connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name);
    21        
     20    connection = GS3SQLConnectionFactory.getGS3SQLConnection(db_name);
     21    try {
     22
    2223        // test the connection
    2324        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();
    2928        return true;
    3029    } 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;
    3340    }
    3441    }
     
    4855        GSSQL.END;
    4956   
    50     connection.execute(query);
     57    Statement statement = null;
    5158    ResultSet results = null;
    5259    String doc_id = null;
    5360    String meta_id = null;
    5461    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    }
    6575
    6676    // now get division label
     
    7383        GSSQL.END;
    7484
    75     connection.execute(query);
     85   
    7686    String short_label = null;
    7787    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) {
    8397
    8498        System.err.println("SQLQuery.MGNum2OID() Error: "+e.getMessage());
    8599        return null;
    86100    }
    87 
    88     ///ystem.out.println("short label = "+short_label);
    89 
    90     System.out.println("final doc_id = "+GS3OID.createOID(doc_id, short_label));
     101   
    91102    return GS3OID.createOID(doc_id, short_label);
    92103    }
    93104
    94105    public String OID2MGNum(String oid) {
    95     System.out.println("converting oid "+oid+" to mg num");
    96106    String id = getDocumentMetadata(oid, "gsdl3.mgseqno");
    97     System.out.println("mg id = "+id);
    98107    return id;
    99108
     
    113122        " and "+ GSSQL.STRUCTURE_ID +GSSQL.EQUALS_QUOTE + "Section" + GSSQL.QUOTE +
    114123        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();
    123130    } catch (java.sql.SQLException e) {
    124131        return false;
    125132    }
    126 
    127     return false;
     133   
     134    return is_hierarchical;
    128135    }
    129136   
     
    131138    public String getClassifierMetadata(String oid, String full_meta_name) {
    132139
    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) {
    146165       
    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   
    163171    }
    164172   
     
    172180        section_id = GS3OID.getSectionLabel(oid);
    173181    }
    174     System.out.println("getDocChildren: oid = "+oid+", doc id = "+doc_id+", sec id ="+section_id);
    175182//      int sep_index = oid.indexOf(".");
    176183//      if (sep_index != -1) {
     
    186193        GSSQL.END;
    187194
    188     connection.execute(query);
    189195    ResultSet results = null;
     196    Statement statement = null;
    190197    String div_ref = null;
    191198    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        }
    195207    } catch (java.sql.SQLException e) {
    196208       
     
    206218        " and "+GSSQL.PARENT_REF+GSSQL.EQUALS_QUOTE+div_ref+GSSQL.QUOTE+
    207219        GSSQL.END;
    208     connection.execute(query);
    209     results = null;
    210     try {
    211         results = connection.getResultSet();
     220    try {
     221        results = statement.executeQuery(query);
    212222        while (results.next()) {
    213223        String id = results.getString(GSSQL.SHORT_LABEL);
    214224        children.add(GS3OID.createOID(doc_id, id));
    215225        }
     226        statement.close();
    216227    } catch (java.sql.SQLException e) {
    217228       
     
    243254        GSSQL.END;
    244255   
    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);
    249259        while (results.next()) {
    250260        String id = results.getString(GSSQL.CLASSIFIER_ID);
    251261        children.add(id);
    252262        }
    253     } catch (java.sql.SQLException e) {
    254        
     263        statement.close();
     264    } catch (java.sql.SQLException e) {
     265       
    255266        System.err.println("SQLQuery.getClassifierChildren Error: "+e.getMessage());
    256267        return null;
     
    260271
    261272    public ArrayList getClassifierDocChildren(String oid) {
    262     System.out.println("in getclassifierdocchildren");
    263273    ArrayList children = new ArrayList();
    264274
     
    269279        " order by "+GSSQL.CLASS_DOCUMENT_TABLE+GSSQL.DOT+GSSQL.DOCUMENT_ORDER+
    270280        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);
    276284        while (results.next()) {
    277285        String id = results.getString(GSSQL.DOCUMENT_ID);
     
    283291        return null;
    284292    }
    285     // now check for documents
    286293   
    287294    return children;
     
    302309//      }
    303310
    304     System.out.println("get meta for "+oid+", doc id = "+doc_id+"sec id = "+section_id);
    305311
    306312    // get the metadata block id
     
    314320        GSSQL.END;
    315321   
    316     connection.execute(query);
     322    Statement statement = null;
    317323    ResultSet results = null;
    318324    String meta_id = null;
    319325    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        }
    323334    } catch (java.sql.SQLException e) {
    324335
     
    326337        return null;
    327338    }
    328     System.err.println("metadata block id = "+meta_id);
    329 
     339   
    330340    // now get the list of namespace refs for the right namespace
    331341    int sep_index = full_meta_name.indexOf('.');
     
    337347        meta_name = full_meta_name.substring(sep_index+1);
    338348    }
    339     System.out.println("orig meta = "+full_meta_name+", ns = "+meta_ns+", name="+meta_name);
    340349
    341350    query = "select * "+
     
    347356        " and "+GSSQL.NAMESPACE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+GSSQL.EQUALS+GSSQL.METADATA_VALUE_TABLE+GSSQL.DOT+GSSQL.NAMESPACE_REF+
    348357        GSSQL.END;
    349     System.out.println("query="+query);
    350     connection.execute(query);
     358   
    351359    String meta_value = null;
    352360    try {
    353         results = connection.getResultSet();
     361        statement = connection.createStatement();
     362        results = statement.executeQuery(query);
    354363        while (results.next()) {
    355364        String m_name = results.getString(GSSQL.LABEL);
     
    359368        }
    360369        }
     370        statement.close();
    361371    } catch (java.sql.SQLException e) {
    362372
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/XMLConverter.java

    r8923 r9874  
    158158    String nodeName = xmlNode.getNodeName();
    159159
     160    if (nodeType == Node.DOCUMENT_NODE) {
     161        return getString(((Document)xmlNode).getDocumentElement(), depth, pretty);
     162    }
    160163    // Handle Element nodes
    161164    if (nodeType == Node.ELEMENT_NODE) {
  • trunk/gsdl3/src/packages/mg/java/org/greenstone/mg/MGQueryResult.java

    r3794 r9874  
    5353    }
    5454
     55    public boolean isClear() {
     56    return (total_num_docs_ == 0 && docs_.isEmpty() && terms_.isEmpty());
     57    }
    5558
    5659    /** returns the result as a String - useful for printing out results */
  • trunk/gsdl3/src/packages/mg/jni/MGWrapperImpl.c

    r8920 r9874  
    315315
    316316  /* Check that the index was loaded successfully */
    317   assert(qd != NULL);
     317  if (qd==NULL) {
     318    return NULL;
     319  }
     320  /*assert(qd != NULL);*/
    318321
    319322  /* Get the document position and length in the text file */
     
    372375  jthrowable exc;
    373376
    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 */
    402378  /* The result to write to */
    403379  result_ptr = (*j_env)->GetObjectField(j_env, j_obj, FID_query_result);
     
    411387    return;
    412388  }
     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);
    413420
    414421  /* Obtain a C version of the query string */
  • trunk/gsdl3/src/packages/mg/src/images/WIN32.MAK

    r3921 r9874  
    156156
    157157mostlyclean:
    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.*
    159165 
    160166clean: mostlyclean
    161     rm -f $(EXEC)
     167    if exist *$e del *$e
    162168 
    163169distclean: clean
    164     rm -f ansi2knr
    165     rm -f Makefile
    166  
     170    del ansi2knr
     171     
    167172maintainer-clean: distclean
    168173    @echo "This command is intended only for maintainers to use;"
  • trunk/gsdl3/src/packages/mg/src/text/win32.mak

    r7585 r9874  
    237237clean:
    238238        if exist *$o del *$o
    239     if exist $(EXEC) del $(EXEC)
     239    if exist *$e del *$e
    240240        if exist libmgtextin.lib del libmgtextin.lib
    241241        if exist libmgpass.lib del libmgpass.lib
  • trunk/gsdl3/src/packages/mg/winMake.bat

    r6416 r9874  
    2929    cd ..\..
    3030
     31    cd java\org\greenstone\mg
     32    call winMake.bat %1
     33    cd ..\..\..\..
     34
    3135    cd jni
    3236    %MAKE% %MAKE_OPTIONS% win32.mak %1
     
    4044
    4145:done
     46
     47
Note: See TracChangeset for help on using the changeset viewer.