001 package railo.runtime.tag; 002 003 import javax.servlet.jsp.tagext.Tag; 004 005 import railo.commons.io.res.util.ResourceUtil; 006 import railo.runtime.exp.ApplicationException; 007 import railo.runtime.ext.tag.TagImpl; 008 009 /** 010 * Required for cfhttp POST operations, cfhttpparam is used to specify the parameters necessary to 011 * build a cfhttp POST. 012 * 013 * 014 * 015 **/ 016 public final class HttpParam extends TagImpl { 017 018 HttpParamBean param=new HttpParamBean(); 019 020 /** 021 * Applies to FormField and CGI types; ignored for all other types. 022 * Specifies whether to URLEncode the form field or header. 023 * @param encoded 024 */ 025 public void setEncoded(boolean encoded) { 026 param.setEncoded(encoded); 027 } 028 029 /** 030 * Applies to File type; invalid for all other types. 031 * Specifies the MIME media type of the file contents. 032 * The content type can include an identifier for the character encoding of the file; 033 * for example, text/html; charset=ISO-8859-1 indicates that the file is HTML text in 034 * the ISO Latin-1 character encoding. 035 * @param mimetype 036 */ 037 public void setMimetype(String mimetype) { 038 param.setMimeType(mimetype); 039 } 040 041 042 /** set the value value 043 * Specifies the value of the URL, FormField, Cookie, File, or CGI variable being passed. 044 * @param value value to set 045 **/ 046 public void setValue(Object value) { 047 param.setValue(value); 048 } 049 050 /** set the value type 051 * The transaction type. 052 * @param type value to set 053 **/ 054 public void setType(String type) { 055 param.setType(type); 056 } 057 058 /** set the value file 059 * Required for type = "File". 060 * @param file value to set 061 **/ 062 public void setFile(String file) { 063 param.setFile(ResourceUtil.toResourceNotExisting(pageContext,file)); 064 } 065 066 /** set the value name 067 * A variable name for the data being passed. 068 * @param name value to set 069 **/ 070 public void setName(String name) { 071 param.setName(name); 072 } 073 074 075 /** 076 * @throws ApplicationException 077 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 078 */ 079 public int doStartTag() throws ApplicationException { 080 if(param.getName()==null && 081 (!"body".equalsIgnoreCase(param.getType()) && 082 !"xml".equalsIgnoreCase(param.getType()))) { 083 throw new ApplicationException("attribute [name] is required for tag [httpparam] if type is not [body or xml]"); 084 } 085 086 // get HTTP Tag 087 Tag parent=getParent(); 088 while(parent!=null && !(parent instanceof Http)) { 089 parent=parent.getParent(); 090 } 091 092 if(parent instanceof Http) { 093 Http http = (Http)parent; 094 http.setParam(param); 095 } 096 else { 097 throw new ApplicationException("Wrong Context, tag HttpParam must be inside a Http tag"); 098 } 099 return SKIP_BODY; 100 } 101 102 /** 103 * @see javax.servlet.jsp.tagext.Tag#doEndTag() 104 */ 105 public int doEndTag() { 106 return EVAL_PAGE; 107 } 108 109 /** 110 * @see javax.servlet.jsp.tagext.Tag#release() 111 */ 112 public void release() { 113 super.release(); 114 param=new HttpParamBean(); 115 } 116 }