001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: InputBean.java 6385 2007-10-25 14:02:26Z wehrens $
004: */package org.gridsphere.provider.portletui.beans;
005:
006: /**
007: * An abstract <code>InputBean</code> provides a generic input HTML element
008: */
009: public abstract class InputBean extends BaseComponentBean implements
010: TagBean {
011:
012: public static final String INPUT_STYLE = "portlet-form-input-field";
013:
014: protected String inputtype = "";
015: protected int size = 0;
016: protected int maxlength = 0;
017:
018: protected String onFocus = null;
019: protected String onClick = null;
020: protected String onDblClick = null;
021: protected String onChange = null;
022: protected String onBlur = null;
023: protected String onSelect = null;
024:
025: protected String onmousedown = null;
026: protected String onmousemove = null;
027: protected String onmouseout = null;
028: protected String onmouseover = null;
029: protected String onmouseup = null;
030:
031: /**
032: * Constructs a default input bean
033: */
034: public InputBean() {
035: super ();
036: this .cssClass = INPUT_STYLE;
037: }
038:
039: /**
040: * Constructs an input bean with a supplied name
041: *
042: * @param name the bean name
043: */
044: public InputBean(String name) {
045: super (name);
046: this .cssClass = INPUT_STYLE;
047: }
048:
049: /**
050: * Returns the onChange JavaScript function
051: *
052: * @return onChange JavaScript function
053: */
054: public String getOnChange() {
055: return onChange;
056: }
057:
058: /**
059: * Sets the onChange JavaScript function
060: *
061: * @param onChange the onChange JavaScript function
062: */
063: public void setOnChange(String onChange) {
064: this .onChange = onChange;
065: }
066:
067: /**
068: * Returns the onBlur JavaScript function
069: *
070: * @return onBlur JavaScript function
071: */
072: public String getOnBlur() {
073: return onBlur;
074: }
075:
076: /**
077: * Sets the onBlur JavaScript function
078: *
079: * @param onBlur the onBlur JavaScript function
080: */
081: public void setOnBlur(String onBlur) {
082: this .onBlur = onBlur;
083: }
084:
085: /**
086: * Returns the onSelect JavaScript function
087: *
088: * @return onSelect JavaScript function
089: */
090: public String getOnSelect() {
091: return onSelect;
092: }
093:
094: /**
095: * Sets the onSelect JavaScript function
096: *
097: * @param onSelect the onSelect JavaScript function
098: */
099: public void setOnSelect(String onSelect) {
100: this .onSelect = onSelect;
101: }
102:
103: /**
104: * Sets the onFocus JavaScript function
105: *
106: * @param onFocus the onFocus JavaScript function
107: */
108: public void setOnFocus(String onFocus) {
109: this .onFocus = onFocus;
110: }
111:
112: /**
113: * Returns the onFocus JavaScript function
114: *
115: * @return onFocus JavaScript function
116: */
117: public String getOnFocus() {
118: return onFocus;
119: }
120:
121: /**
122: * Returns the onClick javascript function
123: *
124: * @return the onClick javascript function
125: */
126: public String getOnClick() {
127: return onClick;
128: }
129:
130: /**
131: * Sets the onClick JavaScript function
132: *
133: * @param onClick the onFocus JavaScript function
134: */
135: public void setOnClick(String onClick) {
136: this .onClick = onClick;
137: }
138:
139: /**
140: * Returns the onDblClick javascript function
141: *
142: * @return the onDblClick javascript function
143: */
144: public String getOnDblClick() {
145: return onDblClick;
146: }
147:
148: /**
149: * Sets the onDblClick JavaScript function
150: *
151: * @param onDblClick the onDblClick JavaScript function
152: */
153: public void setOnDblClick(String onDblClick) {
154: this .onDblClick = onDblClick;
155: }
156:
157: /**
158: * Returns the onmousedown event
159: *
160: * @return the onmousedown function
161: */
162: public String getOnMouseDown() {
163: return onmousedown;
164: }
165:
166: /**
167: * Sets the onmousedown event
168: *
169: * @param onmousedown the onmousedown function
170: */
171: public void setOnMouseDown(String onmousedown) {
172: this .onmousedown = onmousedown;
173: }
174:
175: /**
176: * Returns the onmousemove function
177: *
178: * @return the onmousemove function
179: */
180: public String getOnMouseMove() {
181: return onmousemove;
182: }
183:
184: /**
185: * Sets the onmousemove function
186: *
187: * @param onmousemove the onmousemove function
188: */
189: public void setOnMouseMove(String onmousemove) {
190: this .onmousemove = onmousemove;
191: }
192:
193: /**
194: * Returns the onmouseout function
195: *
196: * @return the onmouseout function
197: */
198: public String getOnMouseOut() {
199: return onmouseout;
200: }
201:
202: /**
203: * Sets the onmouseout function
204: *
205: * @param onmouseout the onmouseout function
206: */
207: public void setOnMouseOut(String onmouseout) {
208: this .onmouseout = onmouseout;
209: }
210:
211: /**
212: * Returns the onmouseover function
213: *
214: * @return the onmouseover function
215: */
216: public String getOnMouseOver() {
217: return onmouseover;
218: }
219:
220: /**
221: * Sets the onmouseover javascript function
222: *
223: * @param onmouseover the onmouseover function
224: */
225: public void setOnMouseOver(String onmouseover) {
226: this .onmouseover = onmouseover;
227: }
228:
229: /**
230: * Returns the onMouseUp javascript function
231: *
232: * @return the onmouseup event
233: */
234: public String getOnMouseUp() {
235: return onmouseup;
236: }
237:
238: /**
239: * Sets the onMouseUp javascript function
240: *
241: * @param onmouseup a mouseup event
242: */
243: public void setOnMouseUp(String onmouseup) {
244: this .onmouseup = onmouseup;
245: }
246:
247: /**
248: * Returns the size of this input element
249: *
250: * @return the size of this input element
251: */
252: public int getSize() {
253: return size;
254: }
255:
256: /**
257: * Sets the size of this input element
258: *
259: * @param size the size of this input element
260: */
261: public void setSize(int size) {
262: this .size = size;
263: }
264:
265: /**
266: * Returns the maximum length of this input element
267: *
268: * @return the maximum length of this input element
269: */
270: public int getMaxLength() {
271: return maxlength;
272: }
273:
274: /**
275: * Sets the maximum length of this input element
276: *
277: * @param maxlength the maximum length of this input element
278: */
279: public void setMaxLength(int maxlength) {
280: this .maxlength = maxlength;
281: }
282:
283: public String getEncodedName() {
284: return createTagName(name);
285: }
286:
287: /**
288: * Returns the bean value
289: *
290: * @return the bean value
291: */
292: public String getValue() {
293: return parseUserInput(value);
294: }
295:
296: /**
297: * An attempt to parse user supplied input for any HTML arrow tags and convert them
298: *
299: * @param userInput some user supplied input
300: * @return the parsed user input text
301: */
302: private static String parseUserInput(String userInput) {
303: if (userInput == null)
304: return null;
305: userInput = userInput.replaceAll("<", "<");
306: userInput = userInput.replaceAll(">", ">");
307: return userInput;
308: }
309:
310: public String toStartString() {
311: StringBuffer sb = new StringBuffer();
312: sb.append("<input ");
313: if (id != null)
314: sb.append("id=\"").append(id).append("\" ");
315: sb.append(getFormattedCss());
316: sb.append(" type=\"");
317: sb.append(inputtype);
318: sb.append("\" ");
319: String sname = createTagName(name);
320: sb.append("name=\"");
321: sb.append(sname);
322: sb.append("\" ");
323: if (value != null)
324: sb.append("value=\"").append(value).append("\" ");
325: if (size != 0)
326: sb.append("size=\"").append(size).append("\" ");
327: if (maxlength != 0)
328: sb.append("maxlength=\"").append(maxlength).append("\" ");
329: if (onFocus != null)
330: sb.append("onfocus=\"").append(onFocus).append("\" ");
331: if (onClick != null)
332: sb.append("onclick=\"").append(onClick).append("\" ");
333: if (onDblClick != null)
334: sb.append("ondblclick=\"").append(onDblClick).append("\" ");
335: if (onChange != null)
336: sb.append("onchange=\"").append(onChange).append("\" ");
337: if (onBlur != null)
338: sb.append("onblur=\"").append(onBlur).append("\" ");
339: if (onSelect != null)
340: sb.append("onselect=\"").append(onSelect).append("\" ");
341: if (onmouseout != null)
342: sb.append("onmouseout=\"").append(onmouseout).append("\" ");
343: if (onmousedown != null)
344: sb.append("onmousedown=\"").append(onmousedown).append(
345: "\" ");
346: if (onmouseup != null)
347: sb.append("onmouseup=\"").append(onmouseup).append("\" ");
348: if (onmousemove != null)
349: sb.append("onmousemove=\"").append(onmousemove).append(
350: "\" ");
351: if (onmouseover != null)
352: sb.append("onmouseover=\"").append(onmouseover).append(
353: "\" ");
354:
355: sb.append(checkReadOnly());
356: sb.append(checkDisabled());
357: sb.append("/>");
358: return sb.toString();
359: }
360:
361: public String toEndString() {
362: return "";
363: }
364:
365: }
|