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: Katherine Don, Greenstone Digital Library, University of Waikato
|
---|
9 | *
|
---|
10 | * Copyright (C) 2006 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 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
30 | import org.w3c.dom.*;
|
---|
31 |
|
---|
32 |
|
---|
33 | /** This class represents an index option. currently, might be a level or a stem option.
|
---|
34 | */
|
---|
35 | public class IndexOption
|
---|
36 | implements DOMProxyListEntry {
|
---|
37 |
|
---|
38 | /** The Element this object will source its information from. */
|
---|
39 | private Element element;
|
---|
40 |
|
---|
41 | /** Constructor used only during DOMProxyListModel initialization. */
|
---|
42 | public IndexOption() {
|
---|
43 | }
|
---|
44 |
|
---|
45 | /** Normal constructor.
|
---|
46 | * @param element the Element this object will find its data from
|
---|
47 | */
|
---|
48 | public IndexOption(Element element) {
|
---|
49 | this.element = element;
|
---|
50 | }
|
---|
51 |
|
---|
52 | /** Creation of a brand new IndexOption
|
---|
53 | * @param name the name of this type as a String
|
---|
54 | */
|
---|
55 | public IndexOption(String name) {
|
---|
56 | this.element = CollectionConfiguration.createElement(StaticStrings.INDEXOPTION_ELEMENT);
|
---|
57 | this.element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /** Compare two objects for ordering.
|
---|
61 | * @param object the other Object to compare to
|
---|
62 | * @return <0 if this option should be before the given object, 0 if they are equal, and >0 if it should be after
|
---|
63 | */
|
---|
64 | public int compareTo(Object object) {
|
---|
65 | if(object == null) {
|
---|
66 | return -1;
|
---|
67 | }
|
---|
68 | // hope we never compare a IndexOption with something that is not a IndexOption!
|
---|
69 | return getName().compareTo(((IndexOption)object).getName());
|
---|
70 | }
|
---|
71 |
|
---|
72 | /** Factory-like method to allow DOMProxyListModel to generate new entries.
|
---|
73 | * @param element the Element the new option should be based on
|
---|
74 | * @return a newly created DOMProxyListEntry for the given element
|
---|
75 | */
|
---|
76 | public DOMProxyListEntry create(Element element) {
|
---|
77 | return new IndexOption(element);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /** Determine if this option is equivalent to another object.
|
---|
81 | * @param object the other Object to match against
|
---|
82 | * @return true if the two are equal, false otherwise
|
---|
83 | */
|
---|
84 | public boolean equals(Object object) {
|
---|
85 | return (compareTo(object) == 0);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /** Retrieve the element this DOMProxyListEntry is based upon. Specified by the interface.
|
---|
89 | * @return the Element in question
|
---|
90 | */
|
---|
91 | public Element getElement() {
|
---|
92 | return element;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /** Retrieve the option name
|
---|
96 | * @return the name as a String
|
---|
97 | */
|
---|
98 | public String getName() {
|
---|
99 | return element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
|
---|
100 | }
|
---|
101 | /** Retrieve the option value
|
---|
102 | * @return the value as a string
|
---|
103 | */
|
---|
104 | public String getValue() {
|
---|
105 | return element.getAttribute(StaticStrings.VALUE_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 | */
|
---|
111 | public boolean isAssigned() {
|
---|
112 | return (element != null && !element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR));
|
---|
113 | }
|
---|
114 |
|
---|
115 | /** Set the assigned state.
|
---|
116 | * @param assigned the desired state of assigned as a boolean
|
---|
117 | */
|
---|
118 | public void setAssigned(boolean assigned) {
|
---|
119 | if(element != null) {
|
---|
120 | element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, (assigned ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | /** Set the element that this DOMProxyListEntry is base on.
|
---|
125 | * @param element the new Element that this entry should source informatin from
|
---|
126 | */
|
---|
127 | public void setElement(Element element) {
|
---|
128 | this.element = element;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Set the name of this option.
|
---|
132 | * @param name the new name for this option, as a String
|
---|
133 | */
|
---|
134 | public void setName(String name) {
|
---|
135 | if(element != null) {
|
---|
136 | element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | /** Set the value of this option - sometimes value is used as well as name*/
|
---|
141 | public void setValue(String value) {
|
---|
142 | if (element != null) {
|
---|
143 | element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value);
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | /** Produce a text representation of this option
|
---|
148 | * @return a String showing this option's name
|
---|
149 | */
|
---|
150 | public String toString() {
|
---|
151 | return getName();
|
---|
152 | }
|
---|
153 | }
|
---|