/** *######################################################################### * * 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 SearchType element is important. * @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.4 */ public class SearchType implements DOMProxyListEntry { /** The Element this searchtype 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 SearchType() { } /** Normal constructor. * @param element the Element this object will find its data from */ public SearchType(Element element) { this.element = element; } /** Creation of a brand new SearchType * @param name the name of this type as a String */ public SearchType(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 searchtype 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 searchtype should be based on * @return a newly created DOMProxyListEntry for the given element */ public DOMProxyListEntry create(Element element) { return new SearchType(element); } /** Determine if this searchtype 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 searchtype. * @return the name as a String */ public String getName() { return toString(); } /** 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 * @see org.greenstone.gatherer.util.StaticStrings */ 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 * @see org.greenstone.gatherer.util.StaticStrings */ 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 searchtype. * @param name the new name for this searchtype, as a String * @see org.greenstone.gatherer.cdm.CollectionConfiguration * @see org.greenstone.gatherer.util.StaticStrings */ public void setName(String name) { if(element != null) { element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name); this.text = null; } } /** Produce a text representation of this searchtype. * @return a String showing this searchtype * @see org.greenstone.gatherer.cdm.CollectionConfiguration * @see org.greenstone.gatherer.util.StaticStrings */ public String toString() { if(text == null && element != null) { text = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); } return text; } }