View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/cewolf/CewolfCategoryDataTag.java,v 1.2 2006/03/16 14:23:02 hkollmann Exp $
3    * $Revision: 1.2 $
4    * $Date: 2006/03/16 14:23:02 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib.cewolf;
25  
26  import java.util.HashMap;
27  
28  import javax.servlet.jsp.JspException;
29  
30  import de.laures.cewolf.taglib.DataAware;
31  import de.laures.cewolf.DatasetProducer;
32  
33  import org.jfree.data.category.DefaultCategoryDataset;
34  
35  import org.dbforms.taglib.AbstractDbBaseHandlerTag;
36  import org.dbforms.config.ResultSetVector;
37  /***
38   * 
39   * This tag defines CategoryData for cewolf
40   * 
41   * @author Henner Kollmann
42   * 
43   */
44  
45  public class CewolfCategoryDataTag extends AbstractDbBaseHandlerTag  {
46  	private String categoryField;
47  	private String dataField;
48  	private String seriesField;
49  	
50  
51      public String getSeriesField() {
52  		return seriesField;
53  	}
54  
55  
56  	public void setSeriesField(String seriesField) {
57  		this.seriesField = seriesField;
58  	}
59  
60  
61  	public int doEndTag() throws JspException {
62      	DefaultCategoryDataset ds = new DefaultCategoryDataset();
63      	ResultSetVector rsv = getParentForm().getResultSetVector();
64      	for (int i = 0; i < rsv.size(); i++) {
65          	Comparable c = (Comparable) rsv.getFieldAsObject(i, getCategoryField());
66      		if (c == null)
67       		   c = new String();	
68          	Comparable s = (Comparable) rsv.getFieldAsObject(i, getSeriesField());
69      		Number n = (Number) rsv.getFieldAsObject(i, getDataField());
70      		if (s == null)
71      		   s = new String();	
72      		ds.addValue(n, s, c);
73      	}
74      	DatasetProducer dataProducer = new DbFormsDatasetProducer(ds);
75          DataAware dw = (DataAware) findAncestorWithClass(this, DataAware.class);
76          dw.setDataProductionConfig(dataProducer, new HashMap(), false);
77          return SKIP_BODY;
78      }
79  
80  
81  	/***
82  	 * @return Returns the categoryField.
83  	 */
84  	public String getCategoryField() {
85  		return categoryField;
86  	}
87  	/***
88  	 * @param categoryField The categoryField to set.
89  	 */
90  	public void setCategoryField(String categoryField) {
91  		this.categoryField = categoryField;
92  	}
93  	/***
94  	 * @return Returns the dataField.
95  	 */
96  	public String getDataField() {
97  		return dataField;
98  	}
99  	/***
100 	 * @param dataField The dataField to set.
101 	 */
102 	public void setDataField(String dataField) {
103 		this.dataField = dataField;
104 	}
105 
106 	public void doFinally() {
107 		super.doFinally();
108 		categoryField = null;
109 		dataField = null;
110 		seriesField = null;
111 	}
112 	
113 }