Changeset 12277


Ignore:
Timestamp:
2006-07-24T11:26:11+12:00 (18 years ago)
Author:
kjdon
Message:

Language can now have more than one lang code associated with it. getCode or toString return comma separated lists

File:
1 edited

Legend:

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

    r9561 r12277  
    2727package org.greenstone.gatherer.cdm;
    2828
    29 
     29import java.util.ArrayList;
    3030import org.w3c.dom.*;
    3131
     
    3838    /** The Element this language entry is based upon. */
    3939    private Element element = null;
    40     /** The two character code for this language. */
     40    /** A comma separated list of two character codes */
    4141    private String code = null;
    42     /** The name of this language. */
     42    /** A comma separated list of language names */
    4343    private String name = null;
    4444 
     
    5757    element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, code);
    5858    element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.TRUE_STR);
     59    }
     60
     61    /** Constructor which takes an ArrayList of codes */
     62    public Language(ArrayList codes) {
     63    StringBuffer code_str = new StringBuffer();
     64    boolean first = true;
     65    for (int i=0; i<codes.size(); i++) {
     66        if (!first) {
     67        code_str.append(",");
     68        } else {
     69        first = false;
     70        }
     71        code_str.append(codes.get(i));
     72    }
     73    this.code = code_str.toString();
     74    element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.LANGUAGE_ELEMENT);
     75    element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, code);
     76    element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.TRUE_STR);
     77   
    5978    }
    6079
     
    7695     */
    7796    public boolean equals(Object object) {
    78     //return (compareTo(object) == 0);
    7997    // two langs are equal if their codes are equal
    8098    if (object instanceof Language) {
    8199        return getCode().equals(((Language)object).getCode());
     100    } else if (object instanceof String) {
     101        return getCode().equals((String)object);
    82102    }
    83103    return false;
     
    100120    public String getName() {
    101121    if(name == null) {
    102         String code = getCode();
    103         name = CollectionDesignManager.language_manager.getLanguageName(code);
     122        String code_str = getCode();
     123        String [] codes = code_str.split(",");
     124        StringBuffer name_str = new StringBuffer();
     125        boolean first = true;
     126        for (int i=0; i<codes.length; i++) {
     127        if (!first) {
     128            name_str.append(",");
     129        } else {
     130            first = false;
     131        }
     132        name_str.append(CollectionDesignManager.language_manager.getLanguageName(codes[i]));
     133        }
     134        name = name_str.toString();
    104135    }
    105136    return name;
Note: See TracChangeset for help on using the changeset viewer.