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

Last change on this file since 4932 was 4932, checked in by jmt12, 21 years ago

Major CDM rewrite so it uses DOM.

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