01: /* ============================================================================
02: * GNU Lesser General Public License
03: * ============================================================================
04: *
05: * Copyright (C) 2001-2007 JasperSoft Corporation http://www.jaspersoft.com
06: *
07: * This class is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This class is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this class; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * JasperSoft Corporation
22: * 303 Second Street, Suite 450 North
23: * San Francisco, CA 94107
24: * http://www.jaspersoft.com
25: *
26: *
27: *
28: * ReportUtils.java
29: *
30: */
31:
32: package it.businesslogic.ireport.util;
33:
34: import java.util.*;
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 encodeParameters(Map parametri1,
52: String[] parametri2) {
53: String url = "";
54: HashMap param_map = new HashMap();
55: if (parametri1 == null)
56: parametri1 = new HashMap();
57: if (parametri2 == null)
58: parametri2 = new String[] {};
59:
60: param_map.putAll(parametri1);
61:
62: for (int i = 0; i < parametri2.length; ++i) {
63:
64: if (parametri2[i].indexOf("=") > 0) {
65: String key = parametri2[i].substring(0, parametri2[i]
66: .indexOf("="));
67: String val = parametri2[i].substring(parametri2[i]
68: .indexOf("=") + 1);
69:
70: parametri1.put(key, val);
71: }
72: }
73:
74: Set keys = parametri1.keySet();
75: Iterator params_iterator = keys.iterator();
76: while (params_iterator.hasNext()) {
77: try {
78: String key = (String) params_iterator.next();
79: Object val = (Object) parametri1.get(key);
80:
81: if (url.length() > 0)
82: url += "&";
83:
84: url += java.net.URLEncoder.encode(key, "UTF-8") + "="
85: + java.net.URLEncoder.encode("" + val, "UTF-8");
86:
87: } catch (Exception ex) {
88: }
89: }
90:
91: return url;
92: }
93: }
|