Changeset 6358


Ignore:
Timestamp:
2004-01-06T17:04:00+13:00 (20 years ago)
Author:
kjdon
Message:

uncommented lots of classifier stuff, and modified for sql

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Retrieve.java

    r6304 r6358  
    3535import java.util.Set;
    3636import java.util.Iterator;
     37import java.util.ArrayList;
    3738
    3839/** Implements the generic retrieval and classifier services for GS3
     
    110111    this.short_service_info.appendChild(dcr_service);
    111112
    112     // Open GDBM database for querying
    113 //      String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name);
    114 //      if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    115 //          System.err.println("GS3Retrieve Error: Could not open GDBM database!");
    116 //          return false;
    117 //      }
    118113    if (!database.setDatabase(this.cluster_name)) {
    119114        System.err.println("GS3Search Error: Could not open SQL database!");
     
    124119 
    125120        // check that there are classifiers specified
    126 //          Element class_list = (Element)GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
    127 //          if (class_list == null) {
    128 //              // no classifiers specified
    129 //              return true;
    130 //          }
    131    
    132 //      // get the display and format elements from the coll config file for
    133 //      // the classifiers
    134 //      extractExtraClassifierInfo(info, extra_info);
    135    
    136 //      this.config_info = info;
    137    
    138 //          // short_service_info_ - the browse one
    139 //          Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    140 //          cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
    141 //          cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
    142 //          this.short_service_info.appendChild(cb_service);
    143    
    144 //      // metadata retrieval for the browsing 
    145 //          Element cbmr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    146 //          cbmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
    147 //          cbmr_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_METADATA_SERVICE);
    148 //          this.short_service_info.appendChild(cbmr_service);
    149 
    150 //      // the format info
    151 //      Element cb_format_info = this.doc.createElement(GSXML.FORMAT_ELEM);
    152 //      boolean format_found = false;
    153 //      // add in to the description a simplified list of classifiers
    154 //          NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    155 //      for(int i=0; i<classifiers.getLength(); i++) {
    156 //          Element cl = (Element)classifiers.item(i);
    157 //          Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
    158        
    159 //          // get the format info out, and put inside a classifier element
    160 //          Element format_cl = (Element)new_cl.cloneNode(false);
    161 //          Element format = (Element)GSXML.getChildByTagName(cl, GSXML.FORMAT_ELEM);
    162 //          if (format != null) {
    163        
    164 //          //copy all the children
    165 //          NodeList elems = format.getChildNodes();
    166 //          for (int j=0; j<elems.getLength();j++) {
    167 //              format_cl.appendChild(this.doc.importNode(elems.item(j), true));
    168 //          }
    169 //          cb_format_info.appendChild(format_cl);
    170 //          format_found = true;
    171 //          }
    172        
    173        
    174 //      }
    175        
    176 //      if (format_found) {
    177 //          this.format_info_map.put(CLASSIFIER_SERVICE, cb_format_info);
    178 //      }
     121        Element class_list = (Element)GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     122        if (class_list == null) {
     123            // no classifiers specified
     124            return true;
     125        }
     126   
     127    // get the display and format elements from the coll config file for
     128    // the classifiers
     129    extractExtraClassifierInfo(info, extra_info);
     130   
     131    this.config_info = info;
     132   
     133        // short_service_info_ - the browse one
     134        Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     135        cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
     136        cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
     137        this.short_service_info.appendChild(cb_service);
     138   
     139    // metadata retrieval for the browsing 
     140        Element cbmr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     141        cbmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
     142        cbmr_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_METADATA_SERVICE);
     143        this.short_service_info.appendChild(cbmr_service);
     144
     145    // the format info
     146    Element cb_format_info = this.doc.createElement(GSXML.FORMAT_ELEM);
     147    boolean format_found = false;
     148    // add in to the description a simplified list of classifiers
     149        NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     150    for(int i=0; i<classifiers.getLength(); i++) {
     151        Element cl = (Element)classifiers.item(i);
     152        Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
     153       
     154        // get the format info out, and put inside a classifier element
     155        Element format_cl = (Element)new_cl.cloneNode(false);
     156        Element format = (Element)GSXML.getChildByTagName(cl, GSXML.FORMAT_ELEM);
     157        if (format != null) {
     158       
     159        //copy all the children
     160        NodeList elems = format.getChildNodes();
     161        for (int j=0; j<elems.getLength();j++) {
     162            format_cl.appendChild(this.doc.importNode(elems.item(j), true));
     163        }
     164        cb_format_info.appendChild(format_cl);
     165        format_found = true;
     166        }
     167       
     168       
     169    }
     170       
     171    if (format_found) {
     172        this.format_info_map.put(CLASSIFIER_SERVICE, cb_format_info);
     173    }
    179174
    180175    // look for document display format
     
    183178    if (display_format != null) {
    184179        this.format_info_map.put(DOCUMENT_CONTENT_RETRIEVE_SERVICE, this.doc.importNode(display_format, true));
    185         // shoudl we make a copy?
     180        // should we make a copy?
    186181    }
    187182    return true;
     
    190185    protected Element getServiceDescription(String service_id, String lang, String subset) {
    191186
    192 //      if (service_id.equals(CLASSIFIER_SERVICE)) {
    193        
    194 //          Element class_list = (Element)GSXML.getChildByTagName(this.config_info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
    195 //          if (class_list == null) {
    196 //              // no classifiers specified
    197 //          return null;
    198 //          }
    199        
    200 //          Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    201 //          cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
    202 //          cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
    203 //          cb_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME,  getTextString(CLASSIFIER_SERVICE+".name", lang)));
    204 //          cb_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION,  getTextString(CLASSIFIER_SERVICE+".description", lang)));
    205        
    206 //          Element cl_list = this.doc.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
    207 //          cb_service.appendChild(cl_list);
    208 //          NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    209 //          for(int i=0; i<classifiers.getLength(); i++) {
    210 //          Element cl = (Element)classifiers.item(i);
    211 //          Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
    212 //          String content = cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT);
    213 //          cl_list.appendChild(new_cl);
    214 //          String text = GSXML.getDisplayText(cl,
    215 //                             GSXML.DISPLAY_TEXT_NAME,
    216 //                             lang, "en");
    217 //          if (text == null || text.equals("")) {
    218 //              // no display element was specified, use the metadata name
    219 //              // for now this looks in the class properties file
    220 //              // this needs to use a general metadata thing instead
    221 //              text = getMetadataNameText(content+".buttonname", lang);
    222 //          }
    223 //          if (text == null) {
    224 //              text = content;
    225 //          }
    226        
    227 //          Element cl_name = GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, text);
    228 //          new_cl.appendChild(cl_name);
    229 
    230 //          // description
    231        
    232 //          String meta_name = getMetadataNameText(content, lang);
    233 //          if (meta_name==null) {
    234 //              meta_name = content;
    235 //          }
    236 //          String [] array = {meta_name};
    237 //          String description = getTextString("ClassifierBrowse.classifier_help", array, lang);
    238 //          Element cl_desc = GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, description);
    239 //          new_cl.appendChild(cl_desc);
    240        
    241 //          }
    242 //          return cb_service;
    243 //      }
     187    if (service_id.equals(CLASSIFIER_SERVICE)) {
     188       
     189        Element class_list = (Element)GSXML.getChildByTagName(this.config_info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     190        if (class_list == null) {
     191            // no classifiers specified
     192        return null;
     193        }
     194       
     195        Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     196        cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
     197        cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
     198        cb_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME,  getTextString(CLASSIFIER_SERVICE+".name", lang)));
     199        cb_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION,  getTextString(CLASSIFIER_SERVICE+".description", lang)));
     200       
     201        Element cl_list = this.doc.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     202        cb_service.appendChild(cl_list);
     203        NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     204        for(int i=0; i<classifiers.getLength(); i++) {
     205        Element cl = (Element)classifiers.item(i);
     206        Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
     207        String content = cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT);
     208        cl_list.appendChild(new_cl);
     209        String text = GSXML.getDisplayText(cl,
     210                           GSXML.DISPLAY_TEXT_NAME,
     211                           lang, "en");
     212        if (text == null || text.equals("")) {
     213            // no display element was specified, use the metadata name
     214            // for now this looks in the class properties file
     215            // this needs to use a general metadata thing instead
     216            text = getMetadataNameText(content+".buttonname", lang);
     217        }
     218        if (text == null) {
     219            text = content;
     220        }
     221       
     222        Element cl_name = GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, text);
     223        new_cl.appendChild(cl_name);
     224
     225        // description
     226       
     227        String meta_name = getMetadataNameText(content, lang);
     228        if (meta_name==null) {
     229            meta_name = content;
     230        }
     231        String [] array = {meta_name};
     232        String description = getTextString("ClassifierBrowse.classifier_help", array, lang);
     233        Element cl_desc = GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, description);
     234        new_cl.appendChild(cl_desc);
     235       
     236        }
     237        return cb_service;
     238    }
    244239   
    245240    // these ones are probably never called, but put them here just in case
     
    277272
    278273    /** this looks for any classifier specific display or format info from extra_info and adds it in to the correct place in info */
    279 //      protected boolean extractExtraClassifierInfo(Element info, Element extra_info) {
    280    
    281 //      if (extra_info == null) {
    282 //          return false;
    283 //      }
    284    
    285 //      Document owner = info.getOwnerDocument();
    286 //      // so far we have display and format elements that we need for classifiers
    287 //      NodeList classifiers = info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    288 //      Element config_browse = (Element)GSXML.getChildByTagName(extra_info, GSXML.BROWSE_ELEM);
    289 
    290 //      for (int i=0; i<classifiers.getLength();i++) {
    291 //          Element cl = (Element)classifiers.item(i);
    292 //          String name = cl.getAttribute(GSXML.NAME_ATT);
    293 //          Element node_extra = GSXML.getNamedElement(config_browse,
    294 //                                 GSXML.CLASSIFIER_ELEM,
    295 //                                 GSXML.NAME_ATT,
    296 //                                 name);
    297 //          if (node_extra == null) {
    298 //          System.err.println("GS3REtrieve: haven't found extra info for classifier named "+name);
    299 //          continue;
    300 //          }
    301        
    302 //          // get the display elements if any - displayName
    303 //          NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
    304 //          if (display_names !=null) {
    305 //          Element display = owner.createElement(GSXML.DISPLAY_ELEM);
    306 //          for (int j=0; j<display_names.getLength(); j++) {
    307 //              Element e = (Element)display_names.item(j);
    308 //              cl.appendChild(owner.importNode(e, true));
     274    protected boolean extractExtraClassifierInfo(Element info, Element extra_info) {
     275   
     276    if (extra_info == null) {
     277        return false;
     278    }
     279   
     280    Document owner = info.getOwnerDocument();
     281    // so far we have display and format elements that we need for classifiers
     282    NodeList classifiers = info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     283    Element config_browse = (Element)GSXML.getChildByTagName(extra_info, GSXML.BROWSE_ELEM);
     284
     285    for (int i=0; i<classifiers.getLength();i++) {
     286        Element cl = (Element)classifiers.item(i);
     287        String name = cl.getAttribute(GSXML.NAME_ATT);
     288        Element node_extra = GSXML.getNamedElement(config_browse,
     289                               GSXML.CLASSIFIER_ELEM,
     290                               GSXML.NAME_ATT,
     291                               name);
     292        if (node_extra == null) {
     293        System.err.println("GS3REtrieve: haven't found extra info for classifier named "+name);
     294        continue;
     295        }
     296       
     297        // get the display elements if any - displayName
     298        NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
     299        if (display_names !=null) {
     300        Element display = owner.createElement(GSXML.DISPLAY_ELEM);
     301        for (int j=0; j<display_names.getLength(); j++) {
     302            Element e = (Element)display_names.item(j);
     303            cl.appendChild(owner.importNode(e, true));
    309304           
    310 //          }
    311 //          }
    312        
    313 //          // get the format element if any
    314 //          Element format = (Element)GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
    315 //          if (format==null) { // try a generic one that applies to all classifiers
    316 //          format = (Element)GSXML.getChildByTagName(extra_info,
    317 //                                GSXML.FORMAT_ELEM);
    318 //          }
    319 //          if (format!=null) { // append to index info
    320 //          cl.appendChild(owner.importNode(format, true));
    321 //          }
    322 //      } // for each classifier
    323 //      return true;
    324 //      }
     305        }
     306        }
     307       
     308        // get the format element if any
     309        Element format = (Element)GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
     310        if (format==null) { // try a generic one that applies to all classifiers
     311        format = (Element)GSXML.getChildByTagName(extra_info,
     312                              GSXML.FORMAT_ELEM);
     313        }
     314        if (format!=null) { // append to index info
     315        cl.appendChild(owner.importNode(format, true));
     316        }
     317    } // for each classifier
     318    return true;
     319    }
    325320       
    326321
     
    328323     * child is true is it definitely is a child of something - just for efficiency purposes */
    329324    protected Element createDocNode(String node_id, boolean parent, boolean child) {
    330     Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    331     node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    332     node.setAttribute(GSXML.NODE_ID_ATT, node_id);
    333     return node;
    334     }
    335 //      // create this here or pass it in?
    336 //      DBInfo info = this.gdbm_src.getInfo(node_id);
    337 //      Element node;
    338 //      if (isClassifier(node_id)) {
    339 //          node = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
    340 //          //String childtype = info.getInfo("childtype");
    341 //          //String orientation="";
    342 //          //if (childtype.equals("HList")) {
    343 //          //  orientation = "horizontal";
    344 //          //} else { // assume vertical
    345 //          //  orientation = "vertical";
    346 //          //}
    347 //          //node.setAttribute(GSXML.CLASS_NODE_ORIENTATION_ATT, orientation);
    348 //      } else {
    349        
    350 //          node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     325//      Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     326//      node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
     327//      node.setAttribute(GSXML.NODE_ID_ATT, node_id);
     328//      return node;
     329   
     330    Element node;
     331    if (isClassifier(node_id)) {
     332        node = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
     333        //String childtype = info.getInfo("childtype");
     334        //String orientation="";
     335        //if (childtype.equals("HList")) {
     336        //  orientation = "horizontal";
     337        //} else { // assume vertical
     338        //  orientation = "vertical";
     339        //}
     340        //node.setAttribute(GSXML.CLASS_NODE_ORIENTATION_ATT, orientation);
     341    } else {
     342       
     343        node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     344        node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    351345
    352346//          String top_id = OID.getTop(node_id);
     
    383377//          }
    384378       
    385 //      }
    386 //      node.setAttribute(GSXML.NODE_ID_ATT, node_id);
    387 //      return node;
    388 
    389 //      }
     379    }
     380    node.setAttribute(GSXML.NODE_ID_ATT, node_id);
     381    return node;
     382
     383    }
    390384    /** Returns the parent of a specified documentID, or null if none exists */
    391 //      protected Element getParent(String doc_id)
    392 //      {
    393 //      String parent_id = OID.getParent(doc_id);
    394 //      if (parent_id.equals(doc_id))
    395 //          return null;
    396    
    397 //      return createDocNode(parent_id, true, false);
    398 //      }
     385    protected Element getParent(String doc_id)
     386    {
     387    String parent_id = OID.getParent(doc_id);
     388    if (parent_id.equals(doc_id))
     389        return null;
     390   
     391    return createDocNode(parent_id, true, false);
     392    }
    399393
    400394
    401395    /** adds all the children of doc_id the the doc element,
    402396     * and if recursive=true, adds all their children as well*/
    403 //      protected void addDescendants(Element doc, String doc_id,
    404 //                    boolean recursive)
    405 //      {
    406 //      DBInfo info = this.gdbm_src.getInfo(doc_id);
    407 //      String contains = info.getInfo("contains");
    408 
    409 //      StringTokenizer st = new StringTokenizer(contains, ";");
    410 //      while (st.hasMoreTokens()) {
    411 //          String child_id = st.nextToken().replaceAll("\"", doc_id);
    412 //          Element child = createDocNode(child_id, false, true);
    413 //          doc.appendChild(child);
    414 
    415 //          // Apply recursively, if desired
    416 //          if (recursive) {
    417 //          addDescendants(child, child_id, recursive);
    418 //          }
    419        
    420 //      }
    421 //      }
    422 
    423 //      /** adds all the siblings of current_id to the parent element. */
     397    protected void addDescendants(Element doc, String doc_id,
     398                  int type, boolean recursive)
     399    {
     400    if (type == DOCUMENT) {
     401        return;
     402    }
     403    if (type == CLASSIFIER) {
     404        ArrayList documents = database.getClassifierDocChildren(doc_id);
     405        for (int i=0; i<documents.size(); i++) {
     406        String child_id = (String) documents.get(i);
     407        Element child = createDocNode(child_id, false, true);
     408        doc.appendChild(child);
     409        }
     410        ArrayList children = database.getClassifierChildren(doc_id);
     411        for (int i=0; i<children.size(); i++) {
     412        String child_id = (String) children.get(i);
     413        Element child = createDocNode(child_id, false, true);
     414        doc.appendChild(child);
     415        // Apply recursively, if desired
     416        if (recursive) {
     417            addDescendants(child, child_id, type, recursive);
     418        }
     419        }
     420       
     421    }
     422    }
     423
     424    /** adds all the siblings of current_id to the parent element. */
    424425//      protected Element addSiblings(Element parent, String parent_id, String current_id) {
    425426//      Element current_node = (Element)parent.getFirstChild();
     
    443444
    444445//      }
    445 //      /** Returns true if the OID specifies a leaf node, false otherwise
    446 //      Note: this makes a request to the GDBM database so it may not be
    447 //            a particularly cheap operation */
     446    /** Returns true if the OID specifies a leaf node, false otherwise
     447    Note: this makes a request to the GDBM database so it may not be
     448          a particularly cheap operation */
    448449//      protected boolean isLeafNode(String oid)
    449450//      {
     
    453454//      }
    454455
    455 //      // for now just use CL for classifiers - should have a type? in teh gdbm
    456 //      // database.
    457 //      protected boolean isClassifier(String oid) {
    458 //      if (oid.startsWith("CL")) {
    459 //          return true;
    460 //      }
    461 //      return false;
    462 //      }
     456    // for now just use CL for classifiers - should have a type?
     457    protected boolean isClassifier(String oid) {
     458    if (oid.startsWith("CL")) {
     459        return true;
     460    }
     461    return false;
     462    }
    463463
    464464//      protected Element processDocumentStructureRetrieve(Element request) {
     
    466466//      }
    467467
    468 //      protected Element processClassifierBrowse(Element request) {
    469 //      return genericStructureRetrieve(request, CLASSIFIER);
    470 //      }
    471 
    472 //      /** Retrieve the structure of a document */
    473 //      protected Element genericStructureRetrieve(Element request, int type)
    474 //      {
    475 //      // Create a new (empty) result message
    476 //      Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    477    
    478 //      String node_name;
    479 //      String service_name;
    480 //      if (type==DOCUMENT) {
    481 //          service_name = DOCUMENT_STRUCTURE_RETRIEVE_SERVICE;
    482 //          node_name = GSXML.DOC_NODE_ELEM;
    483 //      } else {
    484 //          service_name = CLASSIFIER_SERVICE;
    485 //          node_name = GSXML.CLASS_NODE_ELEM;
    486 //      }
    487    
    488 //      result.setAttribute(GSXML.FROM_ATT, service_name);
    489 //      result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    490 
    491 
    492 //      Element query_doc_list = (Element) GSXML.getChildByTagName(request, node_name+GSXML.LIST_MODIFIER);
    493 //      if (query_doc_list == null) {
    494 //          System.err.println("GS3Retrieve Error: DocumentStructureRetrieve request specified no doc nodes.\n");
    495 //          return result;
    496 //      }
    497 
    498 //      // Get the parameters of the request
    499 //      Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    500 //      if (param_list == null) {
    501 //          System.err.println("GS3Retrieve Error: DocumentStructureRetrieve request had no paramList.");
    502 //          return result;  // Return the empty result
    503 //      }
    504 
    505 //      // the type of info required
    506 //      boolean want_structure = false;
    507 //      boolean want_info = false;
    508 
    509 //      Vector info_types=new Vector();
    510 //      // The document structure information desired
    511 //      boolean want_ancestors = false;
    512 //      boolean want_parent = false;
    513 //      boolean want_siblings = false;
    514 //      boolean want_children = false;
    515 //      boolean want_descendants = false;
    516 
    517 //      boolean want_entire_structure = false;
    518 //      // Process the request parameters
    519 //      NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
    520 //      for (int i=0; i<params.getLength();i++) {
    521        
    522 //          Element param = (Element)params.item(i);
    523 //          String p_name = param.getAttribute(GSXML.NAME_ATT);
    524 //          String p_value = GSXML.getValue(param);
    525 //          // Identify the structure information desired
    526 //          if (p_name.equals(STRUCT_PARAM)) {
    527 //          want_structure = true;
    528        
    529 //          // This is NOT locale sensitive
    530 //          if (p_value.equals(STRUCT_ANCESTORS))
    531 //              want_ancestors = true;
    532 //          else if (p_value.equals(STRUCT_PARENT))
    533 //              want_parent = true;
    534 //          else if (p_value.equals(STRUCT_SIBS))
    535 //              want_siblings = true;
    536 //          else if (p_value.equals(STRUCT_CHILDREN))
    537 //              want_children = true;
    538 //          else if (p_value.equals(STRUCT_DESCENDS))
    539 //              want_descendants = true;
    540 //          else if (p_value.equals(STRUCT_ENTIRE))
    541 //              want_entire_structure = true;
    542 //          else
    543 //              System.err.println("GS3Retrieve Warning: Unknown value \"" + p_value + "\".");
    544 //          } else if (p_name.equals(INFO_PARAM)) {
    545 //          want_info = true;
    546 //          info_types.add(p_value);
    547 //          }
    548 //      }
    549 
    550 //      // Make sure there is no repeated information
    551 //      if (want_ancestors)
    552 //          want_parent = false;
    553 //      if (want_descendants)
    554 //          want_children = false;
    555    
    556    
    557    
    558 //      Element doc_list = this.doc.createElement(node_name+GSXML.LIST_MODIFIER);
    559 //      result.appendChild(doc_list);
    560    
    561 //      // Get the documents
    562 //      String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
    563 //                                  GSXML.NODE_ID_ATT);
    564 //      for (int i = 0; i < doc_ids.length; i++) {
    565 //          String doc_id = doc_ids[i];
    566        
    567 //          if (OID.needsTranslating(doc_id)) {
    568 //          doc_id = this.gdbm_src.translateOID(doc_id);
    569 //          }
    570 
    571 //          // Add the document to the list
    572 //          Element doc = this.doc.createElement(node_name);
    573 //          doc_list.appendChild(doc);
    574 //          doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
     468    protected Element processClassifierBrowse(Element request) {
     469    return genericStructureRetrieve(request, CLASSIFIER);
     470    }
     471
     472    /** Retrieve the structure of a document */
     473    protected Element genericStructureRetrieve(Element request, int type)
     474    {
     475    // Create a new (empty) result message
     476    Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
     477   
     478    String node_name;
     479    String service_name;
     480    if (type==DOCUMENT) {
     481        service_name = DOCUMENT_STRUCTURE_RETRIEVE_SERVICE;
     482        node_name = GSXML.DOC_NODE_ELEM;
     483    } else {
     484        service_name = CLASSIFIER_SERVICE;
     485        node_name = GSXML.CLASS_NODE_ELEM;
     486    }
     487   
     488    result.setAttribute(GSXML.FROM_ATT, service_name);
     489    result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
     490
     491
     492    Element query_doc_list = (Element) GSXML.getChildByTagName(request, node_name+GSXML.LIST_MODIFIER);
     493    if (query_doc_list == null) {
     494        System.err.println("GS3Retrieve Error: DocumentStructureRetrieve request specified no doc nodes.\n");
     495        return result;
     496    }
     497
     498    // Get the parameters of the request
     499    Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     500    if (param_list == null) {
     501        System.err.println("GS3Retrieve Error: DocumentStructureRetrieve request had no paramList.");
     502        return result;  // Return the empty result
     503    }
     504
     505    // the type of info required
     506    boolean want_structure = false;
     507    boolean want_info = false;
     508
     509    Vector info_types=new Vector();
     510    // The document structure information desired
     511    boolean want_ancestors = false;
     512    boolean want_parent = false;
     513    boolean want_siblings = false;
     514    boolean want_children = false;
     515    boolean want_descendants = false;
     516
     517    boolean want_entire_structure = false;
     518    // Process the request parameters
     519    NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
     520    for (int i=0; i<params.getLength();i++) {
     521       
     522        Element param = (Element)params.item(i);
     523        String p_name = param.getAttribute(GSXML.NAME_ATT);
     524        String p_value = GSXML.getValue(param);
     525        // Identify the structure information desired
     526        if (p_name.equals(STRUCT_PARAM)) {
     527        want_structure = true;
     528       
     529        // This is NOT locale sensitive
     530        if (p_value.equals(STRUCT_ANCESTORS))
     531            want_ancestors = true;
     532        else if (p_value.equals(STRUCT_PARENT))
     533            want_parent = true;
     534        else if (p_value.equals(STRUCT_SIBS))
     535            want_siblings = true;
     536        else if (p_value.equals(STRUCT_CHILDREN))
     537            want_children = true;
     538        else if (p_value.equals(STRUCT_DESCENDS))
     539            want_descendants = true;
     540        else if (p_value.equals(STRUCT_ENTIRE))
     541            want_entire_structure = true;
     542        else
     543            System.err.println("GS3Retrieve Warning: Unknown value \"" + p_value + "\".");
     544        } else if (p_name.equals(INFO_PARAM)) {
     545        want_info = true;
     546        info_types.add(p_value);
     547        }
     548    }
     549
     550    // Make sure there is no repeated information
     551    if (want_ancestors)
     552        want_parent = false;
     553    if (want_descendants)
     554        want_children = false;
     555   
     556   
     557   
     558    Element doc_list = this.doc.createElement(node_name+GSXML.LIST_MODIFIER);
     559    result.appendChild(doc_list);
     560   
     561    // Get the documents
     562    String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
     563                                GSXML.NODE_ID_ATT);
     564    for (int i = 0; i < doc_ids.length; i++) {
     565        String doc_id = doc_ids[i];
     566       
     567        if (OID.needsTranslating(doc_id)) {
     568        doc_id = translateOID(doc_id);
     569        }
     570
     571        // Add the document to the list
     572        Element doc = this.doc.createElement(node_name);
     573        doc_list.appendChild(doc);
     574        doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    575575
    576576       
     
    588588//          }
    589589//          }
    590 //          if (want_structure) {
    591 //          // all structure info goes into a nodeStructure elem
    592 //          Element structure_elem = this.doc.createElement(GSXML.NODE_STRUCTURE_ELEM);
    593 //          doc.appendChild(structure_elem);
     590        if (want_structure) {
     591        // all structure info goes into a nodeStructure elem
     592        Element structure_elem = this.doc.createElement(GSXML.NODE_STRUCTURE_ELEM);
     593        doc.appendChild(structure_elem);
    594594       
    595595//          if (want_entire_structure) {
     
    601601//          }
    602602       
    603 //          // Add the requested structure information
    604 //          Element current = createDocNode(doc_id, false, false);
    605        
    606 //          //Ancestors: continually add parent nodes until the root is reached
    607 //          Element top_node = current; // the top node so far
    608 //          if (want_ancestors) {
    609 //              String current_id = doc_id;
    610 //              while (true) {
    611 //              Element parent = getParent(current_id);
    612 //              if (parent == null)
    613 //                  break;
     603        // Add the requested structure information
     604        Element current = createDocNode(doc_id, false, false);
     605       
     606        //Ancestors: continually add parent nodes until the root is reached
     607        Element top_node = current; // the top node so far
     608        if (want_ancestors) {
     609            String current_id = doc_id;
     610            while (true) {
     611            Element parent = getParent(current_id);
     612            if (parent == null)
     613                break;
    614614           
    615 //              parent.appendChild(top_node);
    616 //              current_id = parent.getAttribute(GSXML.NODE_ID_ATT);
    617 //              top_node = parent;
    618 //              }
    619 //          }
    620 //          // Parent: get the parent of the selected node
    621 //          if (want_parent) {
    622 //              Element parent = getParent(doc_id);
    623 //              if (parent != null) {
    624 //              parent.appendChild(current);
    625 //              top_node = parent;
    626 //              }
    627 //          }
    628 
    629        
    630 //          // now the top node is the root of the structure
    631 //          structure_elem.appendChild(top_node);
    632        
    633 //          //Siblings: get the other descendants of the selected node's parent
     615            parent.appendChild(top_node);
     616            current_id = parent.getAttribute(GSXML.NODE_ID_ATT);
     617            top_node = parent;
     618            }
     619        }
     620        // Parent: get the parent of the selected node
     621        if (want_parent) {
     622            Element parent = getParent(doc_id);
     623            if (parent != null) {
     624            parent.appendChild(current);
     625            top_node = parent;
     626            }
     627        }
     628
     629       
     630        // now the top node is the root of the structure
     631        structure_elem.appendChild(top_node);
     632       
     633        //Siblings: get the other descendants of the selected node's parent
    634634//          if (want_siblings) {
    635635//              Element parent = (Element)current.getParentNode(); // this may be the structure element if there has been no request for parents or ancestors
     
    640640//          }
    641641       
    642 //          // Children: get the descendants, but only one level deep
    643 //          if (want_children)
    644 //              addDescendants(current, doc_id, false);
    645 //          // Descendants: recursively get every descendant of the selected node
    646 //          if (want_descendants)
    647 //              addDescendants(current, doc_id, true);
    648 //          } // if want structure
    649 //      } // for each doc
    650 //      return result;
    651 //      }
     642        // Children: get the descendants, but only one level deep
     643        if (want_children)
     644            addDescendants(current, doc_id, type, false);
     645        // Descendants: recursively get every descendant of the selected node
     646        if (want_descendants)
     647            addDescendants(current, doc_id, type, true);
     648        } // if want structure
     649    } // for each doc
     650    return result;
     651    }
    652652
    653653
     
    656656    }
    657657
    658 //       protected Element processClassifierBrowseMetadataRetrieve(Element request) {
    659 //      return genericMetadataRetrieve(request, CLASSIFIER);
    660 //      }
     658    protected Element processClassifierBrowseMetadataRetrieve(Element request) {
     659    return genericMetadataRetrieve(request, CLASSIFIER);
     660    }
    661661   
    662662   
     
    751751            String metadata = (String) metadata_list.get(m);
    752752            System.out.println("lookign for metadata "+metadata);
    753             String value = database.getMetadata(node_id, metadata);
    754             System.out.println("found value "+value);
    755             //String value = getMetadata(node_id, info, metadata);
    756             GSXML.addMetadata(this.doc, node_meta_list, metadata, value);
     753            String value = null;
     754            if (type==DOCUMENT) {
     755            value = database.getDocumentMetadata(node_id, metadata);
     756            } else {
     757            value = database.getClassifierMetadata(node_id, metadata);
     758            }
     759            if (value != null) {
     760            System.out.println("found value "+value);
     761            GSXML.addMetadata(this.doc, node_meta_list, metadata, value);
     762            }
    757763        }
    758764        }
Note: See TracChangeset for help on using the changeset viewer.