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            @Override
076            public int doStartTag() throws ApplicationException     {
077            if(param.getName()==null &&
078                    (!"body".equalsIgnoreCase(param.getType()) &&
079                    !"xml".equalsIgnoreCase(param.getType()))) {
080                throw new ApplicationException("attribute [name] is required for tag [httpparam] if type is not [body or xml]");
081            }
082            
083                    // get HTTP Tag
084                    Tag parent=getParent();
085                    while(parent!=null && !(parent instanceof Http)) {
086                            parent=parent.getParent();
087                    }
088                    
089                    if(parent instanceof Http) {
090                            Http http = (Http)parent;
091                            http.setParam(param);
092                    }
093                    else {
094                            throw new ApplicationException("Wrong Context, tag HttpParam must be inside a Http tag");       
095                    }
096                    return SKIP_BODY;
097            }
098    
099            @Override
100            public int doEndTag()   {
101                    return EVAL_PAGE;
102            }
103    
104            @Override
105            public void release()   {
106                    super.release();
107                    param=new HttpParamBean();
108            }
109    }