1 package fr.improve.struts.taglib.layout.field; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.apache.struts.taglib.html.BaseHandlerTag; 6 import org.apache.struts.taglib.html.TextareaTag; 7 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 { 17 fieldTag = textareaTag; 18 textAreaFilter = filter; 19 filter = false; 20 return true; 21 } 22 protected Object getFieldValue() throws JspException { 23 Object 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 StringBuffer lc_formattedBuffer = new StringBuffer (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, " "); 58 lc_numberOfConsecutiveCharacter = 0; 59 continue; 60 } 61 if (lc_formattedBuffer.charAt(i) == '<' && textAreaFilter) { 62 lc_formattedBuffer.replace(i, i + 1, "<"); 63 continue; 64 } 65 if (lc_formattedBuffer.charAt(i) == '>' && textAreaFilter) { 66 lc_formattedBuffer.replace(i, i + 1, ">"); 67 continue; 68 } 69 if (lc_formattedBuffer.charAt(i) == '"') { 70 lc_formattedBuffer.replace(i, i+1, """); 72 continue; 73 } 74 } 75 return lc_formattedBuffer.toString(); 76 } 77 return lc_value; 78 } 79 80 protected void doAfterValue() throws JspException { 81 filter = textAreaFilter; 82 } 83 84 protected void copyProperties(BaseHandlerTag in_dest) throws JspException { 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 |