Changeset 28987

Show
Ignore:
Timestamp:
17.04.2014 13:17:33 (5 years ago)
Author:
kjdon
Message:

some tidying up. have started work on new metadata format stuff, but its not finished yet.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java

    r28966 r28987  
    4747  /** The unique  repository identifier */ 
    4848  protected String repository_id = null; 
    49      
    50   /** a converter class to parse XML and create Docs */ 
    51   protected XMLConverter converter=null; 
    52    
     49       
    5350  /** the configure file of this receptionist passed from the oai servlet. */ 
    5451  protected Element oai_config = null; 
     
    7875  /** store the super coll elements for convenience */ 
    7976  HashMap<String, Element> super_coll_data = null; 
     77  /** store the metadata formats ??????*/ 
    8078  /** The identify response */ 
    8179  protected Element identify_response = null; 
     
    8684 
    8785  public OAIReceptionist() { 
    88     this.converter = new XMLConverter(); 
     86 
    8987  } 
    9088   
     
    199197 
    200198    // go through and store a list of collection names for convenience 
    201     // also create a 'to' attribute 
     199    // also create a 'to' attribute for the next request to the MR, which 
     200    // is a ListSets request to each collection 
    202201    Node child = this.collection_list.getFirstChild(); 
    203202    if (child == null) { 
     
    239238    // send to MR 
    240239    msg_node = mr.process(message); 
    241     logger.error(this.converter.getPrettyString(msg_node)); 
     240    logger.error(XMLConverter.getPrettyString(msg_node)); 
    242241    NodeList response_list =  ((Element)msg_node).getElementsByTagName(GSXML.RESPONSE_ELEM); 
    243242    for (int c=0; c<response_list.getLength(); c++) { 
     
    267266          this.super_coll_map.put(set_spec, subcolls); 
    268267          // the first time a supercoll is mentioned, add into the set list 
    269           logger.error("finding the set info "+this.converter.getPrettyString(this.super_coll_data.get(set_spec))); 
     268          logger.error("finding the set info "+XMLConverter.getPrettyString(this.super_coll_data.get(set_spec))); 
    270269          listsets_element.appendChild(GSXML.duplicateWithNewName(listsets_doc, this.super_coll_data.get(set_spec), OAIXML.SET, true)); 
    271270        } 
     
    295294 
    296295    Element response = (Element) this.mr.process(mr_request_message); 
    297     logger.error("configure response = "+this.converter.getPrettyString(response)); 
     296    logger.error("configure response = "+XMLConverter.getPrettyString(response)); 
    298297  } 
    299298  /** process using strings - just calls process using Elements */ 
    300299  public String process(String xml_in) { 
    301300     
    302     Node message_node = this.converter.getDOM(xml_in); 
     301    Node message_node = XMLConverter.getDOM(xml_in); 
    303302    Node page = process(message_node); 
    304     return this.converter.getString(page); 
     303    return XMLConverter.getString(page); 
    305304  } 
    306305 
     
    322321 
    323322    Element message = GSXML.nodeToElement(message_node); 
    324     logger.error(this.converter.getString(message)); 
     323    logger.error(XMLConverter.getString(message)); 
    325324 
    326325    // check that its a correct message tag 
     
    593592      Element result = (Element)mr.process(mr_msg); 
    594593      logger.error(verb+ " result for coll "+current_coll); 
    595       logger.error(this.converter.getPrettyString(result)); 
     594      logger.error(XMLConverter.getPrettyString(result)); 
    596595      if (result == null) { 
    597596    logger.info("message router returns null"); 
     
    725724  } 
    726725 
    727  
    728   // method exclusively used by doListRecords/doListIdentifiers 
    729   private void getRecords(Element verb_elem, NodeList list, int start_point, int end_point) { 
    730     for (int i=start_point; i<end_point; i++) { 
    731       verb_elem.appendChild(verb_elem.getOwnerDocument().importNode(list.item(i), true)); 
    732     } 
    733   } 
    734726  private Element collectAll(Element result, Element msg, String verb, String elem_name) { 
    735727    if(result == null) { 
     
    763755    //if the verb is ListMetadataFormats, there could be only one parameter: identifier 
    764756    //, or there is no parameter; otherwise it is an error 
    765     //logger.info("" + this.converter.getString(msg)); 
     757    //logger.info("" + XMLConverter.getString(msg)); 
    766758     
    767759    NodeList params = GSXML.getChildrenByTagName(req, GSXML.PARAM_ELEM); 
     
    777769 
    778770      Element list_metadata_formats = lmf_doc.createElement(OAIXML.LIST_METADATA_FORMATS); 
    779        
    780       Element format_list = (Element)GSXML.getChildByTagName(oai_config, OAIXML.LIST_METADATA_FORMATS); 
    781       if(format_list == null) { 
    782     logger.error("OAIConfig.xml must contain the supported metadata formats"); 
    783     // TODO this is internal error, what to do??? 
    784     return getMessage(lmf_doc, list_metadata_formats); 
    785       } 
    786       NodeList formats = format_list.getElementsByTagName(OAIXML.METADATA_FORMAT); 
     771      // get all the formats out of oai_config 
     772      NodeList formats = oai_config.getElementsByTagName(OAIXML.METADATA_FORMAT); 
     773      if (formats.getLength() ==0) { 
     774        logger.error("OAIConfig.xml must contain the supported metadata formats"); 
     775        // TODO this is internal error, what to do??? 
     776        return getMessage(lmf_doc, list_metadata_formats); 
     777      } 
     778     
    787779      for(int i=0; i<formats.getLength(); i++) { 
    788780    Element meta_fmt = lmf_doc.createElement(OAIXML.METADATA_FORMAT); 
     
    794786    list_metadata_formats.appendChild(meta_fmt); 
    795787      } 
    796       return getMessage(lmf_doc, list_metadata_formats); 
    797        
     788      this.listmetadataformats_response = getMessage(lmf_doc, list_metadata_formats); 
     789      return this.listmetadataformats_response; 
    798790       
    799791    }  
     
    820812    identifier = param.getAttribute(GSXML.VALUE_ATT); 
    821813    // the identifier is in the form: <coll_name>:<OID> 
    822     // so it must contain at least two ':' characters 
    823     String[] strs = identifier.split(":"); 
    824     if(strs == null || strs.length < 2) { 
    825       // the OID may also contain ':' 
     814    // so it must contain at least one ':' characters  
     815    // (the oid itself may contain : chars) 
     816    String[] strs = identifier.split(":", 2); 
     817    if(strs.length != 2) { 
    826818      logger.error("identifier is not in the form coll:id" + identifier); 
    827819      return OAIXML.createErrorMessage(OAIXML.ID_DOES_NOT_EXIST, ""); 
     
    830822    // send request to message router 
    831823    // get the names 
    832     strs = splitNames(identifier); 
    833     if(strs == null || strs.length < 2) { 
    834       logger.error("identifier is not in the form coll:id" + identifier); 
    835       return OAIXML.createErrorMessage(OAIXML.ID_DOES_NOT_EXIST, ""); 
    836     } 
    837     //String name_of_site = strs[0]; 
    838824    String coll_name = strs[0]; 
    839825    String oid = strs[1]; 
    840826 
    841     //re-organize the request element 
    842     // reset the 'to' attribute 
     827    Document msg_doc = XMLConverter.newDOM(); 
     828    Element message = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
    843829    String verb = req.getAttribute(GSXML.TO_ATT); 
    844     req.setAttribute(GSXML.TO_ATT, coll_name + "/" + verb); 
    845     // reset the identifier element 
    846     param.setAttribute(GSXML.NAME_ATT, OAIXML.OID); 
    847     param.setAttribute(GSXML.VALUE_ATT, oid); 
    848  
    849     // TODO is this the best way to do this???? should we create a new request??? 
    850     Element message = req.getOwnerDocument().createElement(GSXML.MESSAGE_ELEM); 
    851     message.appendChild(req); 
     830    String new_to = coll_name + "/" + verb; 
     831    Element request = GSXML.createBasicRequest(msg_doc, "oai???", new_to, null); 
     832    message.appendChild(request); 
     833    // add the id param 
     834    GSXML.addParameterToList(request, OAIXML.OID, oid); 
     835 
    852836    //Now send the request to the message router to process 
    853837    Node result_node = mr.process(message); 
     
    861845    Element original_element = (Element)GSXML.getChildByTagName(oai_config, element_name); 
    862846    if(original_element != null) { 
    863       copyNode(to_elem, original_element); 
    864     } 
    865   } 
    866  
    867   private void copyNode(Element to_elem, Node original_element) { 
    868     to_elem.appendChild(to_elem.getOwnerDocument().importNode(original_element, true)); 
    869  
    870   } 
     847      GSXML.copyNode(to_elem, original_element); 
     848    } 
     849  } 
     850 
    871851 
    872852  private Element doIdentify() { 
     
    894874    } 
    895875    for (int i=0; i<num_admin; i++) { 
    896       copyNode(identify, admin_emails.item(i)); 
     876      GSXML.copyNode(identify, admin_emails.item(i)); 
    897877    } 
    898878 
     
    927907    description.appendChild(gsdl); 
    928908    for (int m = 0; m<meta.getLength(); m++) { 
    929       copyNode(gsdl, meta.item(m)); 
     909      GSXML.copyNode(gsdl, meta.item(m)); 
    930910    } 
    931911     
     
    934914    this.identify_response = identify; 
    935915    return getMessage(doc, identify); 
    936   } 
    937   //split setSpec (site_name:coll_name) into an array of strings 
    938   //It has already been checked that the set_spec contains at least one ':' 
    939   private String[] splitSetSpec(String set_spec) { 
    940     logger.info(set_spec); 
    941     String[] strs = new String[2]; 
    942     int colon_index = set_spec.indexOf(":"); 
    943     strs[0] = set_spec.substring(0, colon_index); 
    944     strs[1] = set_spec.substring(colon_index + 1); 
    945     return strs; 
    946916  } 
    947917  /** split the identifier into <collection + OID> as an array  
    948918      It has already been checked that the 'identifier' contains at least one ':' 
    949919  */ 
    950   private String[] splitNames(String identifier) { 
    951     logger.info(identifier); 
    952     String [] strs = new String[2]; 
    953     int first_colon = identifier.indexOf(":"); 
    954     if(first_colon == -1) { 
    955       return null; 
    956     } 
    957     strs[0] = identifier.substring(0, first_colon); 
    958     strs[1] = identifier.substring(first_colon + 1); 
    959     return strs; 
    960   } 
     920  // private String[] splitNames(String identifier) { 
     921  //   logger.info(identifier); 
     922  //   String [] strs = new String[2]; 
     923  //   int first_colon = identifier.indexOf(":"); 
     924  //   if(first_colon == -1) { 
     925  //     return null; 
     926  //   } 
     927  //   strs[0] = identifier.substring(0, first_colon); 
     928  //   strs[1] = identifier.substring(first_colon + 1); 
     929  //   return strs; 
     930  // } 
    961931  /** validate if the specified metadata prefix value is supported by the repository 
    962932   *  by checking it in the OAIConfig.xml 
     
    1007977 
    1008978    // get the names 
    1009     String[] strs = splitNames(identifier); 
     979    String[] strs = identifier.split(":", 2); 
    1010980    if(strs == null || strs.length < 2) { 
    1011981      logger.error("identifier is not in the form coll:id" + identifier);