Changeset 21795


Ignore:
Timestamp:
2010-03-15T15:44:16+13:00 (11 years ago)
Author:
kjdon
Message:

some tidy up stuff, for code and output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java

    r21782 r21795  
    478478        //create the <metadata> element
    479479        //OAIXML.oai_version is read from OAIConfig.xml and its default value is "2.0"
     480    Element metadata = OAIXML.createElement(OAIXML.METADATA);
    480481        Element prfx_str_elem = OAIXML.getMetadataPrefixElement(prfx_str, OAIXML.oai_version);
    481         String[] metadata_names = getMetadataNames(metadata_format);
     482        metadata.appendChild(prfx_str_elem);
     483        String[] metadata_names = getMetadataNameMapping(metadata_format);
    482484        HashMap meta_map = getInfoByNames(info, metadata_names);
    483         ArrayList meta_list = new ArrayList(meta_map.entrySet());
    484         for (int j=0; j<meta_list.size(); j++) {
    485           Entry men = (Entry)meta_list.get(j);
    486           String meta_name = (String)men.getKey();
    487           String meta_value = (String)men.getValue();
    488           Element e = OAIXML.createElement(meta_name);
    489           GSXML.setNodeText(e, meta_value);
    490           prfx_str_elem.appendChild(e);
    491         }
    492         Element metadata = OAIXML.createElement(OAIXML.METADATA);
    493         metadata.appendChild(prfx_str_elem);
     485    if (meta_map == null) {
     486      return metadata;
     487    }
     488    ArrayList meta_list = new ArrayList(meta_map.entrySet());
     489    for (int j=0; j<meta_list.size(); j++) {
     490      Entry men = (Entry)meta_list.get(j);
     491      String meta_name = (String)men.getKey();
     492      //meta_name = meta_name.replace('.', ':'); // namespace separator should be : for oai
     493      String meta_value = (String)men.getValue();
     494      Element e = OAIXML.createElement(meta_name);
     495      GSXML.setNodeText(e, meta_value);
     496      prfx_str_elem.appendChild(e);
     497    }
     498   
    494499        return metadata;
    495500  }
     
    547552    for (int i=0; i<meta_list.getLength(); i++) {
    548553      Element metadata_format = (Element)meta_list.item(i);
    549       String[] metadata_names = getMetadataNames(metadata_format);
     554      String[] metadata_names = getMetadataNameMapping(metadata_format);
    550555      if (containsMetadata(info, metadata_names) == true) {
    551556        has_meta_format = true;
     
    574579  /** @param metadata_format - the metadataFormat element in collectionConfig.xml
    575580   */
    576   protected String[] getMetadataNames(Element metadata_format) {
    577     String[] names = null;
    578    
    579     //read the mappingList element
    580     Element mapping_list = (Element)GSXML.getChildByTagName(metadata_format, OAIXML.MAPPING_LIST);
    581     if (mapping_list == null) {
    582       logger.info("No metadata mappings are provided in collectionConfig.xml. Use the standard Dublin Core names.");
    583       names = OAIXML.getGlobalMetadataMapping(metadata_format.getAttribute(OAIXML.METADATA_PREFIX));
    584      
    585       return (names != null)? names : OAIXML.getDublinCoreNames();
    586     }
    587     NodeList mappings = GSXML.getChildrenByTagName(mapping_list, OAIXML.MAPPING);
    588     int size = mappings.getLength();
    589     if (size == 0) {
    590         logger.info("No metadata mappings are provided in collectionConfig.xml. \n Return standard DC names.");
    591         // read the standard Dublin Core metadata names
    592         return OAIXML.getDublinCoreNames();
    593     }
    594     names = new String[size];
    595     for (int i=0; i<size; i++) {
    596       names[i] = GSXML.getNodeText((Element)mappings.item(i)).trim();
    597     }
     581  protected String[] getMetadataNameMapping(Element metadata_format) {
     582 
     583    String[] names = OAIXML.getMetadataMapping(metadata_format);
     584    if (names != null) {
     585      return names;
     586    }
     587    logger.info("No metadata mappings are provided in collectionConfig.xml. Try for global mapping");
     588    names = OAIXML.getGlobalMetadataMapping(metadata_format.getAttribute(OAIXML.METADATA_PREFIX));
    598589    return names;
    599590  }
     
    691682  }
    692683  protected HashMap getInfoByNames(DBInfo info, String[] metadata_names) {
     684
     685    if (metadata_names == null) {
     686      return null;
     687    }
    693688    HashMap map = new HashMap();
    694689    boolean empty_map = true;
Note: See TracChangeset for help on using the changeset viewer.