source: trunk/gli/src/org/greenstone/gatherer/cdm/Level.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.5 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 Level element is important.
38 * @author John Thompson, Greenstone Digital Library, University of Waikato
39 * @version 2.4
40 */
41public class Level
42 implements DOMProxyListEntry {
43
44 /** The Element this level 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 Level() {
51 }
52
53 /** Normal constructor.
54 * @param element the Element this object will find its data from
55 */
56 public Level(Element element) {
57 this.element = element;
58 }
59
60 /** Creation of a brand new Level
61 * @param name the name of this type as a String
62 */
63 public Level(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 level 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 level should be based on
82 * @return a newly created DOMProxyListEntry for the given element
83 */
84 public DOMProxyListEntry create(Element element) {
85 return new Level(element);
86 }
87
88 /** Determine if this level 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 level.
104 * @return the name as a String
105 */
106 public String getName() {
107 return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
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 */
114 public boolean isAssigned() {
115 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
116 }
117
118 /** Set the assigned state.
119 * @param assigned the desired state of assigned as a boolean
120 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
121 */
122 public void setAssigned(boolean assigned) {
123 if(element != null) {
124 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
125 }
126 }
127
128 /** Set the element that this DOMProxyListEntry is base on.
129 * @param element the new Element that this entry should source informatin from
130 */
131 public void setElement(Element element) {
132 this.element = element;
133 this.text = null;
134 }
135
136 /** Set the name of this level.
137 * @param name the new name for this level, as a String
138 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
139 */
140 public void setName(String name) {
141 if(element != null) {
142 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
143 this.text = null;
144 }
145 }
146
147 /** Produce a text representation of this level.
148 * @return a String showing this level
149 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
150 */
151 public String toString() {
152 if(text == null) {
153 if(element == null) {
154 text = "#Error";
155 }
156 else {
157 String name = getName();
158 StringBuffer text_buffer = new StringBuffer(name);
159 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + name, false);
160 if(metadatum != null) {
161 text_buffer.append(" \"");
162 text_buffer.append(metadatum.getValue());
163 text_buffer.append("\"");
164 }
165 text = text_buffer.toString();
166 text_buffer = null;
167 }
168 }
169 return text;
170 }
171}
Note: See TracBrowser for help on using the repository browser.