/** *######################################################################### * * 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. *######################################################################## */ package org.greenstone.gatherer.cdm; /************************************************************************************** * Written: 16/07/03 * Revised: **************************************************************************************/ import org.w3c.dom.*; /** This class represents a single search type setting which means that, at the moment, it is either based on an Content element containing the string 'plain' or one on the string 'form'. The ordering of these elements within the Level element is important. * @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.4 */ public class Level implements DOMProxyListEntry { /** The Element this level object will source its information from. */ private Element element; /** A cached version of the string representation, for speed of painting (given toString() might be called several times during a list repaint). */ private String text; /** Constructor used only during DOMProxyListModel initialization. */ public Level() { } /** Normal constructor. * @param element the Element this object will find its data from */ public Level(Element element) { this.element = element; } /** Creation of a brand new Level * @param name the name of this type as a String */ public Level(String name) { element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT); element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name); text = null; } /** Compare two objects for ordering. * @param object the other Object to compare to * @return <0 if this level should be before the given object, 0 if they are equal, and >0 if it should be after */ public int compareTo(Object object) { if(object == null) { return -1; } return toString().compareTo(object.toString()); } /** Factory-like method to allow DOMProxyListModel to generate new entries. * @param element the Element the new level should be based on * @return a newly created DOMProxyListEntry for the given element */ public DOMProxyListEntry create(Element element) { return new Level(element); } /** Determine if this level is equavilent to another object. * @param object the other Other to match against * @return true if the two are equal, false otherwise */ public boolean equals(Object object) { return (compareTo(object) == 0); } /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface. * @return the Element in question */ public Element getElement() { return element; } /** Retrieve the name of this level. * @return the name as a String */ public String getName() { return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); } /** Determine is this command has been assigned, either because it already existed in the collection configuration, or because it has been explicitly set by the user. Non-assigned entries imply they have been added by the GLI to ensure consistancy (and avoid NPE's!) * @return true if this command has been assigned, false otherwise * @see org.greenstone.gatherer.cdm.CollectionConfiguration */ public boolean isAssigned() { return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR)); } /** Set the assigned state. * @param assigned the desired state of assigned as a boolean * @see org.greenstone.gatherer.cdm.CollectionConfiguration */ public void setAssigned(boolean assigned) { if(element != null) { element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR)); } } /** Set the element that this DOMProxyListEntry is base on. * @param element the new Element that this entry should source informatin from */ public void setElement(Element element) { this.element = element; this.text = null; } /** Set the name of this level. * @param name the new name for this level, as a String * @see org.greenstone.gatherer.cdm.CollectionConfiguration */ public void setName(String name) { if(element != null) { element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name); this.text = null; } } /** Produce a text representation of this level. * @return a String showing this level * @see org.greenstone.gatherer.cdm.CollectionConfiguration */ public String toString() { if(text == null) { if(element == null) { text = "#Error"; } else { String name = getName(); StringBuffer text_buffer = new StringBuffer(name); CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + name, false); if(metadatum != null) { text_buffer.append(" \""); text_buffer.append(metadatum.getValue(CollectionMeta.TEXT)); text_buffer.append("\""); } text = text_buffer.toString(); text_buffer = null; } } return text; } }