source: trunk/gli/src/org/greenstone/gatherer/cdm/Language.java@ 8055

Last change on this file since 8055 was 7997, checked in by mdewsnip, 20 years ago

Removed some more references to the msm package.

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