[4932] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
| 5 | * library suite from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 9 | *
|
---|
| 10 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | *########################################################################
|
---|
| 26 | */
|
---|
| 27 | package org.greenstone.gatherer.cdm;
|
---|
[5590] | 28 |
|
---|
[7997] | 29 |
|
---|
[4932] | 30 | import org.w3c.dom.*;
|
---|
[5590] | 31 |
|
---|
[4932] | 32 | /** A pretty unexciting extension of a two character string, in that it has a field which details if its the default language.
|
---|
| 33 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 34 | * @version 2.1
|
---|
| 35 | */
|
---|
| 36 | public class Language
|
---|
| 37 | implements Comparable, DOMProxyListEntry {
|
---|
| 38 | /** The Element this language entry is based upon. */
|
---|
| 39 | private Element element = null;
|
---|
| 40 | /** The two character code for this language. */
|
---|
| 41 | private String code = null;
|
---|
| 42 | /** The name of this language. */
|
---|
| 43 | private String name = null;
|
---|
| 44 |
|
---|
| 45 | public Language() {
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public Language(Element element) {
|
---|
| 49 | this.element = element;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /** Constructor for a brand new language. */
|
---|
| 53 | public Language(String code) {
|
---|
| 54 | this.code = code;
|
---|
| 55 | // Create the new element
|
---|
| 56 | element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.LANGUAGE_ELEMENT);
|
---|
| 57 | element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, code);
|
---|
| 58 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.TRUE_STR);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /** Method to compare two languages for ordering purposes.
|
---|
| 62 | * @param object the other language as an Object
|
---|
| 63 | * @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
|
---|
| 64 | */
|
---|
| 65 | public int compareTo(Object object) {
|
---|
| 66 | return toString().compareTo(object.toString());
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public DOMProxyListEntry create(Element element) {
|
---|
| 70 | return new Language(element);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /** Method to test for the equality of two languages.
|
---|
| 74 | * @param object The other language as an <strong>Object</strong>.
|
---|
| 75 | * @return <i>true</i> if the languages are equal, <i>false</i> otherwise.
|
---|
| 76 | */
|
---|
| 77 | public boolean equals(Object object) {
|
---|
[9561] | 78 | //return (compareTo(object) == 0);
|
---|
| 79 | // two langs are equal if their codes are equal
|
---|
| 80 | if (object instanceof Language) {
|
---|
| 81 | return getCode().equals(((Language)object).getCode());
|
---|
| 82 | }
|
---|
| 83 | return false;
|
---|
[4932] | 84 | }
|
---|
| 85 |
|
---|
| 86 | /** Method to retrieve the code of this language.
|
---|
| 87 | * @return A <strong>String</strong> representing the two letter code.
|
---|
| 88 | */
|
---|
| 89 | public String getCode() {
|
---|
| 90 | if(code == null && element != null) {
|
---|
| 91 | code = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
|
---|
| 92 | }
|
---|
| 93 | return code;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public Element getElement() {
|
---|
| 97 | return element;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public String getName() {
|
---|
| 101 | if(name == null) {
|
---|
| 102 | String code = getCode();
|
---|
| 103 | name = CollectionDesignManager.language_manager.getLanguageName(code);
|
---|
| 104 | }
|
---|
| 105 | return name;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public boolean isAssigned() {
|
---|
| 109 | return (element != null && element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.TRUE_STR));
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | public void setAssigned(boolean value) {
|
---|
| 113 | if(element != null) {
|
---|
| 114 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (value ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | public void setCode(String new_code) {
|
---|
| 119 | code = new_code;
|
---|
| 120 | // Set element
|
---|
| 121 | if(element != null) {
|
---|
| 122 | element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, new_code);
|
---|
| 123 | }
|
---|
| 124 | // Reset name
|
---|
| 125 | name = null;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public void setElement(Element new_element) {
|
---|
| 129 | element = new_element;
|
---|
| 130 | code = null;
|
---|
| 131 | name = null;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /** Method to display the language code.
|
---|
| 135 | * @return A <strong>String</strong> representing the language code.
|
---|
| 136 | */
|
---|
| 137 | public String toString() {
|
---|
| 138 | return getName();
|
---|
| 139 | }
|
---|
| 140 | }
|
---|