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 /** 035 * @see javax.servlet.jsp.tagext.Tag#release() 036 */ 037 public void release() { 038 super.release(); 039 text=""; 040 width=-1; 041 align=Table.ALIGN_LEFT; 042 header=""; 043 } 044 045 /** set the value text 046 * Double-quote delimited text that determines what displays in the column. The rules for the text 047 * attribute are identical to the rules for cfoutput sections; it can consist of a combination of 048 * literal text, HTML tags, and query record set field references. You can embed hyperlinks, image 049 * references, and input controls in columns. 050 * @param text value to set 051 **/ 052 public void setText(String text) { 053 this.text=text; 054 } 055 056 /** set the value width 057 * The width of the column in characters (the default is 20). If the length of the data displayed exceeds the width value, 058 * the data is truncated to fit. 059 * @param width value to set 060 **/ 061 public void setWidth(double width) { 062 this.width=(int)width; 063 if(this.width<0)this.width=-1; 064 } 065 066 /** set the value align 067 * Column alignment, Left, Right, or Center. 068 * @param align value to set 069 * @throws ApplicationException 070 **/ 071 public void setAlign(String align) throws ApplicationException { 072 align=StringUtil.toLowerCase(align); 073 if(align.equals("left"))this.align=Table.ALIGN_LEFT; 074 else if(align.equals("center"))this.align=Table.ALIGN_CENTER; 075 else if(align.equals("right"))this.align=Table.ALIGN_RIGHT; 076 else 077 throw new ApplicationException("value ["+align+"] of attribute align from tag col is invalid", 078 "valid values are [left, center, right]"); 079 } 080 081 /** set the value header 082 * The text for the column's header. 083 * @param header value to set 084 **/ 085 public void setHeader(String header) { 086 this.header=header; 087 } 088 089 090 /** 091 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 092 */ 093 public int doStartTag() throws ExpressionException, ApplicationException { 094 Tag parent=getParent(); 095 while(parent!=null && !(parent instanceof Table)) { 096 parent=parent.getParent(); 097 } 098 099 if(parent instanceof Table) { 100 Table table = (Table)parent; 101 table.setCol(header,text,align,width); 102 } 103 else throw new ApplicationException("invalid context for tag col, tag must be inside a table tag"); 104 105 return SKIP_BODY; 106 } 107 108 /** 109 * @see javax.servlet.jsp.tagext.Tag#doEndTag() 110 */ 111 public int doEndTag() { 112 return EVAL_PAGE; 113 } 114 }