Changeset 20438


Ignore:
Timestamp:
2009-08-30T18:38:39+12:00 (15 years ago)
Author:
kjdon
Message:

added convertMetadataElementListNames to convert from display to proper names and vice versa

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/metadata/MetadataTools.java

    r9856 r20438  
    2727package org.greenstone.gatherer.metadata;
    2828
     29import java.util.StringTokenizer;
    2930
    3031/** This class is a static class containing useful metadata functions */
     
    135136    return file_path_regexp;
    136137    }
     138
     139    static public boolean TO_DISPLAY_NAMES = true;
     140    static public boolean FROM_DISPLAY_NAMES = false;
     141
     142    static public String convertMetadataElementListNames(String value_str, boolean to_display) {
     143    if (value_str == null || value_str.length () == 0) {
     144        return value_str;
     145    }
     146   
     147    // final true arg to return delims as tokens
     148    StringTokenizer string_tokenizer = new StringTokenizer (value_str, ",;/", true);
     149    StringBuffer value_buffer = new StringBuffer ();
     150    while (string_tokenizer.hasMoreElements ()) {
     151      String raw_token = (String) string_tokenizer.nextElement ();
     152      String token = raw_token.trim ();
     153      boolean modified_token = false;
     154      // not a delimiter token
     155      if (!raw_token.equals(",") && !raw_token.equals(";") && !raw_token.equals("/")) {
     156      MetadataElement meta_elem = null;
     157      if (to_display) {
     158         meta_elem = getMetadataElementWithName(token);
     159         if (meta_elem !=null) {
     160         token = meta_elem.getDisplayName();
     161         modified_token = true;
     162         }
     163      } else {
     164          meta_elem = getMetadataElementWithDisplayName(token);
     165         
     166          if (meta_elem != null) {
     167          token = meta_elem.getFullName ();
     168          modified_token = true;
     169          }
     170      }
     171      }
     172      if (modified_token) {
     173    value_buffer.append (token);
     174      } else {
     175    // we may have had whitespace etc that was part of the string
     176    value_buffer.append (raw_token);
     177      }
     178    }
     179   
     180   
     181    if(value_buffer.length () == 0) {
     182      return "";
     183    }
     184    return value_buffer.toString();
     185    }
     186 
     187
    137188}
     189
Note: See TracChangeset for help on using the changeset viewer.