Ignore:
Timestamp:
2003-07-15T13:55:22+12:00 (21 years ago)
Author:
jmt12
Message:

Major CDM rewrite so it uses DOM.

File:
1 edited

Legend:

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

    r4675 r4932  
    66 * University of Waikato, New Zealand.
    77 *
    8  * <BR><BR>
    9  *
    108 * Author: John Thompson, Greenstone Digital Library, University of Waikato
    119 *
    12  * <BR><BR>
    13  *
    1410 * Copyright (C) 1999 New Zealand Digital Library Project
    15  *
    16  * <BR><BR>
    1711 *
    1812 * This program is free software; you can redistribute it and/or modify
     
    2115 * (at your option) any later version.
    2216 *
    23  * <BR><BR>
    24  *
    2517 * This program is distributed in the hope that it will be useful,
    2618 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2719 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2820 * GNU General Public License for more details.
    29  *
    30  * <BR><BR>
    3121 *
    3222 * You should have received a copy of the GNU General Public License
     
    3525 *########################################################################
    3626 */
    37 
    38  
    39 
    40 
    41 
    42 
    4327package org.greenstone.gatherer.cdm;
    4428/**************************************************************************************
    45  * Title:        Gatherer
    46  * Description:  The Gatherer: a tool for gathering and enriching a digital collection.
    47  * Copyright:    Copyright (c) 2001
    48  * Company:      The University of Waikato
    4929 * Written:      08/05/02
    5030 * Revised:      17/11/02 - Commented
     31 *               07/07/03 - DOM support
    5132 **************************************************************************************/
    52 
     33import org.greenstone.gatherer.cdm.CollectionConfiguration;
     34import org.greenstone.gatherer.cdm.CollectionDesignManager;
     35import org.greenstone.gatherer.cdm.DOMProxyListEntry;
     36import org.greenstone.gatherer.msm.MSMUtils;
     37import org.w3c.dom.*;
    5338/** A pretty unexciting extension of a two character string, in that it has a field which details if its the default language.
    5439* @author John Thompson, Greenstone Digital Library, University of Waikato
     
    5641*/
    5742public class Language
    58     implements Comparable {
    59     /** Is this language the default one. */
    60     private boolean default_language = false;
     43    implements Comparable, DOMProxyListEntry {
     44    /** The Element this language entry is based upon. */
     45    private Element element = null;
     46    /** The two character code for this language. */
     47    private String code = null;
    6148    /** The name of this language. */
    6249    private String name = null;
    63     /** The two character code for this language. */
    64     private String value = null;
    65     /** Constructor.
    66      * @param value A <strong>String</strong> representing the code for this language.
    67      * @param name A <strong>String</strong> representing the name of this language.
    68      * @param default_language A <i>boolean</i> which is <i>true</i> if this language is the default one.
    69       */
    70     public Language(String value, String name, boolean default_language) {
    71     this.default_language = default_language;
    72     this.name = name;
    73     this.value = value.substring(0, 2);
     50 
     51    public Language() {
    7452    }
    75     /** Copy constructor.
    76       * @param language The <strong>Language</strong> we want to copy.
    77       */
    78     public Language(Language language) {
    79     this.default_language = language.isDefault();
    80     this.name = language.toString();
    81     this.value = language.getCode();
     53
     54    public Language(Element element) {
     55    this.element = element;
    8256    }
     57
     58    /** Constructor for a brand new language. */
     59    public Language(String code) {
     60    this.code = code;
     61    // Create the new element
     62    element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.LANGUAGE_ELEMENT);
     63    element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, code);
     64    element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.TRUE_STR);
     65    }
     66
    8367    /** Method to compare two languages for ordering purposes.
    84       * @param object The other language as an <strong>Object</strong>.
    85       * @return An <i>int</i> which indicates order using the same values as in String.compareTo().
    86       * @see java.lang.String#compareTo
    87       */
     68     * @param object the other language as an Object
     69     * @return an int which indicates the order between this language and the given one: < 0, 0 or > 0 for before, equal to or after respectively
     70     */
    8871    public int compareTo(Object object) {
    8972    return toString().compareTo(object.toString());
    9073    }
     74
     75    public DOMProxyListEntry create(Element element) {
     76    return new Language(element);
     77    }
     78
    9179    /** Method to test for the equality of two languages.
    92       * @param object The other language as an <strong>Object</strong>.
    93       * @return <i>true</i> if the languages are equal, <i>false</i> otherwise.
    94       */
     80     * @param object The other language as an <strong>Object</strong>.
     81     * @return <i>true</i> if the languages are equal, <i>false</i> otherwise.
     82     */
    9583    public boolean equals(Object object) {
    96     if(compareTo(object) == 0) {
    97         return true;
     84    return (compareTo(object) == 0);
     85    }
     86
     87    /** Method to retrieve the code of this language.
     88     * @return A <strong>String</strong> representing the two letter code.
     89     */
     90    public String getCode() {
     91    if(code == null && element != null) {
     92        code = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
    9893    }
    99     return false;
     94    return code;
    10095    }
    101     /** Method to retrieve the code of this language.
    102       * @return A <strong>String</strong> representing the two letter code.
    103       */
    104     public String getCode() {
    105     return value;
     96
     97    public Element getElement() {
     98    return element;
    10699    }
    107     /** Method to determine if this language is the default one.
    108       * @return A <i>boolean</i> which is <i>true</i> if this language is the default one.
    109       */
    110     public boolean isDefault() {
    111     return default_language;
     100
     101    public String getName() {
     102    if(name == null) {
     103        String code = getCode();
     104        name = CollectionDesignManager.language_manager.getLanguageName(code);
     105    }
     106    return name;
    112107    }
    113     /** Method to set the value of default.
    114       * @param value The new value of default as a <i>boolean</i>.
    115       */
    116     public void setDefault(boolean value) {
    117     this.default_language = default_language;
     108
     109    public boolean isAssigned() {
     110    return (element != null && element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.TRUE_STR));
    118111    }
     112
     113    public void setAssigned(boolean value) {
     114    if(element != null) {
     115        element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (value ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
     116    }
     117    }
     118
     119    public void setCode(String new_code) {
     120    code = new_code;
     121    // Set element
     122    if(element != null) {
     123        element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, new_code);
     124    }
     125    // Reset name
     126    name = null;
     127    }
     128
     129    public void setElement(Element new_element) {
     130    element = new_element;
     131    code = null;
     132    name = null;
     133    }
     134
    119135    /** Method to display the language code.
    120       * @return A <strong>String</strong> representing the language code.
    121       */
     136     * @return A <strong>String</strong> representing the language code.
     137     */
    122138    public String toString() {
    123     return name;
     139    return getName();
    124140    }
    125141}
Note: See TracChangeset for help on using the changeset viewer.