/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Author: John Thompson, Greenstone Digital Library, University of Waikato * * Copyright (C) 1999 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer.cdm; import org.w3c.dom.*; /** A pretty unexciting extension of a two character string, in that it has a field which details if its the default language. * @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.1 */ public class Language implements Comparable, DOMProxyListEntry { /** The Element this language entry is based upon. */ private Element element = null; /** The two character code for this language. */ private String code = null; /** The name of this language. */ private String name = null; public Language() { } public Language(Element element) { this.element = element; } /** Constructor for a brand new language. */ public Language(String code) { this.code = code; // Create the new element element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.LANGUAGE_ELEMENT); element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, code); element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.TRUE_STR); } /** Method to compare two languages for ordering purposes. * @param object the other language as an Object * @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 */ public int compareTo(Object object) { return toString().compareTo(object.toString()); } public DOMProxyListEntry create(Element element) { return new Language(element); } /** Method to test for the equality of two languages. * @param object The other language as an Object. * @return true if the languages are equal, false otherwise. */ public boolean equals(Object object) { return (compareTo(object) == 0); } /** Method to retrieve the code of this language. * @return A String representing the two letter code. */ public String getCode() { if(code == null && element != null) { code = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); } return code; } public Element getElement() { return element; } public String getName() { if(name == null) { String code = getCode(); name = CollectionDesignManager.language_manager.getLanguageName(code); } return name; } public boolean isAssigned() { return (element != null && element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.TRUE_STR)); } public void setAssigned(boolean value) { if(element != null) { element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (value ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR)); } } public void setCode(String new_code) { code = new_code; // Set element if(element != null) { element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, new_code); } // Reset name name = null; } public void setElement(Element new_element) { element = new_element; code = null; name = null; } /** Method to display the language code. * @return A String representing the language code. */ public String toString() { return getName(); } }