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