/**
*#########################################################################
*
* A component of the Gatherer application, part of the Greenstone digital
* library suite from the New Zealand Digital Library Project at the
* University of Waikato, New Zealand.
*
*
*
* Author: John Thompson, Greenstone Digital Library, University of Waikato
*
*
*
* Copyright (C) 1999 New Zealand Digital Library Project
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*########################################################################
*/
/* GPL_HEADER */
package org.greenstone.gatherer.cdm;
/**************************************************************************************
* Title: Gatherer
* Description: The Gatherer: a tool for gathering and enriching a digital collection.
* Copyright: Copyright (c) 2001
* Company: The University of Waikato
* Written: /05/02
* Revised: 22/08/02 Revamped, Optimized and Commented.
**************************************************************************************/
import org.greenstone.gatherer.cdm.Index;
import org.greenstone.gatherer.cdm.Language;
import org.greenstone.gatherer.util.Utility;
/** This class encapsulates a single collection level metadata assignment, which constitutes a name, language and value.
* @author John Thompson, Greenstone Digital Library, University of Waikato
* @version 2.3
*/
public class CollectionMeta
implements Comparable {
/** A reference to the collection design manager for access to the language manager. */
private CollectionDesignManager manager = null;
/** The language of this metadata. Should be a two letter code. */
private Language language = null;
/** The name of the thing this metadata is assigned to, which may index an Index. */
private Object name = null;
/** The value of this metadata. */
private String value = null;
/** Constructor.
* @param name The object the metadata is assigned to as an Object.
* @param language The language of the metadata as a Language. Should be a two letter code.
* @param value The value of this metadata, as a String.
*/
public CollectionMeta(CollectionDesignManager manager, Object name, Language language, String value) {
this.language = language;
this.manager = manager;
this.name = name;
this.value = value;
}
/** Method to compare two collection metadata objects to calculate their respective ordering.
* @param object The other metadata to compare to, as an Object.
* @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.
* @see org.greenstone.gatherer.cdm.Language
*/
public int compareTo(Object object) {
if(object instanceof CollectionMeta) {
CollectionMeta metadata = (CollectionMeta) object;
int result = name.toString().compareTo(metadata.getName().toString());
if(result == 0) {
Language other_language = metadata.getLanguage();
if(language != null && other_language != null) {
result = language.compareTo(metadata.getLanguage());
if(result == 0) {
return value.compareTo(metadata.getValue());
}
}
else if(language != null) {
return -1;
}
else if(other_language != null) {
return 1;
}
}
return result;
}
return toString().compareTo(object.toString());
}
/** Method to compare two collection metadata objects for equality.
* @param object The other metadata to compare to, as an Object.
* @return A boolean value of true if the object are equal, false otherwise.
*/
public boolean equals(Object object) {
if(compareTo(object) == 0) {
return true;
}
return false;
}
/** Method to retrieve the value of language.
* @return The value of language as a Language.
*/
public Language getLanguage() {
return language;
}
/** Method to retrieve the value of name.
* @return The value of name as an Object.
*/
public Object getName() {
return name;
}
/** Method to retrieve the value of value (well great choice of name there).
* @return The value of value as a String.
*/
public String getValue() {
return value;
}
/** Method to print out this class as it would appear within the collection configuration file.
* @return A String containing the text value of this class.
*/
public String toString() {
String text = "collectionmeta ";
if(name instanceof Index) {
text = text + ".";
Index index = (Index)name;
text = text + index.toString(false) + " ";
}
else {
text = text + name.toString() + " ";
}
if(language != null && manager.languages.size() > 0 && !manager.languages.isDefaultLanguage(language)) {
text = text + "[l=" + language.getCode() + "] ";
}
text = text + "\"" + Utility.encodeGreenstone(value) + "\"\n";
return text;
}
/** Used to update the contents of this collection level metadata to the given 'new' values.
* @param name The new name of the metadata, as a Object.
* @param language The new Language of the metadata.
* @param value And the value the metadata is assigned, as a String.
*/
public void update(Object name, Language language, String value) {
this.name = name;
this.language = language;
this.value = value;
}
/** Ensure this is a valid metadata entry by checking that the value is non-null and non-zero length (after having removed whitespace).
* @return true if this metadata has a valid value and should be added to the config, false otherwise.
*/
public boolean valid() {
return(value != null && value.trim().length() > 0);
}
}