001    package railo.runtime.tag;
002    
003    import javax.servlet.jsp.tagext.Tag;
004    
005    import railo.commons.lang.StringUtil;
006    import railo.runtime.exp.ApplicationException;
007    import railo.runtime.exp.ExpressionException;
008    import railo.runtime.ext.tag.TagImpl;
009    
010    /**
011    * Defines table column header, width, alignment, and text. Used only inside a cftable.
012    *
013    *
014    *
015    **/
016    public final class Col extends TagImpl {
017    
018            /** Double-quote delimited text that determines what displays in the column. The rules for the text
019            **              attribute are identical to the rules for cfoutput sections; it can consist of a combination of 
020            **              literal text, HTML tags, and query record set field references. You can embed hyperlinks, image 
021            **              references, and input controls in columns. */
022            private String text="";
023    
024            /** The width of the column in characters (the default is 20). If the length of the data displayed exceeds the width value, 
025            **              the data is truncated to fit. */
026            private int width=-1;
027    
028            /** Column alignment, Left, Right, or Center. */
029            private short align=Table.ALIGN_LEFT;
030    
031            /** The text for the column's header. */
032            private String header="";
033    
034            @Override
035            public void release()   {
036                    super.release();
037                    text="";
038                    width=-1;
039                    align=Table.ALIGN_LEFT;
040                    header="";
041            }
042    
043            /** set the value text
044            *  Double-quote delimited text that determines what displays in the column. The rules for the text
045            *               attribute are identical to the rules for cfoutput sections; it can consist of a combination of 
046            *               literal text, HTML tags, and query record set field references. You can embed hyperlinks, image 
047            *               references, and input controls in columns.
048            * @param text value to set
049            **/
050            public void setText(String text)        {
051                    this.text=text;
052            }
053    
054            /** set the value width
055            *  The width of the column in characters (the default is 20). If the length of the data displayed exceeds the width value, 
056            *               the data is truncated to fit.
057            * @param width value to set
058            **/
059            public void setWidth(double width)      {
060                    this.width=(int)width;
061                    if(this.width<0)this.width=-1;
062            }
063    
064            /** set the value align
065            *  Column alignment, Left, Right, or Center.
066            * @param align value to set
067             * @throws ApplicationException
068            **/
069            public void setAlign(String align) throws ApplicationException  {
070                    align=StringUtil.toLowerCase(align);
071                    if(align.equals("left"))this.align=Table.ALIGN_LEFT;
072                    else if(align.equals("center"))this.align=Table.ALIGN_CENTER;
073                    else if(align.equals("right"))this.align=Table.ALIGN_RIGHT;
074                    else
075                        throw new ApplicationException("value ["+align+"] of attribute align from tag col is invalid",
076                            "valid values are [left, center, right]");
077            }
078    
079            /** set the value header
080            *  The text for the column's header.
081            * @param header value to set
082            **/
083            public void setHeader(String header)    {
084                    this.header=header;
085            }
086    
087    
088            @Override
089            public int doStartTag() throws ExpressionException, ApplicationException        {
090                    Tag parent=getParent();
091                    while(parent!=null && !(parent instanceof Table)) {
092                            parent=parent.getParent();
093                    }
094                    
095                    if(parent instanceof Table) {
096                        Table table = (Table)parent;
097                        table.setCol(header,text,align,width);
098                    }
099                    else throw new ApplicationException("invalid context for tag col, tag must be inside a table tag");
100                
101                    return SKIP_BODY;
102            }
103    
104            @Override
105            public int doEndTag()   {
106                    return EVAL_PAGE;
107            }
108    }