KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > util > ReportUtils


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  * ReportUtils.java
28  *
29  */

30
31 package it.businesslogic.ireport.util;
32
33 import java.util.*;
34
35
36 public class ReportUtils {
37     
38     /**
39         Esempio di utilizzo:
40         
41         encodeParameters($P{REPORT_MAP},
42                 new String[]{
43                    "REPORT_ID=107",
44                    "02_Area_Manager_ID=" + $F{Manager_ID},
45                    "PIPPO=Pluto"
46                 });
47         
48         Ii parametri2 hanno precedenza su parametri1
49     
50     */

51     public static String JavaDoc encodeParameters(Map parametri1, String JavaDoc[] parametri2)
52     {
53         String JavaDoc url = "";
54         HashMap param_map = new HashMap();
55         if (parametri1 == null) parametri1 = new HashMap();
56         if (parametri2 == null) parametri2 = new String JavaDoc[]{};
57         
58         param_map.putAll( parametri1 );
59         
60         for (int i=0; i<parametri2.length; ++i)
61         {
62             
63             if (parametri2[i].indexOf("=") > 0)
64             {
65                 String JavaDoc key = parametri2[i].substring(0, parametri2[i].indexOf("="));
66                 String JavaDoc val = parametri2[i].substring(parametri2[i].indexOf("=")+1);
67                 
68                 parametri1.put(key, val);
69             }
70         }
71         
72         Set keys = parametri1.keySet();
73         Iterator params_iterator = keys.iterator();
74         while (params_iterator.hasNext())
75         {
76             try {
77                 String JavaDoc key = (String JavaDoc)params_iterator.next();
78                 Object JavaDoc val = (Object JavaDoc)parametri1.get(key);
79             
80                 if (url.length() > 0) url += "&";
81             
82                 url += java.net.URLEncoder.encode(key,"UTF-8") + "=" + java.net.URLEncoder.encode(""+val,"UTF-8");
83             
84             } catch (Exception JavaDoc ex)
85             {}
86         }
87         
88         return url;
89     }
90 }
91
Popular Tags