- 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/CollectionMeta.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 /* GPL_HEADER */44 27 package org.greenstone.gatherer.cdm; 45 28 /************************************************************************************** 46 * Title: Gatherer 47 * Description: The Gatherer: a tool for gathering and enriching a digital collection. 48 * Copyright: Copyright (c) 2001 49 * Company: The University of Waikato 50 * Written: /05/02 51 * Revised: 22/08/02 Revamped, Optimized and Commented. 29 * Written: 30 * Revised: 28/06/03 - DOM support 52 31 **************************************************************************************/ 32 import org.greenstone.gatherer.Configuration; 33 import org.greenstone.gatherer.Gatherer; 34 import org.greenstone.gatherer.cdm.CollectionConfiguration; 35 import org.greenstone.gatherer.cdm.CollectionDesignManager; 36 import org.greenstone.gatherer.cdm.DOMProxyListEntry; 53 37 import org.greenstone.gatherer.cdm.Index; 54 import org.greenstone.gatherer.cdm.Language; 38 import org.greenstone.gatherer.msm.MSMUtils; 39 import org.greenstone.gatherer.util.StaticStrings; 55 40 import org.greenstone.gatherer.util.Utility; 41 import org.w3c.dom.*; 56 42 /** This class encapsulates a single collection level metadata assignment, which constitutes a name, language and value. 57 43 * @author John Thompson, Greenstone Digital Library, University of Waikato 58 * @version 2. 344 * @version 2.4 59 45 */ 60 46 public class CollectionMeta 61 implements Comparable { 62 /** A reference to the collection design manager for access to the language manager. */ 63 private CollectionDesignManager manager = null; 64 /** The language of this metadata. Should be a two letter code. */ 65 private Language language = null; 66 /** The name of the thing this metadata is assigned to, which may also refer to an Index or a Partition. */ 67 private Object name = null; 68 /** The value of this metadata. */ 69 private String value = null; 47 implements DOMProxyListEntry { 48 private Element element; 49 private String text; 50 70 51 /** Constructor. 71 * @param name The object the metadata is assigned to as an <strong>Object</strong>. 72 * @param language The language of the metadata as a <strong>Language</strong>. Should be a two letter code. 73 * @param value The value of this metadata, as a <strong>String</strong>. 74 */ 75 public CollectionMeta(CollectionDesignManager manager, Object name, Language language, String value) { 76 this.language = language; 77 this.manager = manager; 78 this.name = name; 79 this.value = value; 52 * @param element the Element from which we will determine metadata details 53 */ 54 public CollectionMeta(Element element) { 55 this.element = element; 80 56 } 57 58 /** Constructor to create a new piece of metadata given its name. */ 59 public CollectionMeta(String name) { 60 element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 61 element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name); 62 element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Gatherer.config.interface_language); 63 } 64 65 /** Constructor to create a new piece of metadata given its name. */ 66 public CollectionMeta(String name, String language) { 67 element = CollectionDesignManager.collect_config.document.createElement(StaticStrings.COLLECTIONMETADATA_ELEMENT); 68 element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name); 69 element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, language); 70 } 71 81 72 /** Method to compare two collection metadata objects to calculate their respective ordering. 82 * @param object The other metadata to compare to, as an <strong>Object</strong>. 83 * @return An <i>int</i>which is less than 0 if this object proceeds the given object, 0 if they are equal and greater than 0 otherwise.84 85 73 * @param object the other metadata to compare to, as an Object 74 * @return an int which is less than 0 if this object proceeds the given object, 0 if they are equal and greater than 0 otherwise. 75 * @see org.greenstone.gatherer.cdm.Language 76 */ 86 77 public int compareTo(Object object) { 87 if(object instanceof CollectionMeta) {88 CollectionMeta metadata = (CollectionMeta) object;89 int result = name.toString().compareTo(metadata.getName().toString());90 if(result == 0) {91 Language other_language = metadata.getLanguage();92 if(language != null && other_language != null) {93 result = language.compareTo(metadata.getLanguage());94 if(result == 0) {95 return value.compareTo(metadata.getValue());96 }97 }98 else if(language != null) {99 return -1;100 }101 else if(other_language != null) {102 return 1;103 }104 }105 return result;106 }107 78 return toString().compareTo(object.toString()); 108 79 } 80 81 /** Factory constructor. */ 82 public DOMProxyListEntry create(Element element) { 83 return new CollectionMeta(element); 84 } 85 109 86 /** Method to compare two collection metadata objects for equality. 110 111 112 87 * @param object The other metadata to compare to, as an <strong>Object</strong>. 88 * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise. 89 */ 113 90 public boolean equals(Object object) { 114 if(compareTo(object) == 0) { 115 return true; 116 } 117 return false; 91 return (compareTo(object) == 0); 118 92 } 93 94 public Element getElement() { 95 return element; 96 } 97 119 98 /** Method to retrieve the value of language. 120 * @return The value of language as a <strong> Language</strong>.99 * @return The value of language as a <strong>String</strong>. 121 100 */ 122 public Language getLanguage() { 123 return language; 101 public String getLanguage() { 102 // Retrieve the language string 103 return element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE); 124 104 } 105 125 106 /** Method to retrieve the value of name. 126 * @return The value of name as an <strong>Object</strong>.107 * @return 127 108 */ 128 public ObjectgetName() {129 return name;109 public String getName() { 110 return element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 130 111 } 131 112 /** Method to retrieve the value of value (well great choice of name there). 132 133 113 * @return The value of value as a <strong>String</strong>. 114 */ 134 115 public String getValue() { 135 return value; 116 // We have to replace the string made of '\' 'n' with the '\n' character! Also watch for other greenstone magic 117 return Utility.decodeGreenstone(MSMUtils.getValue(element)); 136 118 } 137 /** Method to print out this class as it would appear within the collection configuration file. 138 * @return A <strong>String</strong> containing the text value of this class. 139 */ 140 public String toString() { 141 String text = "collectionmeta "; 142 if(name instanceof Index) { 143 text = text + "."; 144 Index index = (Index)name; 145 text = text + index.toStringConfig() + " "; 119 120 public boolean isAssigned() { 121 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR)); 122 } 123 124 /** Determine if this metadata is one of the four special pieces of metadata. 125 * @return true if this metadata is special, false otherwise. 126 */ 127 public boolean isSpecial() { 128 return (element != null && element.getAttribute(StaticStrings.SPECIAL_ATTRIBUTE).equals(StaticStrings.TRUE_STR)); 129 } 130 131 public void setAssigned(boolean assigned) { 132 if(element != null) { 133 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR)); 146 134 } 147 else if(name instanceof SubIndex) {148 text = text + ".";149 SubIndex index = (SubIndex)name;150 text = text + index.toString() + " ";151 }152 else {153 text = text + name.toString() + " ";154 }155 if(language != null && manager.languages.size() > 0 && !manager.languages.isDefaultLanguage(language)) {156 text = text + "[l=" + language.getCode() + "] ";157 }158 text = text + "\"" + Utility.encodeGreenstone(value) + "\"\n";159 return text;160 135 } 161 /** Used to update the contents of this collection level metadata to the given 'new' values. 162 * @param name The new name of the metadata, as a <strong>Object</strong>. 163 * @param language The new <strong>Language</strong> of the metadata. 164 * @param value And the value the metadata is assigned, as a <strong>String</strong>. 165 */ 166 public void update(Object name, Language language, String value) { 167 this.name = name; 168 this.language = language; 169 this.value = value; 136 137 public void setElement(Element element) { 138 this.element = element; 139 text = null; 170 140 } 171 141 … … 174 144 */ 175 145 public void setValue(String value) { 176 this.value = value; 146 MSMUtils.setValue(element, Utility.encodeGreenstone(value)); 147 text = null; // Reset text 177 148 } 178 149 179 /** Ensure this is a valid metadata entry by checking that the value is non-null and non-zero length (after having removed whitespace). 180 * @return <i>true</i> if this metadata has a valid value and should be added to the config, <i>false</i> otherwise. 181 */ 182 public boolean valid() { 183 return(value != null && value.trim().length() > 0); 150 /** Method to print out this class as it would appear within the collection configuration file. 151 * @return A <strong>String</strong> containing the text value of this class. 152 */ 153 public String toString() { 154 if(text == null) { 155 text = CollectionConfiguration.toString(element, true); 156 } 157 return text; 184 158 } 185 159 }
Note:
See TracChangeset
for help on using the changeset viewer.