KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > field > TextareaFieldTag


1 package fr.improve.struts.taglib.layout.field;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import org.apache.struts.taglib.html.BaseHandlerTag;
6 import org.apache.struts.taglib.html.TextareaTag;
7 /**
8  * Insert the type's description here.
9  * Creation date: (01/12/2001 02:18:46)
10  * @author: Jean-NoŽl Ribette
11  */

12 public class TextareaFieldTag extends AbstractFieldTag {
13     TextareaTag textareaTag = new org.apache.struts.taglib.html.TextareaTag();
14     boolean textAreaFilter;
15     
16     protected boolean doBeforeValue() throws javax.servlet.jsp.JspException JavaDoc {
17     fieldTag = textareaTag;
18     textAreaFilter = filter;
19     filter = false;
20     return true;
21 }
22 protected Object JavaDoc getFieldValue() throws JspException JavaDoc {
23     Object JavaDoc lc_value = super.getFieldValue();
24     switch (getFieldDisplayMode()) {
25         case MODE_EDIT :
26             return lc_value;
27         case MODE_NODISPLAY :
28             return lc_value;
29         case MODE_INSPECT :
30         case MODE_INSPECT_ONLY :
31         case MODE_INSPECT_PRESENT :
32             if (lc_value == null) {
33                 return null;
34             }
35             // Remplacement des \n par des <br>, des \t par des escapes et coupure des mots trop longs.
36
StringBuffer JavaDoc lc_formattedBuffer = new StringBuffer JavaDoc(lc_value.toString());
37             int lc_numberOfConsecutiveCharacter = 0;
38             for (int i = 0; i < lc_formattedBuffer.length(); i++) {
39                 lc_numberOfConsecutiveCharacter++;
40                 if (lc_formattedBuffer.charAt(i) == ' ') {
41                     lc_numberOfConsecutiveCharacter = 0;
42                     continue;
43                 }
44
45                 if (lc_numberOfConsecutiveCharacter >= 80) {
46                     lc_formattedBuffer.insert(i, " ");
47                     lc_numberOfConsecutiveCharacter = 0;
48                     continue;
49                 }
50                 if (lc_formattedBuffer.charAt(i) == '\n') {
51                     lc_formattedBuffer.replace(i, i + 1, "<br>");
52                     i += 3;
53                     lc_numberOfConsecutiveCharacter = 0;
54                     continue;
55                 }
56                 if (lc_formattedBuffer.charAt(i) == '\t') {
57                     lc_formattedBuffer.replace(i, i + 1, "&nbsp;&nbsp;&nbsp;&nbsp;");
58                     lc_numberOfConsecutiveCharacter = 0;
59                     continue;
60                 }
61                 if (lc_formattedBuffer.charAt(i) == '<' && textAreaFilter) {
62                     lc_formattedBuffer.replace(i, i + 1, "&lt;");
63                     continue;
64                 }
65                 if (lc_formattedBuffer.charAt(i) == '>' && textAreaFilter) {
66                     lc_formattedBuffer.replace(i, i + 1, "&gt;");
67                     continue;
68                 }
69                 if (lc_formattedBuffer.charAt(i) == '"') {
70                     // Double quote breaks the hidden field in inspect mode.
71
lc_formattedBuffer.replace(i, i+1, "&quot;");
72                     continue;
73                 }
74             }
75             return lc_formattedBuffer.toString();
76     }
77     return lc_value;
78 }
79     
80     protected void doAfterValue() throws JspException JavaDoc {
81         filter = textAreaFilter;
82     }
83
84     protected void copyProperties(BaseHandlerTag in_dest) throws JspException JavaDoc {
85         super.copyProperties(in_dest);
86         textareaTag.setCols(getCols());
87         textareaTag.setMaxlength(getMaxlength());
88         textareaTag.setProperty(getProperty());
89         textareaTag.setRows(getRows());
90         textareaTag.setValue(getValue());
91         textareaTag.setName(getName());
92     }
93
94 }
95
Popular Tags