[4293] | 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 | * <BR><BR>
|
---|
| 9 | *
|
---|
| 10 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 11 | *
|
---|
| 12 | * <BR><BR>
|
---|
| 13 | *
|
---|
| 14 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 15 | *
|
---|
| 16 | * <BR><BR>
|
---|
| 17 | *
|
---|
| 18 | * This program is free software; you can redistribute it and/or modify
|
---|
| 19 | * it under the terms of the GNU General Public License as published by
|
---|
| 20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 21 | * (at your option) any later version.
|
---|
| 22 | *
|
---|
| 23 | * <BR><BR>
|
---|
| 24 | *
|
---|
| 25 | * This program is distributed in the hope that it will be useful,
|
---|
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 28 | * GNU General Public License for more details.
|
---|
| 29 | *
|
---|
| 30 | * <BR><BR>
|
---|
| 31 | *
|
---|
| 32 | * You should have received a copy of the GNU General Public License
|
---|
| 33 | * along with this program; if not, write to the Free Software
|
---|
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 35 | *########################################################################
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | /* GPL_HEADER */
|
---|
| 44 | package org.greenstone.gatherer.cdm;
|
---|
| 45 | /**************************************************************************************
|
---|
| 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.
|
---|
| 52 | **************************************************************************************/
|
---|
| 53 | import org.greenstone.gatherer.cdm.Index;
|
---|
| 54 | import org.greenstone.gatherer.cdm.Language;
|
---|
| 55 | import org.greenstone.gatherer.util.Utility;
|
---|
| 56 | /** This class encapsulates a single collection level metadata assignment, which constitutes a name, language and value.
|
---|
| 57 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
| 58 | * @version 2.3
|
---|
| 59 | */
|
---|
| 60 | 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 index an Index. */
|
---|
| 67 | private Object name = null;
|
---|
| 68 | /** The value of this metadata. */
|
---|
| 69 | private String value = null;
|
---|
| 70 | /** 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;
|
---|
| 80 | }
|
---|
| 81 | /** 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 | * @see org.greenstone.gatherer.cdm.Language
|
---|
| 85 | */
|
---|
| 86 | 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 | return toString().compareTo(object.toString());
|
---|
| 108 | }
|
---|
| 109 | /** Method to compare two collection metadata objects for equality.
|
---|
| 110 | * @param object The other metadata to compare to, as an <strong>Object</strong>.
|
---|
| 111 | * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise.
|
---|
| 112 | */
|
---|
| 113 | public boolean equals(Object object) {
|
---|
| 114 | if(compareTo(object) == 0) {
|
---|
| 115 | return true;
|
---|
| 116 | }
|
---|
| 117 | return false;
|
---|
| 118 | }
|
---|
| 119 | /** Method to retrieve the value of language.
|
---|
| 120 | * @return The value of language as a <strong>Language</strong>.
|
---|
| 121 | */
|
---|
| 122 | public Language getLanguage() {
|
---|
| 123 | return language;
|
---|
| 124 | }
|
---|
| 125 | /** Method to retrieve the value of name.
|
---|
| 126 | * @return The value of name as an <strong>Object</strong>.
|
---|
| 127 | */
|
---|
| 128 | public Object getName() {
|
---|
| 129 | return name;
|
---|
| 130 | }
|
---|
| 131 | /** Method to retrieve the value of value (well great choice of name there).
|
---|
| 132 | * @return The value of value as a <strong>String</strong>.
|
---|
| 133 | */
|
---|
| 134 | public String getValue() {
|
---|
| 135 | return value;
|
---|
| 136 | }
|
---|
| 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.toString(false) + " ";
|
---|
| 146 | }
|
---|
| 147 | else {
|
---|
| 148 | text = text + name.toString() + " ";
|
---|
| 149 | }
|
---|
| 150 | if(language != null && manager.languages.size() > 0 && !manager.languages.isDefaultLanguage(language)) {
|
---|
| 151 | text = text + "[l=" + language.getCode() + "] ";
|
---|
| 152 | }
|
---|
| 153 | text = text + "\"" + Utility.encodeGreenstone(value) + "\"\n";
|
---|
| 154 | return text;
|
---|
| 155 | }
|
---|
| 156 | /** Used to update the contents of this collection level metadata to the given 'new' values.
|
---|
| 157 | * @param name The new name of the metadata, as a <strong>Object</strong>.
|
---|
| 158 | * @param language The new <strong>Language</strong> of the metadata.
|
---|
| 159 | * @param value And the value the metadata is assigned, as a <strong>String</strong>.
|
---|
| 160 | */
|
---|
| 161 | public void update(Object name, Language language, String value) {
|
---|
| 162 | this.name = name;
|
---|
| 163 | this.language = language;
|
---|
| 164 | this.value = value;
|
---|
| 165 | }
|
---|
| 166 | /** Ensure this is a valid metadata entry by checking that the value is non-null and non-zero length (after having removed whitespace).
|
---|
| 167 | * @return <i>true</i> if this metadata has a valid value and should be added to the config, <i>false</i> otherwise.
|
---|
| 168 | */
|
---|
| 169 | public boolean valid() {
|
---|
| 170 | return(value != null && value.trim().length() > 0);
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 |
|
---|