Changeset 4932 for trunk/gli/src/org/greenstone/gatherer/cdm/Language.java
- Timestamp:
- 2003-07-15T13:55:22+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/Language.java
r4675 r4932 6 6 * University of Waikato, New Zealand. 7 7 * 8 * <BR><BR>9 *10 8 * Author: John Thompson, Greenstone Digital Library, University of Waikato 11 9 * 12 * <BR><BR>13 *14 10 * Copyright (C) 1999 New Zealand Digital Library Project 15 *16 * <BR><BR>17 11 * 18 12 * This program is free software; you can redistribute it and/or modify … … 21 15 * (at your option) any later version. 22 16 * 23 * <BR><BR>24 *25 17 * This program is distributed in the hope that it will be useful, 26 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 27 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 20 * GNU General Public License for more details. 29 *30 * <BR><BR>31 21 * 32 22 * You should have received a copy of the GNU General Public License … … 35 25 *######################################################################## 36 26 */ 37 38 39 40 41 42 43 27 package org.greenstone.gatherer.cdm; 44 28 /************************************************************************************** 45 * Title: Gatherer46 * Description: The Gatherer: a tool for gathering and enriching a digital collection.47 * Copyright: Copyright (c) 200148 * Company: The University of Waikato49 29 * Written: 08/05/02 50 30 * Revised: 17/11/02 - Commented 31 * 07/07/03 - DOM support 51 32 **************************************************************************************/ 52 33 import org.greenstone.gatherer.cdm.CollectionConfiguration; 34 import org.greenstone.gatherer.cdm.CollectionDesignManager; 35 import org.greenstone.gatherer.cdm.DOMProxyListEntry; 36 import org.greenstone.gatherer.msm.MSMUtils; 37 import org.w3c.dom.*; 53 38 /** A pretty unexciting extension of a two character string, in that it has a field which details if its the default language. 54 39 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 56 41 */ 57 42 public class Language 58 implements Comparable { 59 /** Is this language the default one. */ 60 private boolean default_language = false; 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; 61 48 /** The name of this language. */ 62 49 private String name = null; 63 /** The two character code for this language. */ 64 private String value = null; 65 /** Constructor. 66 * @param value A <strong>String</strong> representing the code for this language. 67 * @param name A <strong>String</strong> representing the name of this language. 68 * @param default_language A <i>boolean</i> which is <i>true</i> if this language is the default one. 69 */ 70 public Language(String value, String name, boolean default_language) { 71 this.default_language = default_language; 72 this.name = name; 73 this.value = value.substring(0, 2); 50 51 public Language() { 74 52 } 75 /** Copy constructor. 76 * @param language The <strong>Language</strong> we want to copy. 77 */ 78 public Language(Language language) { 79 this.default_language = language.isDefault(); 80 this.name = language.toString(); 81 this.value = language.getCode(); 53 54 public Language(Element element) { 55 this.element = element; 82 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 83 67 /** Method to compare two languages for ordering purposes. 84 * @param object The other language as an <strong>Object</strong>. 85 * @return An <i>int</i> which indicates order using the same values as in String.compareTo(). 86 * @see java.lang.String#compareTo 87 */ 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 */ 88 71 public int compareTo(Object object) { 89 72 return toString().compareTo(object.toString()); 90 73 } 74 75 public DOMProxyListEntry create(Element element) { 76 return new Language(element); 77 } 78 91 79 /** Method to test for the equality of two languages. 92 93 94 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 */ 95 83 public boolean equals(Object object) { 96 if(compareTo(object) == 0) { 97 return true; 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); 98 93 } 99 return false;94 return code; 100 95 } 101 /** Method to retrieve the code of this language. 102 * @return A <strong>String</strong> representing the two letter code. 103 */ 104 public String getCode() { 105 return value; 96 97 public Element getElement() { 98 return element; 106 99 } 107 /** Method to determine if this language is the default one. 108 * @return A <i>boolean</i> which is <i>true</i> if this language is the default one. 109 */ 110 public boolean isDefault() { 111 return default_language; 100 101 public String getName() { 102 if(name == null) { 103 String code = getCode(); 104 name = CollectionDesignManager.language_manager.getLanguageName(code); 105 } 106 return name; 112 107 } 113 /** Method to set the value of default. 114 * @param value The new value of default as a <i>boolean</i>. 115 */ 116 public void setDefault(boolean value) { 117 this.default_language = default_language; 108 109 public boolean isAssigned() { 110 return (element != null && element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.TRUE_STR)); 118 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 119 135 /** Method to display the language code. 120 121 136 * @return A <strong>String</strong> representing the language code. 137 */ 122 138 public String toString() { 123 return name;139 return getName(); 124 140 } 125 141 }
Note:
See TracChangeset
for help on using the changeset viewer.