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 | */
|
---|
27 | package org.greenstone.gatherer.cdm;
|
---|
28 |
|
---|
29 | /**************************************************************************************
|
---|
30 | * Written: 16/07/03
|
---|
31 | * Revised:
|
---|
32 | **************************************************************************************/
|
---|
33 | import 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 | */
|
---|
39 | public class Level
|
---|
40 | implements DOMProxyListEntry {
|
---|
41 |
|
---|
42 | /** The Element this level object will source its information from. */
|
---|
43 | private Element element;
|
---|
44 |
|
---|
45 | /** Constructor used only during DOMProxyListModel initialization. */
|
---|
46 | public Level() {
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** Normal constructor.
|
---|
50 | * @param element the Element this object will find its data from
|
---|
51 | */
|
---|
52 | public Level(Element element) {
|
---|
53 | this.element = element;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /** Creation of a brand new Level
|
---|
57 | * @param name the name of this type as a String
|
---|
58 | */
|
---|
59 | public Level(String level) {
|
---|
60 | this.element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
|
---|
61 | this.element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /** Compare two objects for ordering.
|
---|
65 | * @param object the other Object to compare to
|
---|
66 | * @return <0 if this level should be before the given object, 0 if they are equal, and >0 if it should be after
|
---|
67 | * since we can only have one instance of a particular level, we don't need to look at the name when comparing.
|
---|
68 | */
|
---|
69 | public int compareTo(Object object) {
|
---|
70 | if(object == null) {
|
---|
71 | return -1;
|
---|
72 | }
|
---|
73 | // hope we never compare a Level with something that is not a Level!
|
---|
74 | return getLevel().compareTo(((Level)object).getLevel());
|
---|
75 | }
|
---|
76 |
|
---|
77 | /** Factory-like method to allow DOMProxyListModel to generate new entries.
|
---|
78 | * @param element the Element the new level should be based on
|
---|
79 | * @return a newly created DOMProxyListEntry for the given element
|
---|
80 | */
|
---|
81 | public DOMProxyListEntry create(Element element) {
|
---|
82 | return new Level(element);
|
---|
83 | }
|
---|
84 |
|
---|
85 | /** Determine if this level is equavilent to another object.
|
---|
86 | * @param object the other Other to match against
|
---|
87 | * @return true if the two are equal, false otherwise
|
---|
88 | */
|
---|
89 | public boolean equals(Object object) {
|
---|
90 | return (compareTo(object) == 0);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
|
---|
94 | * @return the Element in question
|
---|
95 | */
|
---|
96 | public Element getElement() {
|
---|
97 | return element;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /** Retrieve the level.
|
---|
101 | * @return the level as a String
|
---|
102 | */
|
---|
103 | public String getLevel() {
|
---|
104 | return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /** Retrieve the display name
|
---|
108 | */
|
---|
109 | public String getName() {
|
---|
110 | CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + getLevel(), false);
|
---|
111 | if(metadatum != null) {
|
---|
112 | return metadatum.getValue(CollectionMeta.TEXT);
|
---|
113 | }
|
---|
114 | return "";
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** 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!)
|
---|
118 | * @return true if this command has been assigned, false otherwise
|
---|
119 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
120 | */
|
---|
121 | public boolean isAssigned() {
|
---|
122 | return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
|
---|
123 | }
|
---|
124 |
|
---|
125 | /** Set the assigned state.
|
---|
126 | * @param assigned the desired state of assigned as a boolean
|
---|
127 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
128 | */
|
---|
129 | public void setAssigned(boolean assigned) {
|
---|
130 | if(element != null) {
|
---|
131 | element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | /** Set the element that this DOMProxyListEntry is base on.
|
---|
136 | * @param element the new Element that this entry should source informatin from
|
---|
137 | */
|
---|
138 | public void setElement(Element element) {
|
---|
139 | this.element = element;
|
---|
140 | }
|
---|
141 |
|
---|
142 | /** Set the name of this level.
|
---|
143 | * @param name the new name for this level, as a String
|
---|
144 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
145 | */
|
---|
146 | public void setLevel(String level) {
|
---|
147 | if(element != null) {
|
---|
148 | element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | /** Produce a text representation of this level.
|
---|
153 | * @return a String showing this level
|
---|
154 | * @see org.greenstone.gatherer.cdm.CollectionConfiguration
|
---|
155 | */
|
---|
156 | public String toString() {
|
---|
157 | String text ="";
|
---|
158 | if(element == null) {
|
---|
159 | text = "#Error";
|
---|
160 | }
|
---|
161 | else {
|
---|
162 | String level = getLevel();
|
---|
163 | StringBuffer text_buffer = new StringBuffer(level);
|
---|
164 | text_buffer.append(" \"");
|
---|
165 | text_buffer.append(getName());
|
---|
166 | text_buffer.append("\"");
|
---|
167 |
|
---|
168 | text = text_buffer.toString();
|
---|
169 | text_buffer = null;
|
---|
170 | }
|
---|
171 |
|
---|
172 | return text;
|
---|
173 | }
|
---|
174 | }
|
---|