View Javadoc
1   /*
2    * JaspertReports JSF Plugin Copyright (C) 2011 A. Alonso Dominguez
3    *
4    * This library is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as published by
6    * the Free Software Foundation; either version 2.1 of the License, or (at
7    * your option) any later version. This library is distributed in the hope
8    * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9    * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   *
11   * See the GNU Lesser General Public License for more details. You should have
12   * received a copy of the GNU Lesser General Public License along with this
13   * library; if not, write to the Free Software Foundation, Inc., 59 Temple
14   * Place, Suite 330, Boston, MA 02111-1307 USA A.
15   *
16   * Alonso Dominguez
17   * alonsoft@users.sf.net
18   */
19  
20  package net.sf.jasperreports.jsf.context;
21  
22  import java.util.Collections;
23  import java.util.Enumeration;
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import javax.faces.render.ResponseStateManager;
28  import javax.portlet.ResourceRequest;
29  import javax.portlet.faces.Bridge;
30  import javax.portlet.filter.ResourceRequestWrapper;
31  
32  import net.sf.jasperreports.jsf.Constants;
33  
34  /**
35   *
36   * @author A. Alonso Dominguez
37   */
38  final class ReportPortletRenderRequest extends ResourceRequestWrapper
39          implements ReportRenderRequest {
40  
41      private final String oldViewId;
42      private final String viewState;
43  
44      public ReportPortletRenderRequest(ResourceRequest request,
45      		String facesMapping, String viewId, String viewState) {
46          super(request);
47          
48          this.oldViewId = (String) request.getAttribute(Bridge.VIEW_ID);
49          request.setAttribute(Bridge.VIEW_ID, viewId);
50          this.viewState = viewState;
51      }
52  
53      @Override
54      public String getParameter(String name) {
55          String[] values = getParameterValues(name);
56          if (values == null || values.length == 0) {
57              return null;
58          } else {
59              return values[0];
60          }
61      }
62  
63      @Override
64      public Map<String, String[]> getParameterMap() {
65          Map<String, String[]> paramMap = new HashMap<String, String[]>();
66          paramMap.putAll(super.getParameterMap());
67          paramMap.put(ResponseStateManager.VIEW_STATE_PARAM,
68                  new String[]{viewState});
69          return Collections.unmodifiableMap(paramMap);
70      }
71  
72      @Override
73      public Enumeration<String> getParameterNames() {
74          return Collections.enumeration(getParameterMap().keySet());
75      }
76  
77      @Override
78      public String[] getParameterValues(String name) {
79          return getParameterMap().get(name);
80      }
81  
82      public String getReportClientId() {
83          return getRequest().getParameter(Constants.PARAM_CLIENTID);
84      }
85  
86      public String getViewId() {
87          return (String) getRequest().getAttribute(Bridge.VIEW_ID);
88      }
89  
90      public void release() {
91          getRequest().setAttribute(Bridge.VIEW_ID, oldViewId);
92      }
93  
94  }