001 package railo.runtime.tag; 002 003 import java.awt.Color; 004 005 import javax.servlet.jsp.JspException; 006 import javax.servlet.jsp.tagext.Tag; 007 008 import railo.commons.color.ColorCaster; 009 import railo.commons.lang.StringUtil; 010 import railo.runtime.exp.ApplicationException; 011 import railo.runtime.exp.ExpressionException; 012 import railo.runtime.exp.PageException; 013 import railo.runtime.ext.tag.BodyTagImpl; 014 import railo.runtime.op.Caster; 015 import railo.runtime.type.Query; 016 import railo.runtime.type.util.ListUtil; 017 018 public final class Chartseries extends BodyTagImpl { 019 020 private ChartSeriesBean series=new ChartSeriesBean(); 021 private String itemColumn; 022 private Query query; 023 private String valueColumn; 024 025 @Override 026 public void release() { 027 super.release(); 028 series=new ChartSeriesBean(); 029 itemColumn=null; 030 valueColumn=null; 031 query=null; 032 } 033 /** 034 * @param colorlist the colorlist to set 035 * @throws ExpressionException 036 */ 037 public void setColorlist(String strColorlist) throws ExpressionException { 038 String[] arr=ListUtil.listToStringArray(strColorlist.trim(),','); 039 Color[] colorlist=new Color[arr.length]; 040 for(int i=0;i<arr.length;i++) { 041 colorlist[i]=ColorCaster.toColor(arr[i]); 042 } 043 series.setColorlist(colorlist); 044 } 045 /** 046 * @param dataLabelStyle the dataLabelStyle to set 047 * @throws ExpressionException 048 */ 049 public void setDatalabelstyle(String strDataLabelStyle) throws ExpressionException { 050 strDataLabelStyle=strDataLabelStyle.trim().toLowerCase(); 051 052 if("none".equals(strDataLabelStyle)) series.setDataLabelStyle(ChartSeriesBean.DATA_LABEL_STYLE_NONE); 053 else if("value".equals(strDataLabelStyle)) series.setDataLabelStyle(ChartSeriesBean.DATA_LABEL_STYLE_VALUE); 054 else if("rowlabel".equals(strDataLabelStyle)) series.setDataLabelStyle(ChartSeriesBean.DATA_LABEL_STYLE_ROWLABEL); 055 else if("columnlabel".equals(strDataLabelStyle))series.setDataLabelStyle(ChartSeriesBean.DATA_LABEL_STYLE_COLUMNLABEL); 056 else if("pattern".equals(strDataLabelStyle)) series.setDataLabelStyle(ChartSeriesBean.DATA_LABEL_STYLE_PATTERN); 057 058 else throw new ExpressionException("invalid value ["+strDataLabelStyle+"] for attribute dataLabelStyle, for this attribute only the following values are supported " + 059 "[none, value, rowlabel, columnlabel, pattern]"); 060 } 061 /** 062 * @param itemColumn the itemColumn to set 063 */ 064 public void setItemcolumn(String itemColumn) { 065 this.itemColumn=itemColumn; 066 } 067 /** 068 * @param markerStyle the markerStyle to set 069 * @throws ExpressionException 070 */ 071 public void setMarkerstyle(String strMarkerStyle) throws ExpressionException { 072 strMarkerStyle=strMarkerStyle.trim().toLowerCase(); 073 074 if("circle".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_CIRCLE); 075 else if("diamond".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_DIAMOND); 076 else if("letter".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_LETTER); 077 else if("mcross".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_MCROSS); 078 else if("rcross".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_RCROSS); 079 else if("rectangle".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_RECTANGLE); 080 else if("snow".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_SNOW); 081 else if("triangle".equals(strMarkerStyle)) series.setMarkerStyle(ChartSeriesBean.MARKER_STYLE_TRIANGLE); 082 083 else throw new ExpressionException("invalid value ["+strMarkerStyle+"] for attribute markerStyle, for this attribute only the following values are supported " + 084 "[circle, diamond, letter, mcross, rcross, rectangle, snow, triangle]"); 085 } 086 /** 087 * @param paintStyle the paintStyle to set 088 * @throws ExpressionException 089 */ 090 public void setPaintstyle(String strPaintStyle) throws ExpressionException { 091 strPaintStyle=strPaintStyle.trim().toLowerCase(); 092 093 if("light".equals(strPaintStyle)) series.setPaintStyle(ChartSeriesBean.PAINT_STYLE_LIGHT); 094 else if("plain".equals(strPaintStyle)) series.setPaintStyle(ChartSeriesBean.PAINT_STYLE_PLAIN); 095 else if("raise".equals(strPaintStyle)) series.setPaintStyle(ChartSeriesBean.PAINT_STYLE_RAISE); 096 else if("shade".equals(strPaintStyle)) series.setPaintStyle(ChartSeriesBean.PAINT_STYLE_SHADE); 097 098 else throw new ExpressionException("invalid value ["+strPaintStyle+"] for attribute paintStyle, for this attribute only the following values are supported " + 099 "[light, plain, raise, shade]"); 100 } 101 /** 102 * @param query the query to set 103 * @throws PageException 104 */ 105 public void setQuery(Object oQuery) throws PageException { 106 if(oQuery instanceof Query) this.query=(Query)oQuery; 107 else if(oQuery instanceof String) this.query=pageContext.getQuery((String)oQuery); 108 else query=Caster.toQuery(oQuery); 109 } 110 /** 111 * @param seriesColor the seriesColor to set 112 * @throws ExpressionException 113 */ 114 public void setSeriescolor(String strSeriesColor) throws ExpressionException { 115 series.setSeriesColor(ColorCaster.toColor(strSeriesColor)); 116 } 117 /** 118 * @param seriesLabel the seriesLabel to set 119 */ 120 public void setSerieslabel(String seriesLabel) { 121 series.setSeriesLabel(seriesLabel); 122 } 123 /** 124 * @param type the type to set 125 * @throws ExpressionException 126 */ 127 public void setType(String strType) throws ExpressionException { 128 strType=strType.trim().toLowerCase(); 129 130 if("area".equals(strType)) series.setType(ChartSeriesBean.TYPE_AREA); 131 else if("bar".equals(strType)) series.setType(ChartSeriesBean.TYPE_BAR); 132 else if("cone".equals(strType)) series.setType(ChartSeriesBean.TYPE_CONE); 133 else if("curve".equals(strType)) series.setType(ChartSeriesBean.TYPE_CURVE); 134 else if("cylinder".equals(strType)) series.setType(ChartSeriesBean.TYPE_CYLINDER); 135 else if("horizontalbar".equals(strType)) series.setType(ChartSeriesBean.TYPE_HORIZONTALBAR); 136 else if("line".equals(strType)) series.setType(ChartSeriesBean.TYPE_LINE); 137 else if("timeline".equals(strType)) series.setType(ChartSeriesBean.TYPE_TIME); 138 else if("time".equals(strType)) series.setType(ChartSeriesBean.TYPE_TIME); 139 else if("pie".equals(strType)) series.setType(ChartSeriesBean.TYPE_PIE); 140 else if("pyramid".equals(strType)) series.setType(ChartSeriesBean.TYPE_PYRAMID); 141 else if("scatter".equals(strType)) series.setType(ChartSeriesBean.TYPE_SCATTER); 142 else if("scatte".equals(strType)) series.setType(ChartSeriesBean.TYPE_SCATTER); 143 else if("step".equals(strType)) series.setType(ChartSeriesBean.TYPE_STEP); 144 145 else throw new ExpressionException("invalid value ["+strType+"] for attribute type, for this attribute only the following values are supported " + 146 "[area, bar, cone, curve, cylinder, horizontalbar, line,pie,pyramid,scatter,step,timeline]"); 147 } 148 /** 149 * @param valueColumn the valueColumn to set 150 */ 151 public void setValuecolumn(String valueColumn) { 152 this.valueColumn=valueColumn; 153 } 154 155 public void addChartData(ChartDataBean data) { 156 series.addChartData(data); 157 } 158 159 160 public int doStartTag() { 161 return EVAL_BODY_INCLUDE; 162 } 163 164 @Override 165 public int doEndTag() throws JspException { 166 167 ChartDataBean data; 168 169 if(query!=null) { 170 if(StringUtil.isEmpty(itemColumn)) throw new ApplicationException("attribute itemColumn is required for tag cfchartseries when attribute query is defined"); 171 if(StringUtil.isEmpty(valueColumn)) throw new ApplicationException("attribute valueColumn is required for tag cfchartseries when attribute query is defined"); 172 173 int rowCount = query.getRecordcount(); 174 for(int i=1;i<=rowCount;i++) { 175 data=new ChartDataBean(); 176 data.setValue(Caster.toDoubleValue(query.getAt(valueColumn, i, new Double(0)))); 177 data.setItem(pageContext,query.getAt(itemColumn, i, "")); 178 //data.setItem(itemToString(query.getAt(itemColumn, i, ""))); 179 addChartData(data); 180 } 181 } 182 // get parent chart 183 Tag parent=this; 184 do{ 185 parent = parent.getParent(); 186 if(parent instanceof Chart) { 187 ((Chart)parent).addChartSeries(series); 188 break; 189 } 190 } 191 while(parent!=null); 192 return EVAL_PAGE; 193 } 194 }