KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > util > DCInput


1 /*
2  * DCInput.java
3  *
4  * Version: $Revision: 1.7 $
5  *
6  * Date: $Date: 2006/02/08 14:34:03 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.webui.util;
42
43 import java.util.List JavaDoc;
44 import java.util.Map JavaDoc;
45
46 import org.dspace.content.MetadataSchema;
47
48 /**
49  * Class representing a line in an input form.
50  *
51  * @author Brian S. Hughes, based on work by Jenny Toves, OCLC
52  * @version
53  */

54 public class DCInput
55 {
56     /** the DC element name */
57     private String JavaDoc dcElement = null;
58
59     /** the DC qualifier, if any */
60     private String JavaDoc dcQualifier = null;
61
62     /** the DC namespace schema */
63     private String JavaDoc dcSchema = null;
64
65     /** a label describing input */
66     private String JavaDoc label = null;
67
68     /** the input type */
69     private String JavaDoc inputType = null;
70
71     /** is input required? */
72     private boolean required = false;
73
74     /** if required, text to display when missing */
75     private String JavaDoc warning = null;
76
77     /** is input repeatable? */
78     private boolean repeatable = false;
79
80     /** 'hint' text to display */
81     private String JavaDoc hint = null;
82
83     /** if input list-controlled, name of list */
84     private String JavaDoc valueListName = null;
85
86     /** if input list-controlled, the list itself */
87     private List JavaDoc valueList = null;
88
89     /** if non-null, visibility scope restriction */
90     private String JavaDoc visibility = null;
91
92     /** the name of the controlled vocabulary to use */
93     private String JavaDoc vocabulary = null;
94
95     /**
96      * Class constructor for creating a DCInput object based on the contents of
97      * a HashMap
98      *
99      * @param row
100      * the corresponding row in the table
101      */

102     public DCInput(Map JavaDoc fieldMap, Map JavaDoc listMap)
103     {
104         dcElement = (String JavaDoc) fieldMap.get("dc-element");
105         dcQualifier = (String JavaDoc) fieldMap.get("dc-qualifier");
106
107         // Default the schema to dublin core
108
dcSchema = (String JavaDoc) fieldMap.get("dc-schema");
109         if (dcSchema == null)
110         {
111             dcSchema = MetadataSchema.DC_SCHEMA;
112         }
113
114         String JavaDoc repStr = (String JavaDoc) fieldMap.get("repeatable");
115         repeatable = "true".equalsIgnoreCase(repStr)
116                 || "yes".equalsIgnoreCase(repStr);
117         label = (String JavaDoc) fieldMap.get("label");
118         inputType = (String JavaDoc) fieldMap.get("input-type");
119         // these types are list-controlled
120
if ("dropdown".equals(inputType) || "qualdrop_value".equals(inputType))
121         {
122             valueListName = (String JavaDoc) fieldMap.get("value-pairs-name");
123             valueList = (List JavaDoc) listMap.get(valueListName);
124         }
125         hint = (String JavaDoc) fieldMap.get("hint");
126         warning = (String JavaDoc) fieldMap.get("required");
127         required = (warning != null && warning.length() > 0);
128         visibility = (String JavaDoc) fieldMap.get("visibility");
129         vocabulary = (String JavaDoc) fieldMap.get("vocabulary");
130     }
131
132     /**
133      * Is this DCInput for display in the given scope? The scope should be
134      * either "workflow" or "submit", as per the input forms definition. If the
135      * internal visibility is set to "null" then this will always return true.
136      *
137      * @param scope
138      * String identifying the scope that this input's visibility
139      * should be tested for
140      *
141      * @return whether the input should be displayed or not
142      */

143     public boolean isVisible(String JavaDoc scope)
144     {
145         return (visibility == null || visibility.equals(scope));
146     }
147
148     /**
149      * Get the repeatable flag for this row
150      *
151      * @return the repeatable flag
152      */

153     public boolean isRepeatable()
154     {
155         return repeatable;
156     }
157
158     /**
159      * Alternate way of calling isRepeatable()
160      *
161      * @return the repeatable flag
162      */

163     public boolean getRepeatable()
164     {
165         return isRepeatable();
166     }
167
168     /**
169      * Get the input type for this row
170      *
171      * @return the input type
172      */

173     public String JavaDoc getInputType()
174     {
175         return inputType;
176     }
177
178     /**
179      * Get the DC element for this form row.
180      *
181      * @return the DC element
182      */

183     public String JavaDoc getElement()
184     {
185         return dcElement;
186     }
187
188     /**
189      * Get the DC namespace prefix for this form row.
190      *
191      * @return the DC namespace prefix
192      */

193     public String JavaDoc getSchema()
194     {
195         return dcSchema;
196     }
197
198     /**
199      * Get the warning string for a missing required field, formatted for an
200      * HTML table.
201      *
202      * @return the string prompt if required field was ignored
203      */

204     public String JavaDoc getWarning()
205     {
206         return "<tr><td colspan=\"4\" class=\"submitFormWarn\">" + warning
207                 + "</td></tr>";
208     }
209
210     /**
211      * Is there a required string for this form row?
212      *
213      * @return true if a required string is set
214      */

215     public boolean isRequired()
216     {
217         return required;
218     }
219
220     /**
221      * Get the DC qualifier for this form row.
222      *
223      * @return the DC qualifier
224      */

225     public String JavaDoc getQualifier()
226     {
227         return dcQualifier;
228     }
229
230     /**
231      * Get the hint for this form row, formatted for an HTML table
232      *
233      * @return the hints
234      */

235     public String JavaDoc getHints()
236     {
237         return "<tr><td colspan=\"4\" class=\"submitFormHelp\">" + hint
238                 + "</td></tr>";
239     }
240
241     /**
242      * Get the label for this form row.
243      *
244      * @return the label
245      */

246     public String JavaDoc getLabel()
247     {
248         return label;
249     }
250
251     /**
252      * Get the name of the pairs type
253      *
254      * @return the pairs type name
255      */

256     public String JavaDoc getPairsType()
257     {
258         return valueListName;
259     }
260
261     /**
262      * Get the name of the pairs type
263      *
264      * @return the pairs type name
265      */

266     public List JavaDoc getPairs()
267     {
268         return valueList;
269     }
270
271     /**
272      * Get the name of the controlled vocabulary that is associated with this
273      * field
274      *
275      * @return the name of associated the vocabulary
276      */

277     public String JavaDoc getVocabulary()
278     {
279         return vocabulary;
280     }
281
282     /**
283      * Set the name of the controlled vocabulary that is associated with this
284      * field
285      *
286      * @param vocabulary
287      * the name of the vocabulary
288      */

289     public void setVocabulary(String JavaDoc vocabulary)
290     {
291         this.vocabulary = vocabulary;
292     }
293
294     /**
295      * Gets the display string that corresponds to the passed storage string in
296      * a particular display-storage pair set.
297      *
298      * @param allPairs
299      * HashMap of all display-storage pair sets
300      * @param pairTypeName
301      * Name of display-storage pair set to search
302      * @param storageString
303      * the string that gets stored
304      *
305      * @return the displayed string whose selection causes storageString to be
306      * stored, null if no match
307      */

308     public String JavaDoc getDisplayString(String JavaDoc pairTypeName, String JavaDoc storedString)
309     {
310         if (valueList != null)
311         {
312             for (int i = 0; i < valueList.size(); i += 2)
313             {
314                 if (((String JavaDoc) valueList.get(i + 1)).equals(storedString))
315                 {
316                     return (String JavaDoc) valueList.get(i);
317                 }
318             }
319         }
320         return null;
321     }
322
323     /**
324      * Gets the stored string that corresponds to the passed display string in a
325      * particular display-storage pair set.
326      *
327      * @param allPairs
328      * HashMap of all display-storage pair sets
329      * @param pairTypeName
330      * Name of display-storage pair set to search
331      * @param displayString
332      * the string that gets displayed
333      *
334      * @return the string that gets stored when displayString gets selected,
335      * null if no match
336      */

337     public String JavaDoc getStoredString(String JavaDoc pairTypeName, String JavaDoc displayedString)
338     {
339         if (valueList != null)
340         {
341             for (int i = 0; i < valueList.size(); i += 2)
342             {
343                 if (((String JavaDoc) valueList.get(i)).equals(displayedString))
344                 {
345                     return (String JavaDoc) valueList.get(i + 1);
346                 }
347             }
348         }
349         return null;
350     }
351
352 }
353
Popular Tags