001 package railo.runtime.tag; 002 003 import java.io.IOException; 004 import java.util.Iterator; 005 import java.util.Map.Entry; 006 007 import javax.servlet.jsp.JspException; 008 import javax.servlet.jsp.tagext.BodyContent; 009 import javax.servlet.jsp.tagext.BodyTag; 010 011 import railo.commons.lang.StringUtil; 012 import railo.runtime.exp.ApplicationException; 013 import railo.runtime.exp.ExpressionException; 014 import railo.runtime.exp.PageException; 015 import railo.runtime.op.Caster; 016 import railo.runtime.type.Collection.Key; 017 import railo.runtime.type.util.KeyConstants; 018 019 // TODO tag textarea 020 // attribute html macht irgendwie keinen sinn, aber auch unter neo nicht 021 022 023 024 public final class Textarea extends Input implements BodyTag { 025 private static final String BASE_PATH = null; // TODO 026 private static final String STYLE_XML = null; 027 private static final String TEMPLATE_XML = null; 028 private static final String SKIN = "default"; 029 private static final String TOOLBAR = "default"; 030 031 private static final int WRAP_OFF = 0; 032 private static final int WRAP_HARD = 1; 033 private static final int WRAP_SOFT = 2; 034 private static final int WRAP_PHYSICAL = 3; 035 private static final int WRAP_VIRTUAL = 4; 036 037 private BodyContent bodyContent=null; 038 039 private String basepath=BASE_PATH; 040 private String fontFormats=null; 041 private String fontNames=null; 042 private String fontSizes=null; 043 044 private boolean html=false; 045 private boolean richText=false; 046 private String skin=SKIN; 047 private String stylesXML=STYLE_XML; 048 private String templatesXML=TEMPLATE_XML; 049 private String toolbar=TOOLBAR; 050 private boolean toolbarOnFocus=false; 051 private int wrap=WRAP_OFF; 052 053 @Override 054 public void release() { 055 super.release(); 056 bodyContent=null; 057 058 059 basepath=BASE_PATH; 060 fontFormats=null; 061 fontNames=null; 062 fontSizes=null; 063 064 html=false; 065 richText=false; 066 skin=SKIN; 067 stylesXML=STYLE_XML; 068 templatesXML=TEMPLATE_XML; 069 toolbar=TOOLBAR; 070 toolbarOnFocus=false; 071 wrap=WRAP_OFF; 072 } 073 074 public void setCols(double cols) throws PageException { 075 attributes.set("cols", Caster.toString(cols)); 076 } 077 public void setRows(double rows) throws PageException { 078 attributes.set("rows", Caster.toString(rows)); 079 } 080 public void setBasepath(String basepath) { 081 this.basepath=basepath; 082 } 083 public void setFontFormats(String fontFormats) { 084 this.fontFormats=fontFormats; 085 } 086 public void setFontNames(String fontNames) { 087 this.fontNames=fontNames; 088 } 089 public void setFontSizes(String fontSizes) { 090 this.fontSizes=fontSizes; 091 } 092 public void setHtml(boolean html) { 093 this.html=html; 094 } 095 public void setRichtext(boolean richText) { 096 this.richText = richText; 097 } 098 public void setSkin(String skin) { 099 this.skin = skin; 100 } 101 public void setStylesxml(String stylesXML) { 102 this.stylesXML = stylesXML; 103 } 104 public void setTemplatesxml(String templatesXML) { 105 this.templatesXML = templatesXML; 106 } 107 public void setToolbar(String toolbar) { 108 this.toolbar = toolbar; 109 } 110 public void setToolbaronfocus(boolean toolbarOnFocus) { 111 this.toolbarOnFocus = toolbarOnFocus; 112 } 113 public void setWrap(String strWrap) throws ExpressionException { 114 strWrap=strWrap.trim().toLowerCase(); 115 if("hard".equals(strWrap)) wrap=WRAP_HARD; 116 else if("soft".equals(strWrap)) wrap=WRAP_SOFT; 117 else if("off".equals(strWrap)) wrap=WRAP_OFF; 118 else if("physical".equals(strWrap)) wrap=WRAP_PHYSICAL; 119 else if("virtual".equals(strWrap)) wrap=WRAP_VIRTUAL; 120 else throw new ExpressionException("invalid value ["+strWrap+"] for attribute wrap, valid values are [hard,soft,off,physical,virtual]"); 121 } 122 123 @Override 124 void draw() throws IOException, PageException { 125 126 // value 127 String attrValue=null; 128 String bodyValue=null; 129 String value=""; 130 if(bodyContent!=null)bodyValue=bodyContent.getString(); 131 if(attributes.containsKey(KeyConstants._value))attrValue=Caster.toString(attributes.get(KeyConstants._value,null)); 132 133 // check values 134 if(!StringUtil.isEmpty(bodyValue) && !StringUtil.isEmpty(attrValue)) { 135 throw new ApplicationException("the value of tag can't be set twice (tag body and attribute value)"); 136 } 137 else if(!StringUtil.isEmpty(bodyValue)){ 138 value=enc(bodyValue); 139 } 140 else if(!StringUtil.isEmpty(attrValue)){ 141 value=enc(attrValue); 142 } 143 // id 144 if(StringUtil.isEmpty(attributes.get(KeyConstants._id,null))) 145 attributes.set(KeyConstants._id,StringUtil.toVariableName((String)attributes.get(KeyConstants._name))); 146 147 // start output 148 pageContext.forceWrite("<textarea"); 149 150 Iterator<Entry<Key, Object>> it = attributes.entryIterator(); 151 Entry<Key, Object> e; 152 while(it.hasNext()) { 153 e = it.next(); 154 pageContext.forceWrite(" "); 155 pageContext.forceWrite(e.getKey().getString()); 156 pageContext.forceWrite("=\""); 157 pageContext.forceWrite(enc(Caster.toString(e.getValue()))); 158 pageContext.forceWrite("\""); 159 } 160 161 if(passthrough!=null) { 162 pageContext.forceWrite(" "); 163 pageContext.forceWrite(passthrough); 164 } 165 pageContext.forceWrite(">"); 166 pageContext.forceWrite(value); 167 pageContext.forceWrite("</textarea>"); 168 } 169 170 @Override 171 public int doStartTag() { 172 return EVAL_BODY_BUFFERED; 173 } 174 175 @Override 176 public void setBodyContent(BodyContent bodyContent) { 177 this.bodyContent=bodyContent; 178 } 179 180 @Override 181 public void doInitBody() throws JspException {} 182 183 @Override 184 public int doAfterBody() throws JspException { 185 return SKIP_BODY; 186 } 187 public void hasBody(boolean hasBody) { 188 189 } 190 }