001: /*
002: * Params.java
003: *
004: * Version: $Revision: 1.1 $
005: *
006: * Date: $Date: 2006/07/05 21:40:01 $
007: *
008: * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.xmlui.wing.element;
042:
043: /**
044: * A class represented parameters to fields. The parameter element is basicaly a
045: * grab bag of attributes associated with varios fields.
046: *
047: * @author Scott Phillips
048: */
049:
050: import org.dspace.app.xmlui.wing.AttributeMap;
051: import org.dspace.app.xmlui.wing.WingContext;
052: import org.dspace.app.xmlui.wing.WingException;
053: import org.xml.sax.ContentHandler;
054: import org.xml.sax.SAXException;
055: import org.xml.sax.ext.LexicalHandler;
056: import org.xml.sax.helpers.NamespaceSupport;
057:
058: public class Params extends AbstractWingElement implements
059: StructuralElement {
060: /** The name of the params element */
061: public static final String E_PARAMS = "params";
062:
063: /** The name of the operations attribute */
064: public static final String A_OPERATIONS = "operations";
065:
066: /** The name of the return value attribute */
067: public static final String A_RETURN_VALUE = "returnValue";
068:
069: /** The name of the size attribute */
070: public static final String A_SIZE = "size";
071:
072: /** The name of the max length attribute */
073: public static final String A_MAX_LENGTH = "maxlength";
074:
075: /** The name of the multiple attribute */
076: public static final String A_MULTIPLE = "multiple";
077:
078: /** The name of the rows attribute */
079: public static final String A_ROWS = "rows";
080:
081: /** The name of the cols attribute */
082: public static final String A_COLS = "cols";
083:
084: /** Possible operations */
085: public static final String OPERATION_ADD = "add";
086:
087: public static final String OPERATION_DELETE = "delete";
088:
089: public static final String[] OPERATIONS = { OPERATION_ADD,
090: OPERATION_DELETE };
091:
092: /** *********** Parameter Attributes *************** */
093:
094: /** The supported operations for this field */
095: protected boolean addOperation;
096: protected boolean deleteOperation;
097:
098: /** The return value for the field, checkboxes and radio buttons. */
099: protected String returnValue;
100:
101: /** The field size */
102: protected int size = -1;
103:
104: /** The maximum length of the field */
105: protected int maxlength = -1;
106:
107: /** Weather multiple values for this field are allowed */
108: protected boolean multiple = false;
109:
110: /** The number of rows the field should span */
111: protected int rows = -1;
112:
113: /** The number of cols the field should span */
114: protected int cols = -1;
115:
116: /**
117: * Construct a new parameter's element
118: *
119: * @param context
120: * (Required) The context this element is contained in, such as
121: * where to route SAX events and what i18n catalogue to use.
122: *
123: */
124: protected Params(WingContext context) throws WingException {
125: super (context);
126: }
127:
128: /**
129: * Enable the add operation for this field set. When this is enabled the
130: * front end will add a button to add more items to the field.
131: *
132: */
133: public void enableAddOperation() throws WingException {
134: this .addOperation = true;
135: }
136:
137: /**
138: * Enable the delete operation for this field set. When this is enabled then
139: * the front end will provide a way for the user to select fields (probably
140: * checkboxes) along with a submit button to delete the selected fields.
141: *
142: */
143: public void enableDeleteOperation() throws WingException {
144: this .deleteOperation = true;
145: }
146:
147: /**
148: * Set the size of the field.
149: *
150: * This applies to text, password, and select fields.
151: *
152: * @param size
153: * (Required) The size of the field.
154: */
155: public void setSize(int size) {
156: this .size = size;
157: }
158:
159: /**
160: * Set the maximum length of the field.
161: *
162: * This applies to text, password, and textarea fields.
163: *
164: * @param maxlength
165: * (Required) The maximum length of the field.
166: */
167: public void setMaxLength(int maxlength) {
168: this .maxlength = maxlength;
169: }
170:
171: /**
172: * Set the number of rows of this field.
173: *
174: * The applies only to textarea fields.
175: *
176: * @param rows
177: * (Required) The number of rows.
178: */
179: public void setRows(int rows) {
180: this .rows = rows;
181: }
182:
183: /**
184: * Set the number of columns of this field.
185: *
186: * The applies only to textarea fields.
187: *
188: * @param cols
189: * (Required) The number of columns.
190: */
191: public void setCols(int cols) {
192: this .cols = cols;
193: }
194:
195: /**
196: * The returned value for this field if it is checked (or selected).
197: *
198: * The applies to radio and checkbox fields.
199: *
200: * @param returnValue
201: * (Required) The value to be returned if this field is checked.
202: */
203: public void setReturnValue(String returnValue) {
204: this .returnValue = returnValue;
205: }
206:
207: /**
208: * Determine if this field can accept multiple values.
209: *
210: * The applies only to select fields.
211: *
212: * @param multiple
213: * (Required) whether the field can accept multiple values.
214: */
215: public void setMultiple(boolean multiple) {
216: this .multiple = multiple;
217: }
218:
219: /**
220: * Translate this element and all contained elements into SAX events. The
221: * events should be routed to the contentHandler found in the WingContext.
222: *
223: * @param contentHandler
224: * (Required) The registered contentHandler where SAX events
225: * should be routed too.
226: * @param lexicalHandler
227: * (Required) The registered lexicalHandler where lexical events
228: * (such as CDATA, DTD, etc) should be routed too.
229: * @param namespaces
230: * (Required) SAX Helper class to keep track of namespaces able
231: * to determine the correct prefix for a given namespace URI.
232: */
233: public void toSAX(ContentHandler contentHandler,
234: LexicalHandler lexicalHandler, NamespaceSupport namespaces)
235: throws SAXException {
236: AttributeMap attributes = new AttributeMap();
237:
238: // Determine if there are any operations
239: String operations = null;
240: if (addOperation) {
241: if (operations == null)
242: operations = OPERATION_ADD;
243: else
244: operations += " " + OPERATION_ADD;
245: }
246: if (addOperation) {
247: if (operations == null)
248: operations = OPERATION_DELETE;
249: else
250: operations += " " + OPERATION_DELETE;
251: }
252: if (operations != null)
253: attributes.put(A_OPERATIONS, operations);
254:
255: if (this .returnValue != null) {
256: attributes.put(A_RETURN_VALUE, this .returnValue);
257: }
258:
259: if (this .size > -1) {
260: attributes.put(A_SIZE, this .size);
261: }
262:
263: if (this .maxlength > -1) {
264: attributes.put(A_MAX_LENGTH, this .maxlength);
265: }
266:
267: if (this .multiple == true) {
268: attributes.put(A_MULTIPLE, this .multiple);
269: }
270:
271: if (this .rows > -1) {
272: attributes.put(A_ROWS, this .rows);
273: }
274:
275: if (this .cols > -1) {
276: attributes.put(A_COLS, this .cols);
277: }
278:
279: startElement(contentHandler, namespaces, E_PARAMS, attributes);
280: endElement(contentHandler, namespaces, E_PARAMS);
281: }
282:
283: /**
284: * Dispose
285: */
286: public void dispose() {
287: super.dispose();
288: }
289: }
|