KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > IReportScriptlet


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * IReportScriptlet.java
28  *
29  * Created on 26 settembre 2004, 16.25
30  *
31  */

32
33 package it.businesslogic.ireport;
34 import net.sf.jasperreports.engine.JRException;
35 import net.sf.jasperreports.engine.JRScriptletException;
36
37 import java.util.*;
38 /**
39  *
40  * @author Administrator
41  */

42 public class IReportScriptlet extends net.sf.jasperreports.engine.JRAbstractScriptlet
43 {
44         // Vector of things to collect...
45
HashMap series = new java.util.HashMap JavaDoc();
46         HashMap groupStarted = new java.util.HashMap JavaDoc();
47         
48     /**
49      *
50      */

51     public void beforeReportInit() throws JRScriptletException
52     {
53         }
54
55
56     /**
57      *
58      */

59     public void afterReportInit() throws JRScriptletException
60     {
61                
62         }
63
64
65     /**
66      *
67      */

68     public void beforePageInit() throws JRScriptletException
69     {
70
71     }
72
73
74     /**
75      *
76      */

77     public void afterPageInit() throws JRScriptletException
78     {
79     }
80
81
82     /**
83      *
84      */

85     public void beforeColumnInit() throws JRScriptletException
86     {
87     }
88
89
90     /**
91      *
92      */

93     public void afterColumnInit() throws JRScriptletException
94     {
95     }
96
97
98     /**
99      *
100      */

101     public void beforeGroupInit(String JavaDoc groupName) throws JRScriptletException
102     {
103             
104     }
105
106
107     /**
108      *
109      */

110     public void afterGroupInit(String JavaDoc groupName) throws JRScriptletException
111     {
112            resetSeries(groupName);
113         }
114
115
116     /**
117      *
118      */

119     public void beforeDetailEval() throws JRScriptletException
120     {
121     }
122
123
124     /**
125      *
126      */

127     public void afterDetailEval() throws JRScriptletException
128     {
129             processSeries();
130     }
131         
132         protected void processSeries()
133         {
134             // Looking for serie_to_calc in variables...
135
Set vars = variablesMap.keySet();
136             Iterator iter = vars.iterator();
137             while( iter.hasNext())
138             {
139                 String JavaDoc key = (String JavaDoc)iter.next();
140                 if (key.startsWith("SERIE_"))
141                 {
142                     Vector serie = (Vector)series.get(key);
143                     if (serie == null)
144                     {
145                         serie = new Vector();
146                         series.put(key,serie);
147                     }
148                     try {
149                         serie.add( getVariableValue(key) );
150                     } catch (Exception JavaDoc ex) {}
151                 }
152             }
153         }
154         
155         protected void resetSeries(String JavaDoc group)
156         {
157             // Looking for serie_to_calc in variables...
158
Set vars = variablesMap.keySet();
159             Iterator iter = vars.iterator();
160             while( iter.hasNext())
161             {
162                 String JavaDoc key = (String JavaDoc)iter.next();
163                 if (key.startsWith("SERIE_") && key.indexOf("G_" + group)> 0)
164                 {
165                     series.remove(key);
166                 }
167             }
168         }
169         
170         public String JavaDoc getSerieAsString(String JavaDoc name)
171         {
172             Vector v = (Vector)series.get(name);
173             Enumeration enum_v = v.elements();
174             String JavaDoc tot = "";
175             while (enum_v.hasMoreElements())
176             {
177                 String JavaDoc s = ""+enum_v.nextElement();
178                 tot += s + "\n";
179             }
180             
181             return tot;
182         }
183         
184         public Vector getSerie(String JavaDoc serieName)
185         {
186             
187             Vector v = (Vector)series.get(serieName);
188             if (v==null)
189             {
190                 v = new Vector();
191                 series.put(serieName, v);
192                 
193             }
194             
195             return v;
196         }
197         
198         
199         public Boolean JavaDoc addValueToSerie(String JavaDoc serieName, Object JavaDoc value)
200         {
201             Vector v = getSerie(serieName);
202             v.add( value );
203             return new Boolean JavaDoc(false);
204         }
205         
206         public Boolean JavaDoc resetSerie(String JavaDoc serieName)
207         {
208             series.remove(serieName);
209             return new Boolean JavaDoc(false);
210         }
211 }
212
Popular Tags