Ignore:
Timestamp:
2004-10-13T14:48:20+13:00 (20 years ago)
Author:
mdewsnip
Message:

Finally committing the (many) changes to the GLI to use the new metadata code... I hope this doesn't have too many bugs in it and committing it now doesn't stuff anyone up! (Katherine said I could commit it, so blame her if anything goes wrong).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/Argument.java

    r8243 r8313  
    3939import org.greenstone.gatherer.collection.Collection;
    4040import org.greenstone.gatherer.collection.CollectionManager;
    41 import org.greenstone.gatherer.msm.ElementWrapper;
     41import org.greenstone.gatherer.metadata.MetadataElement;
     42import org.greenstone.gatherer.metadata.MetadataTools;
    4243import org.greenstone.gatherer.util.StaticStrings;
    4344import org.greenstone.gatherer.util.Utility;
     
    246247     * @see org.greenstone.gatherer.collection.CollectionManager#getCollection
    247248     */
    248     public String getValue() {
    249     String value = null;
    250     // Only assigned arguments have values.
    251     if(element != null) {
    252         value = XMLTools.getValue(element);
    253         // We may have to retrieve the language dependant string for a metadata element
    254         if(type == METADATUM) {
    255         ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(value);
    256         if(element_wrapper != null) {
    257             value = element_wrapper.getName();
    258         }
    259         }
    260     }
    261     return value;
    262     }
    263 
    264     /** Retrieve the vector of values.
    265      * @return an ArrayList of values
    266      * @see org.greenstone.gatherer.Gatherer#c_man
    267      * @see org.greenstone.gatherer.collection.CollectionManager#getCollection
    268      */
    269     public ArrayList getValues() {
    270     ArrayList values = new ArrayList();
    271     // Only assigned arguments have values.
    272     if(element != null) {
    273         String value = XMLTools.getValue(element);
    274         StringTokenizer tokenizer = new StringTokenizer(value, ",");
    275         while(tokenizer.hasMoreTokens()) {
    276         String token = tokenizer.nextToken();
    277         if(type == METADATA) {
    278             ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(token);
    279             if(element_wrapper != null) {
    280             token = element_wrapper.toString();
    281             }
    282         }
    283         values.add(token);
    284         }
    285     }
    286     return values;
    287     }
     249    public String getValue()
     250    {
     251    // Only assigned arguments have values.
     252    if (element == null) {
     253        return null;
     254    }
     255
     256    return XMLTools.getValue(element);
     257    }
     258
    288259
    289260    /** Method to determine if this argument has been assigned.
     
    509480     * @see org.greenstone.gatherer.util.StaticStrings#SPEECH_CHARACTER
    510481     */
    511     public String toString() {
     482    public String toString()
     483    {
    512484    StringBuffer text = new StringBuffer("-");
    513     if(element != null) {
    514         if(name == null) {
    515         name = element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    516         }
    517         text.append(name);
    518         String value = XMLTools.getValue(element);
    519         if(value.length() > 0) {
    520         text.append(StaticStrings.SPACE_CHARACTER);
    521         // If the value contains a space, add speech marks
    522         if(value.indexOf(StaticStrings.SPACE_CHARACTER) != -1) {
    523             value = StaticStrings.SPEECH_CHARACTER + value + StaticStrings.SPEECH_CHARACTER;
    524         }
    525         // Tokenize the string
    526         StringTokenizer tokenizer = new StringTokenizer(value, ",");
    527         while(tokenizer.hasMoreTokens()) {
    528             String token = tokenizer.nextToken();
    529             if(type == METADATA || type == METADATUM) {
    530             ElementWrapper element_wrapper = null;
    531             // if you click on exit before saving and format statements have changed, this could be null
    532             if (Gatherer.c_man.getCollection() != null) {
    533                 element_wrapper = Gatherer.c_man.getCollection().msm.getElement(token);
    534             }
    535             if(element_wrapper != null) {
    536                 text.append(element_wrapper.toString());
    537                 element_wrapper = null;
    538             }
    539             else {
    540                 text.append(token);
    541             }
    542             }
    543             else {
    544             text.append(token);
    545             }
    546             token = null;
    547             text.append(StaticStrings.COMMA_CHARACTER);
    548         }
    549         tokenizer = null;
    550         text.deleteCharAt(text.length() - 1);
    551         }
    552         value = null;
    553     }
     485
     486    if (element == null) {
     487        return text.toString();
     488    }
     489
     490    if (name == null) {
     491        name = element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
     492    }
     493    text.append(name);
     494
     495    String value = XMLTools.getValue(element);
     496    if (value.length() == 0) {
     497        return text.toString();
     498    }
     499
     500    text.append(StaticStrings.SPACE_CHARACTER);
     501
     502//  // Handle metadata elements specially
     503//  if (type == METADATA || type == METADATUM) {
     504//      // Tokenize the string
     505//      StringTokenizer tokenizer = new StringTokenizer(value, ",");
     506//      while (tokenizer.hasMoreTokens()) {
     507//      String token = tokenizer.nextToken();
     508
     509//      MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName(token);
     510//      if (metadata_element != null) {
     511//          text.append(metadata_element.getFullName());
     512//      }
     513//      else {
     514//          text.append(token);
     515//      }
     516
     517//      if (tokenizer.hasMoreTokens()) {
     518//          text.append(StaticStrings.COMMA_CHARACTER);
     519//      }
     520//      }
     521//      return text.toString();
     522//  }
     523
     524    // If the value contains a space, add speech marks
     525    //   (Except for metadata elements, which won't have spaces when written out to collect.cfg)
     526    if (value.indexOf(StaticStrings.SPACE_CHARACTER) != -1 && !(type == METADATUM || type == METADATA)) {
     527        value = StaticStrings.SPEECH_CHARACTER + value + StaticStrings.SPEECH_CHARACTER;
     528    }
     529
     530    text.append(value);
    554531    return text.toString();
    555532    }   
Note: See TracChangeset for help on using the changeset viewer.