source: trunk/gli/src/org/greenstone/gatherer/cdm/SearchType.java@ 5234

Last change on this file since 5234 was 5037, checked in by jmt12, 21 years ago

CDM now recognizes G2-1.4 collect.cfg commands

  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28/**************************************************************************************
29 * Written: 16/07/03
30 * Revised:
31 **************************************************************************************/
32import org.greenstone.gatherer.Gatherer;
33import org.greenstone.gatherer.cdm.CollectionConfiguration;
34import org.greenstone.gatherer.cdm.CollectionDesignManager;
35import org.greenstone.gatherer.cdm.DOMProxyListEntry;
36import org.w3c.dom.*;
37/** 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.
38 * @author John Thompson, Greenstone Digital Library, University of Waikato
39 * @version 2.4
40 */
41public class SearchType
42 implements DOMProxyListEntry {
43
44 /** The Element this searchtype object will source its information from. */
45 private Element element;
46 /** A cached version of the string representation, for speed of painting (given toString() might be called several times during a list repaint). */
47 private String text;
48
49 /** Constructor used only during DOMProxyListModel initialization. */
50 public SearchType() {
51 }
52
53 /** Normal constructor.
54 * @param element the Element this object will find its data from
55 */
56 public SearchType(Element element) {
57 this.element = element;
58 }
59
60 /** Creation of a brand new SearchType
61 * @param name the name of this type as a String
62 */
63 public SearchType(String name) {
64 element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
65 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
66 text = null;
67 }
68
69 /** Compare two objects for ordering.
70 * @param object the other Object to compare to
71 * @return <0 if this searchtype should be before the given object, 0 if they are equal, and >0 if it should be after
72 */
73 public int compareTo(Object object) {
74 if(object == null) {
75 return -1;
76 }
77 return toString().compareTo(object.toString());
78 }
79
80 /** Factory-like method to allow DOMProxyListModel to generate new entries.
81 * @param element the Element the new searchtype should be based on
82 * @return a newly created DOMProxyListEntry for the given element
83 */
84 public DOMProxyListEntry create(Element element) {
85 return new SearchType(element);
86 }
87
88 /** Determine if this searchtype is equavilent to another object.
89 * @param object the other Other to match against
90 * @return true if the two are equal, false otherwise
91 */
92 public boolean equals(Object object) {
93 return (compareTo(object) == 0);
94 }
95
96 /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
97 * @return the Element in question
98 */
99 public Element getElement() {
100 return element;
101 }
102
103 /** Retrieve the name of this searchtype.
104 * @return the name as a String
105 */
106 public String getName() {
107 return toString();
108 }
109
110 /** 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!)
111 * @return true if this command has been assigned, false otherwise
112 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
113 * @see org.greenstone.gatherer.util.StaticStrings
114 */
115 public boolean isAssigned() {
116 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
117 }
118
119 /** Set the assigned state.
120 * @param assigned the desired state of assigned as a boolean
121 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
122 * @see org.greenstone.gatherer.util.StaticStrings
123 */
124 public void setAssigned(boolean assigned) {
125 if(element != null) {
126 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
127 }
128 }
129
130 /** Set the element that this DOMProxyListEntry is base on.
131 * @param element the new Element that this entry should source informatin from
132 */
133 public void setElement(Element element) {
134 this.element = element;
135 this.text = null;
136 }
137
138 /** Set the name of this searchtype.
139 * @param name the new name for this searchtype, as a String
140 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
141 * @see org.greenstone.gatherer.util.StaticStrings
142 */
143 public void setName(String name) {
144 if(element != null) {
145 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
146 this.text = null;
147 }
148 }
149
150 /** Produce a text representation of this searchtype.
151 * @return a String showing this searchtype
152 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
153 * @see org.greenstone.gatherer.util.StaticStrings
154 */
155 public String toString() {
156 if(text == null && element != null) {
157 text = element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
158 }
159 return text;
160 }
161}
Note: See TracBrowser for help on using the repository browser.