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

Last change on this file since 8853 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 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.w3c.dom.*;
31
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*/
36public 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) {
78 return (compareTo(object) == 0);
79 }
80
81 /** Method to retrieve the code of this language.
82 * @return A <strong>String</strong> representing the two letter code.
83 */
84 public String getCode() {
85 if(code == null && element != null) {
86 code = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
87 }
88 return code;
89 }
90
91 public Element getElement() {
92 return element;
93 }
94
95 public String getName() {
96 if(name == null) {
97 String code = getCode();
98 name = CollectionDesignManager.language_manager.getLanguageName(code);
99 }
100 return name;
101 }
102
103 public boolean isAssigned() {
104 return (element != null && element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.TRUE_STR));
105 }
106
107 public void setAssigned(boolean value) {
108 if(element != null) {
109 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (value ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
110 }
111 }
112
113 public void setCode(String new_code) {
114 code = new_code;
115 // Set element
116 if(element != null) {
117 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, new_code);
118 }
119 // Reset name
120 name = null;
121 }
122
123 public void setElement(Element new_element) {
124 element = new_element;
125 code = null;
126 name = null;
127 }
128
129 /** Method to display the language code.
130 * @return A <strong>String</strong> representing the language code.
131 */
132 public String toString() {
133 return getName();
134 }
135}
Note: See TracBrowser for help on using the repository browser.