KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > ControlSuper


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.control;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.core.NodeData;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Hashtable JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.jcr.PropertyType;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.commons.lang.StringUtils;
28
29
30 /**
31  * @author Vinzenz Wyser
32  * @version 2.0
33  */

34 public class ControlSuper implements ControlInterface {
35
36     public static final int BUTTONTYPE_PUSHBUTTON = 0;
37
38     public static final int BUTTONTYPE_CHECKBOX = 1;
39
40     public static final int BUTTONTYPE_RADIO = 2;
41
42     public static final int BUTTONSTATE_NORMAL = 0;
43
44     public static final int BUTTONSTATE_MOUSEOVER = 1;
45
46     public static final int BUTTONSTATE_MOUSEDOWN = 2;
47
48     public static final int BUTTONSTATE_PUSHED = 3;
49
50     public static final int BUTTONSTATE_DISABLED = 4; // not yet supported
51

52     public static final int VALUETYPE_SINGLE = 0;
53
54     public static final int VALUETYPE_MULTIPLE = 1;
55
56     public static final int ENCODING_NO = 0;
57
58     public static final int ENCODING_BASE64 = 1;
59
60     public static final int ENCODING_UNIX = 2;
61
62     public static final int RICHEDIT_NONE = 0;
63
64     public static final int RICHEDIT_KUPU = 1;
65
66     public static final int RICHEDIT_FCK = 2;
67
68     public static final String JavaDoc CSSCLASS_CONTROLBUTTON = "mgnlControlButton"; //$NON-NLS-1$
69

70     public static final String JavaDoc CSSCLASS_CONTROLBUTTONSMALL = "mgnlControlButtonSmall"; //$NON-NLS-1$
71

72     public static final String JavaDoc CSSCLASS_CONTROLBAR = "mgnlControlBar"; //$NON-NLS-1$
73

74     public static final String JavaDoc CSSCLASS_CONTROLBARSMALL = "mgnlControlBarSmall"; //$NON-NLS-1$
75

76     private int valueType = VALUETYPE_SINGLE;
77
78     private int encoding = ENCODING_NO;
79
80     private int isRichEditValue = RICHEDIT_NONE;
81
82     private String JavaDoc label;
83
84     private String JavaDoc name;
85
86     private String JavaDoc id;
87
88     private String JavaDoc value;
89
90     private List JavaDoc values = new ArrayList JavaDoc(); // mulitple values (checkbox)
91

92     private Map JavaDoc events = new Hashtable JavaDoc();
93
94     private Content websiteNode;
95
96     private String JavaDoc htmlPre;
97
98     private String JavaDoc htmlInter;
99
100     private String JavaDoc htmlPost;
101
102     private int type = PropertyType.STRING;
103
104     private boolean saveInfo = true;
105
106     private String JavaDoc cssClass = StringUtils.EMPTY;
107
108     private Map JavaDoc cssStyles = new Hashtable JavaDoc();
109
110     private String JavaDoc path;
111
112     private String JavaDoc nodeCollectionName;
113
114     private String JavaDoc nodeName;
115
116     private String JavaDoc paragraph;
117
118     private HttpServletRequest JavaDoc request;
119
120     ControlSuper() {
121     }
122
123     ControlSuper(String JavaDoc name, String JavaDoc value) {
124         this.setName(name);
125         this.setValue(value);
126     }
127
128     ControlSuper(String JavaDoc name, List JavaDoc values) {
129         this.setName(name);
130         this.setValues(values);
131     }
132
133     ControlSuper(String JavaDoc name, Content websiteNode) {
134         this.setName(name);
135         this.setWebsiteNode(websiteNode);
136     }
137
138     public void setPath(String JavaDoc path) {
139         this.path = path;
140     }
141
142     public String JavaDoc getPath() {
143         return this.path;
144     }
145
146     public void setNodeCollectionName(String JavaDoc nodeCollectionName) {
147         this.nodeCollectionName = nodeCollectionName;
148     }
149
150     public String JavaDoc getNodeCollectionName() {
151         return this.nodeCollectionName;
152     }
153
154     public String JavaDoc getNodeCollectionName(String JavaDoc nullOrEmptyValue) {
155         if (StringUtils.isEmpty(this.getNodeCollectionName())) {
156             return nullOrEmptyValue;
157         }
158
159         return this.getNodeCollectionName();
160     }
161
162     public void setNodeName(String JavaDoc nodeName) {
163         this.nodeName = nodeName;
164     }
165
166     public String JavaDoc getNodeName() {
167         return this.nodeName;
168     }
169
170     public String JavaDoc getNodeName(String JavaDoc nullOrEmptyValue) {
171         if (StringUtils.isEmpty(this.getNodeName())) {
172             return nullOrEmptyValue;
173         }
174
175         return this.getNodeName();
176     }
177
178     public void setParagraph(String JavaDoc paragraph) {
179         this.paragraph = paragraph;
180     }
181
182     public String JavaDoc getParagraph() {
183         return this.paragraph;
184     }
185
186     public void setRequest(HttpServletRequest JavaDoc request) {
187         this.request = request;
188     }
189
190     public HttpServletRequest JavaDoc getRequest() {
191         return this.request;
192     }
193
194     public void setName(String JavaDoc s) {
195         this.name = s;
196     }
197
198     public String JavaDoc getName() {
199         return this.name;
200     }
201
202     public void setId(String JavaDoc s) {
203         this.id = s;
204     }
205
206     public String JavaDoc getId() {
207         return this.id;
208     }
209
210     public String JavaDoc getHtmlId() {
211         if (StringUtils.isNotEmpty(this.getId())) {
212             return " id=\"" + this.getId() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
213
}
214
215         return StringUtils.EMPTY;
216     }
217
218     public void setValue(String JavaDoc value) {
219         this.value = value;
220     }
221
222     public String JavaDoc getValue() {
223         if (this.value != null) {
224             return this.value;
225         }
226
227         try {
228             return this.getWebsiteNode().getNodeData(this.getName()).getString();
229         }
230         catch (Exception JavaDoc e) {
231             return StringUtils.EMPTY;
232         }
233
234     }
235
236     public void setValues(List JavaDoc values) {
237         this.values = values;
238     }
239
240     public List JavaDoc getValues() {
241         if (this.values.size() != 0) {
242             return this.values;
243         }
244         try {
245             Iterator JavaDoc it = this.getWebsiteNode().getContent(this.getName()).getNodeDataCollection().iterator();
246             List JavaDoc l = new ArrayList JavaDoc();
247             while (it.hasNext()) {
248                 NodeData data = (NodeData) it.next();
249                 l.add(data.getString());
250             }
251             return l;
252         }
253         catch (Exception JavaDoc re) {
254             return this.values;
255         }
256     }
257
258     public void setWebsiteNode(Content c) {
259         this.websiteNode = c;
260     }
261
262     public Content getWebsiteNode() {
263         return this.websiteNode;
264     }
265
266     public void setLabel(String JavaDoc label) {
267         this.label = label;
268     }
269
270     public String JavaDoc getLabel() {
271         return this.label;
272     }
273
274     public void setEvent(String JavaDoc event, String JavaDoc action) {
275         setEvent(event, action, false);
276     }
277
278     public void setEvent(String JavaDoc event, String JavaDoc action, boolean removeExisting) {
279         String JavaDoc eventLower = event.toLowerCase();
280         String JavaDoc existing = null;
281         if (!removeExisting) {
282             existing = (String JavaDoc) this.getEvents().get(eventLower);
283         }
284         if (existing == null) {
285             existing = StringUtils.EMPTY;
286         }
287
288         this.getEvents().put(eventLower, existing + action);
289     }
290
291     public void setEvents(Map JavaDoc h) {
292         this.events = h;
293     }
294
295     public Map JavaDoc getEvents() {
296         return this.events;
297     }
298
299     public String JavaDoc getHtmlEvents() {
300         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
301         Iterator JavaDoc en = this.getEvents().keySet().iterator();
302         while (en.hasNext()) {
303             String JavaDoc key = (String JavaDoc) en.next();
304             html.append(" " + key + "=\"" + this.getEvents().get(key) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
305
}
306         return html.toString();
307     }
308
309     /**
310      * Returns an empty string.
311      * @see info.magnolia.cms.gui.control.ControlInterface#getHtml()
312      */

313     public String JavaDoc getHtml() {
314         return StringUtils.EMPTY;
315     }
316
317     public void setHtmlPre(String JavaDoc s) {
318         this.htmlPre = s;
319     }
320
321     public String JavaDoc getHtmlPre() {
322         return this.getHtmlPre(StringUtils.EMPTY);
323     }
324
325     public String JavaDoc getHtmlPre(String JavaDoc nullValue) {
326         if (this.htmlPre != null) {
327             return this.htmlPre;
328         }
329
330         return nullValue;
331     }
332
333     public void setHtmlInter(String JavaDoc s) {
334         this.htmlInter = s;
335     }
336
337     public String JavaDoc getHtmlInter() {
338         return this.getHtmlInter(StringUtils.EMPTY);
339     }
340
341     public String JavaDoc getHtmlInter(String JavaDoc nullValue) {
342         if (this.htmlInter != null) {
343             return this.htmlInter;
344         }
345
346         return nullValue;
347     }
348
349     public void setHtmlPost(String JavaDoc s) {
350         this.htmlPost = s;
351     }
352
353     public String JavaDoc getHtmlPost() {
354         return this.getHtmlPost(StringUtils.EMPTY);
355     }
356
357     public String JavaDoc getHtmlPost(String JavaDoc nullValue) {
358         if (this.htmlPost != null) {
359             return this.htmlPost;
360         }
361
362         return nullValue;
363     }
364
365     public void setType(int i) {
366         this.type = i;
367     }
368
369     public void setType(String JavaDoc s) {
370         this.type = PropertyType.valueFromName(s);
371     }
372
373     public int getType() {
374         return this.type;
375     }
376
377     public void setSaveInfo(boolean b) {
378         this.saveInfo = b;
379     }
380
381     public boolean getSaveInfo() {
382         return this.saveInfo;
383     }
384
385     public void setCssClass(String JavaDoc s) {
386         this.cssClass = s;
387     }
388
389     public String JavaDoc getCssClass() {
390         return this.cssClass;
391     }
392
393     public String JavaDoc getHtmlCssClass() {
394         if (StringUtils.isNotEmpty(this.getCssClass())) {
395             return " class=\"" + this.getCssClass() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
396
}
397
398         return StringUtils.EMPTY;
399     }
400
401     public String JavaDoc getHtmlSaveInfo() {
402         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
403         if (this.getSaveInfo()) {
404             html.append("<input type=\"hidden\""); //$NON-NLS-1$
405
html.append(" name=\"mgnlSaveInfo\""); //$NON-NLS-1$
406
html.append(" value=\"" //$NON-NLS-1$
407
+ this.getName() + "," //$NON-NLS-1$
408
+ PropertyType.nameFromValue(this.getType()) + "," //$NON-NLS-1$
409
+ this.getValueType() + "," //$NON-NLS-1$
410
+ this.getIsRichEditValue() + "," //$NON-NLS-1$
411
+ this.getEncoding() + "\""); //$NON-NLS-1$
412
html.append(" />"); //$NON-NLS-1$
413
}
414         return html.toString();
415     }
416
417     public void setCssStyles(Map JavaDoc h) {
418         this.cssStyles = h;
419     }
420
421     public void setCssStyles(String JavaDoc key, String JavaDoc value) {
422         this.getCssStyles().put(key, value);
423     }
424
425     public Map JavaDoc getCssStyles() {
426         return this.cssStyles;
427     }
428
429     public String JavaDoc getCssStyles(String JavaDoc key, String JavaDoc nullValue) {
430         if (this.getCssStyles().containsKey(key)) {
431             return (String JavaDoc) this.getCssStyles().get(key);
432         }
433         return nullValue;
434     }
435
436     public String JavaDoc getCssStyles(String JavaDoc key) {
437         return this.getCssStyles(key, StringUtils.EMPTY);
438     }
439
440     public String JavaDoc getHtmlCssStyles() {
441         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
442         Iterator JavaDoc en = this.getCssStyles().keySet().iterator();
443         while (en.hasNext()) {
444             String JavaDoc key = (String JavaDoc) en.next();
445             html.append(key + ":" + this.getCssStyles().get(key) + ";"); //$NON-NLS-1$ //$NON-NLS-2$
446
}
447         if (html.length() > 0) {
448             return " style=\"" + html + "\""; //$NON-NLS-1$ //$NON-NLS-2$
449
}
450         return StringUtils.EMPTY;
451     }
452
453     public void setValueType(int i) {
454         this.valueType = i;
455     }
456
457     public int getValueType() {
458         return this.valueType;
459     }
460
461     public void setEncoding(int i) {
462         this.encoding = i;
463     }
464
465     public int getEncoding() {
466         return this.encoding;
467     }
468
469     public void setIsRichEditValue(int i) {
470         this.isRichEditValue = i;
471     }
472
473     public int getIsRichEditValue() {
474         return this.isRichEditValue;
475     }
476
477     public static String JavaDoc escapeHTML(String JavaDoc str) {
478         return str.replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
479
}
480
481 }
482
Popular Tags