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 | * <BR><BR>
|
---|
9 | *
|
---|
10 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
11 | *
|
---|
12 | * <BR><BR>
|
---|
13 | *
|
---|
14 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
15 | *
|
---|
16 | * <BR><BR>
|
---|
17 | *
|
---|
18 | * This program is free software; you can redistribute it and/or modify
|
---|
19 | * it under the terms of the GNU General Public License as published by
|
---|
20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
21 | * (at your option) any later version.
|
---|
22 | *
|
---|
23 | * <BR><BR>
|
---|
24 | *
|
---|
25 | * This program is distributed in the hope that it will be useful,
|
---|
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | * GNU General Public License for more details.
|
---|
29 | *
|
---|
30 | * <BR><BR>
|
---|
31 | *
|
---|
32 | * You should have received a copy of the GNU General Public License
|
---|
33 | * along with this program; if not, write to the Free Software
|
---|
34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
35 | *########################################################################
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | /* GPL_HEADER */
|
---|
44 | package org.greenstone.gatherer.cdm;
|
---|
45 | /**************************************************************************************
|
---|
46 | * Title: Gatherer
|
---|
47 | * Description: The Gatherer: a tool for gathering and enriching a digital collection.
|
---|
48 | * Company: The University of Waikato
|
---|
49 | * Written: 06/05/02
|
---|
50 | * Revised: 04/10/02 - Commented
|
---|
51 | **************************************************************************************/
|
---|
52 | import org.greenstone.gatherer.cdm.Classifier;
|
---|
53 | /** This class encapsulates all the information about a format command from the collection configuration. This includes both the 'general' formatting commands, and the commands targetted at specific classifiers or classification component types.
|
---|
54 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
55 | * @version 2.3
|
---|
56 | */
|
---|
57 | public class Format {
|
---|
58 | /** If this format is of a true/false type, the current state. */
|
---|
59 | private boolean state = false;
|
---|
60 | /** The type of this format command, either FLAG, FORMAT or PARAM. */
|
---|
61 | private int type = -1;
|
---|
62 | /** The feature this format command affects. */
|
---|
63 | private Object feature = null;
|
---|
64 | /** If this format refers to a specific part of a feature, this indicates the part. */
|
---|
65 | private String part = null;
|
---|
66 | /** A command string, which may include a specific HTML chunk used to format a control. */
|
---|
67 | private String value = null;
|
---|
68 | /** An element of the format type enumeration. A true/false option. */
|
---|
69 | static final public int FLAG = 0;
|
---|
70 | /** An element of the format type enumeration. A string parameter. */
|
---|
71 | static final public int VALUE = 1;
|
---|
72 | /** The default features as specified by the Greenstone Developers manual. */
|
---|
73 | static final public String DEFAULT_FEATURES[] = {"", "DocumentArrowsBottom","DocumentButtons","DocumentContents","DocumentHeading","DocumentImages","DocumentText","DocumentUseHTML","Search"};
|
---|
74 | /** The list of known feature parts. */
|
---|
75 | static final public String DEFAULT_PARTS[] = {"","DateList","HList","Invisible","VList"};
|
---|
76 | /** Constructor for a flag format command.
|
---|
77 | * @param feature The <Strong>Object</strong> this format affects.
|
---|
78 | * @param part The specific part of the control to format as a <strong>String</strong>.
|
---|
79 | * @param state A <i>boolean</i> indicating this formats state.
|
---|
80 | */
|
---|
81 | public Format(Object feature, String part, boolean state) {
|
---|
82 | this.feature = feature;
|
---|
83 | this.part = part;
|
---|
84 | this.state = state;
|
---|
85 | this.type = FLAG;
|
---|
86 | }
|
---|
87 | /** Constructor for a format-string format command.
|
---|
88 | * @param feature The <Strong>Object</strong> this format affects.
|
---|
89 | * @param part The specific part of the control to format as a <strong>String</strong>.
|
---|
90 | * @param value The format <strong>String</strong> which may be a label name, or a piece of HTML formatting.
|
---|
91 | */
|
---|
92 | public Format(Object feature, String part, String value) {
|
---|
93 | this.feature = feature;
|
---|
94 | this.part = part;
|
---|
95 | this.type = VALUE;
|
---|
96 | this.value = value;
|
---|
97 | }
|
---|
98 | /** Method to retrieve the value of feature, which may either be a String or a Classifier.
|
---|
99 | * @return The value of feature as an <strong>Object</strong>.
|
---|
100 | */
|
---|
101 | public Object getFeature() {
|
---|
102 | return feature;
|
---|
103 | }
|
---|
104 | /** Method to retrieve the value of part.
|
---|
105 | * @return The value of part as a <Strong>String</strong>.
|
---|
106 | */
|
---|
107 | public String getPart() {
|
---|
108 | return part;
|
---|
109 | }
|
---|
110 | /** Method to retrieve this formats special Greenstone position code.
|
---|
111 | * @return A <strong>String</strong> which distinctly indicates this classifiers position.
|
---|
112 | * @see org.greenstone.gatherer.cdm.Classifier
|
---|
113 | */
|
---|
114 | public String getPosition() {
|
---|
115 | ///ystem.err.println("Retrieving the name of feature " + feature);
|
---|
116 | String position = null;
|
---|
117 | if(feature instanceof Classifier) {
|
---|
118 | position = ((Classifier)feature).getPositionString();
|
---|
119 | }
|
---|
120 | else {
|
---|
121 | position = feature.toString();
|
---|
122 | }
|
---|
123 | ///ystem.err.println("Result: " + position + part);
|
---|
124 | return position + part;
|
---|
125 | }
|
---|
126 | /** Method to retrieve the value of state.
|
---|
127 | * @param The value of state as a <i>boolean</i>.
|
---|
128 | */
|
---|
129 | public boolean getState() {
|
---|
130 | return state;
|
---|
131 | }
|
---|
132 | /** Method to retrieve the value of type.
|
---|
133 | * @param The value of type as an <i>int</i>.
|
---|
134 | */
|
---|
135 | public int getType() {
|
---|
136 | return type;
|
---|
137 | }
|
---|
138 | /** Retrieve the value of value.
|
---|
139 | * @return A <strong>String</strong> which is the value of value.
|
---|
140 | */
|
---|
141 | public String getValue() {
|
---|
142 | return value;
|
---|
143 | }
|
---|
144 | /** Set the value of state.
|
---|
145 | * @param state The new value for state as a <i>boolean</i>.
|
---|
146 | */
|
---|
147 | public void setState(boolean state) {
|
---|
148 | this.state = state;
|
---|
149 | }
|
---|
150 | /** Set the value of type.
|
---|
151 | * @param type The new value for type as an <i>int</i>.
|
---|
152 | */
|
---|
153 | public void setType(int type) {
|
---|
154 | this.type = type;
|
---|
155 | }
|
---|
156 | /** Set the value of value. Hmmm.
|
---|
157 | * @param value The new value from value as a <strong>String</strong>.
|
---|
158 | */
|
---|
159 | public void setValue(String value) {
|
---|
160 | this.value = value;
|
---|
161 | }
|
---|
162 | /** Method to translate this classes information into a line of text as you would expect in the collection configuration file.
|
---|
163 | * @return A <strong>String</strong> containing the format command.
|
---|
164 | */
|
---|
165 | public String toString() {
|
---|
166 | String text = "format ";
|
---|
167 | text = text + getPosition() + " ";
|
---|
168 | switch(type) {
|
---|
169 | case FLAG:
|
---|
170 | if(state) {
|
---|
171 | text = text + "true";
|
---|
172 | }
|
---|
173 | else {
|
---|
174 | text = text + "false";
|
---|
175 | }
|
---|
176 | break;
|
---|
177 | default:
|
---|
178 | text = text + "\"" + value + "\"";
|
---|
179 | }
|
---|
180 | return text;
|
---|
181 | }
|
---|
182 | /** Retrieve the type of a certain named feature.
|
---|
183 | * @param name The name of the feature as a <strong>String</strong>.
|
---|
184 | * @return An <i>int</i> indicating the type, and hence the controls needed to edit this type.
|
---|
185 | */
|
---|
186 | static public int getType(String name) {
|
---|
187 | int index = -1;
|
---|
188 | for(int i = 1; i < DEFAULT_FEATURES.length; i++) {
|
---|
189 | if(name.equalsIgnoreCase(DEFAULT_FEATURES[i])) {
|
---|
190 | index = i;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | if(index == 1 || index == 3 || index == 5 || index == 7) {
|
---|
194 | return FLAG;
|
---|
195 | }
|
---|
196 | return VALUE;
|
---|
197 | }
|
---|
198 | }
|
---|