001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import javax.servlet.jsp.tagext.Tag; 022 023import lucee.commons.lang.StringUtil; 024import lucee.runtime.exp.ApplicationException; 025import lucee.runtime.exp.ExpressionException; 026import lucee.runtime.ext.tag.TagImpl; 027 028/** 029* Defines table column header, width, alignment, and text. Used only inside a cftable. 030* 031* 032* 033**/ 034public final class Col extends TagImpl { 035 036 /** Double-quote delimited text that determines what displays in the column. The rules for the text 037 ** attribute are identical to the rules for cfoutput sections; it can consist of a combination of 038 ** literal text, HTML tags, and query record set field references. You can embed hyperlinks, image 039 ** references, and input controls in columns. */ 040 private String text=""; 041 042 /** The width of the column in characters (the default is 20). If the length of the data displayed exceeds the width value, 043 ** the data is truncated to fit. */ 044 private int width=-1; 045 046 /** Column alignment, Left, Right, or Center. */ 047 private short align=Table.ALIGN_LEFT; 048 049 /** The text for the column's header. */ 050 private String header=""; 051 052 @Override 053 public void release() { 054 super.release(); 055 text=""; 056 width=-1; 057 align=Table.ALIGN_LEFT; 058 header=""; 059 } 060 061 /** set the value text 062 * Double-quote delimited text that determines what displays in the column. The rules for the text 063 * attribute are identical to the rules for cfoutput sections; it can consist of a combination of 064 * literal text, HTML tags, and query record set field references. You can embed hyperlinks, image 065 * references, and input controls in columns. 066 * @param text value to set 067 **/ 068 public void setText(String text) { 069 this.text=text; 070 } 071 072 /** set the value width 073 * The width of the column in characters (the default is 20). If the length of the data displayed exceeds the width value, 074 * the data is truncated to fit. 075 * @param width value to set 076 **/ 077 public void setWidth(double width) { 078 this.width=(int)width; 079 if(this.width<0)this.width=-1; 080 } 081 082 /** set the value align 083 * Column alignment, Left, Right, or Center. 084 * @param align value to set 085 * @throws ApplicationException 086 **/ 087 public void setAlign(String align) throws ApplicationException { 088 align=StringUtil.toLowerCase(align); 089 if(align.equals("left"))this.align=Table.ALIGN_LEFT; 090 else if(align.equals("center"))this.align=Table.ALIGN_CENTER; 091 else if(align.equals("right"))this.align=Table.ALIGN_RIGHT; 092 else 093 throw new ApplicationException("value ["+align+"] of attribute align from tag col is invalid", 094 "valid values are [left, center, right]"); 095 } 096 097 /** set the value header 098 * The text for the column's header. 099 * @param header value to set 100 **/ 101 public void setHeader(String header) { 102 this.header=header; 103 } 104 105 106 @Override 107 public int doStartTag() throws ExpressionException, ApplicationException { 108 Tag parent=getParent(); 109 while(parent!=null && !(parent instanceof Table)) { 110 parent=parent.getParent(); 111 } 112 113 if(parent instanceof Table) { 114 Table table = (Table)parent; 115 table.setCol(header,text,align,width); 116 } 117 else throw new ApplicationException("invalid context for tag col, tag must be inside a table tag"); 118 119 return SKIP_BODY; 120 } 121 122 @Override 123 public int doEndTag() { 124 return EVAL_PAGE; 125 } 126}