source: trunk/gli/src/org/greenstone/gatherer/cdm/Level.java@ 8853

Last change on this file since 8853 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 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/**************************************************************************************
30 * Written: 16/07/03
31 * Revised:
32 **************************************************************************************/
33import org.w3c.dom.*;
34
35/** 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.
36 * @author John Thompson, Greenstone Digital Library, University of Waikato
37 * @version 2.4
38 */
39public class Level
40 implements DOMProxyListEntry {
41
42 /** The Element this level object will source its information from. */
43 private Element element;
44 /** A cached version of the string representation, for speed of painting (given toString() might be called several times during a list repaint). */
45 private String text;
46
47 /** Constructor used only during DOMProxyListModel initialization. */
48 public Level() {
49 }
50
51 /** Normal constructor.
52 * @param element the Element this object will find its data from
53 */
54 public Level(Element element) {
55 this.element = element;
56 }
57
58 /** Creation of a brand new Level
59 * @param name the name of this type as a String
60 */
61 public Level(String name) {
62 element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
63 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
64 text = null;
65 }
66
67 /** Compare two objects for ordering.
68 * @param object the other Object to compare to
69 * @return <0 if this level should be before the given object, 0 if they are equal, and >0 if it should be after
70 */
71 public int compareTo(Object object) {
72 if(object == null) {
73 return -1;
74 }
75 return toString().compareTo(object.toString());
76 }
77
78 /** Factory-like method to allow DOMProxyListModel to generate new entries.
79 * @param element the Element the new level should be based on
80 * @return a newly created DOMProxyListEntry for the given element
81 */
82 public DOMProxyListEntry create(Element element) {
83 return new Level(element);
84 }
85
86 /** Determine if this level is equavilent to another object.
87 * @param object the other Other to match against
88 * @return true if the two are equal, false otherwise
89 */
90 public boolean equals(Object object) {
91 return (compareTo(object) == 0);
92 }
93
94 /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
95 * @return the Element in question
96 */
97 public Element getElement() {
98 return element;
99 }
100
101 /** Retrieve the name of this level.
102 * @return the name as a String
103 */
104 public String getName() {
105 return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
106 }
107
108 /** 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!)
109 * @return true if this command has been assigned, false otherwise
110 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
111 */
112 public boolean isAssigned() {
113 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
114 }
115
116 /** Set the assigned state.
117 * @param assigned the desired state of assigned as a boolean
118 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
119 */
120 public void setAssigned(boolean assigned) {
121 if(element != null) {
122 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
123 }
124 }
125
126 /** Set the element that this DOMProxyListEntry is base on.
127 * @param element the new Element that this entry should source informatin from
128 */
129 public void setElement(Element element) {
130 this.element = element;
131 this.text = null;
132 }
133
134 /** Set the name of this level.
135 * @param name the new name for this level, as a String
136 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
137 */
138 public void setName(String name) {
139 if(element != null) {
140 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
141 this.text = null;
142 }
143 }
144
145 /** Produce a text representation of this level.
146 * @return a String showing this level
147 * @see org.greenstone.gatherer.cdm.CollectionConfiguration
148 */
149 public String toString() {
150 if(text == null) {
151 if(element == null) {
152 text = "#Error";
153 }
154 else {
155 String name = getName();
156 StringBuffer text_buffer = new StringBuffer(name);
157 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + name, false);
158 if(metadatum != null) {
159 text_buffer.append(" \"");
160 text_buffer.append(metadatum.getValue(CollectionMeta.TEXT));
161 text_buffer.append("\"");
162 }
163 text = text_buffer.toString();
164 text_buffer = null;
165 }
166 }
167 return text;
168 }
169}
Note: See TracBrowser for help on using the repository browser.