[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 |
|
---|
[4932] | 29 | /**************************************************************************************
|
---|
| 30 | * Written: 08/05/02
|
---|
| 31 | * Revised: 17/11/02 - Commented
|
---|
| 32 | * 07/07/03 - DOM support
|
---|
| 33 | **************************************************************************************/
|
---|
| 34 | import org.greenstone.gatherer.cdm.CollectionConfiguration;
|
---|
| 35 | import org.greenstone.gatherer.cdm.CollectionDesignManager;
|
---|
| 36 | import org.greenstone.gatherer.cdm.DOMProxyListEntry;
|
---|
| 37 | import org.greenstone.gatherer.msm.MSMUtils;
|
---|
| 38 | import org.w3c.dom.*;
|
---|
[5590] | 39 |
|
---|
[4932] | 40 | /** A pretty unexciting extension of a two character string, in that it has a field which details if its the default language.
|
---|
| 41 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 42 | * @version 2.1
|
---|
| 43 | */
|
---|
| 44 | public class Language
|
---|
| 45 | implements Comparable, DOMProxyListEntry {
|
---|
| 46 | /** The Element this language entry is based upon. */
|
---|
| 47 | private Element element = null;
|
---|
| 48 | /** The two character code for this language. */
|
---|
| 49 | private String code = null;
|
---|
| 50 | /** The name of this language. */
|
---|
| 51 | private String name = null;
|
---|
| 52 |
|
---|
| 53 | public Language() {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public Language(Element element) {
|
---|
| 57 | this.element = element;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /** Constructor for a brand new language. */
|
---|
| 61 | public Language(String code) {
|
---|
| 62 | this.code = code;
|
---|
| 63 | // Create the new element
|
---|
| 64 | element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.LANGUAGE_ELEMENT);
|
---|
| 65 | element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, code);
|
---|
| 66 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.TRUE_STR);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /** Method to compare two languages for ordering purposes.
|
---|
| 70 | * @param object the other language as an Object
|
---|
| 71 | * @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
|
---|
| 72 | */
|
---|
| 73 | public int compareTo(Object object) {
|
---|
| 74 | return toString().compareTo(object.toString());
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public DOMProxyListEntry create(Element element) {
|
---|
| 78 | return new Language(element);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /** Method to test for the equality of two languages.
|
---|
| 82 | * @param object The other language as an <strong>Object</strong>.
|
---|
| 83 | * @return <i>true</i> if the languages are equal, <i>false</i> otherwise.
|
---|
| 84 | */
|
---|
| 85 | public boolean equals(Object object) {
|
---|
| 86 | return (compareTo(object) == 0);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /** Method to retrieve the code of this language.
|
---|
| 90 | * @return A <strong>String</strong> representing the two letter code.
|
---|
| 91 | */
|
---|
| 92 | public String getCode() {
|
---|
| 93 | if(code == null && element != null) {
|
---|
| 94 | code = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
|
---|
| 95 | }
|
---|
| 96 | return code;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public Element getElement() {
|
---|
| 100 | return element;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | public String getName() {
|
---|
| 104 | if(name == null) {
|
---|
| 105 | String code = getCode();
|
---|
| 106 | name = CollectionDesignManager.language_manager.getLanguageName(code);
|
---|
| 107 | }
|
---|
| 108 | return name;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | public boolean isAssigned() {
|
---|
| 112 | return (element != null && element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.TRUE_STR));
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | public void setAssigned(boolean value) {
|
---|
| 116 | if(element != null) {
|
---|
| 117 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (value ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | public void setCode(String new_code) {
|
---|
| 122 | code = new_code;
|
---|
| 123 | // Set element
|
---|
| 124 | if(element != null) {
|
---|
| 125 | element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, new_code);
|
---|
| 126 | }
|
---|
| 127 | // Reset name
|
---|
| 128 | name = null;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | public void setElement(Element new_element) {
|
---|
| 132 | element = new_element;
|
---|
| 133 | code = null;
|
---|
| 134 | name = null;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /** Method to display the language code.
|
---|
| 138 | * @return A <strong>String</strong> representing the language code.
|
---|
| 139 | */
|
---|
| 140 | public String toString() {
|
---|
| 141 | return getName();
|
---|
| 142 | }
|
---|
| 143 | }
|
---|