KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > portlet > PortletSessionParameterProvider


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jul 11, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.ui.portlet;
19
20 import java.util.Date JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.portlet.PortletSession;
24
25 import org.pentaho.core.session.IPentahoSession;
26 import org.pentaho.core.solution.BaseParameterProvider;
27 import org.pentaho.core.solution.IParameterSetter;
28
29 public class PortletSessionParameterProvider extends BaseParameterProvider implements IParameterSetter {
30
31     private IPentahoSession session;
32
33     public PortletSessionParameterProvider(IPentahoSession session) {
34         this.session = session;
35     }
36
37     public Object JavaDoc getParameter(String JavaDoc name) {
38         if ("name".equals(name)) { //$NON-NLS-1$
39
return session.getName();
40         }
41         
42         if (session instanceof PentahoPortletSession) {
43             PentahoPortletSession portletSession = (PentahoPortletSession) session;
44             Object JavaDoc value = portletSession.getAttribute(name, PortletSession.PORTLET_SCOPE);
45             if (value != null) {
46                 return value;
47             }
48             // now look at the application level
49
value = portletSession.getAttribute(name, PortletSession.APPLICATION_SCOPE);
50             return value;
51         } else {
52             return session.getAttribute(name);
53         }
54     }
55
56     public String JavaDoc getStringParameter(String JavaDoc name, String JavaDoc defaultValue) {
57       Object JavaDoc valueObject = getParameter(name);
58       if (valueObject != null) {
59         return valueObject.toString();
60       }
61       return defaultValue;
62     }
63
64     protected String JavaDoc getValue(String JavaDoc name) {
65         return getStringParameter(name, null);
66     }
67
68     public void setParameter(String JavaDoc name, String JavaDoc value) {
69         session.setAttribute(name, value);
70     }
71
72     public void setParameter(String JavaDoc name, long value) {
73         setParameter(name, Long.toString(value));
74     }
75
76     public void setParameter(String JavaDoc name, Date JavaDoc value) {
77         session.setAttribute(name, value);
78     }
79
80     public void setParameter(String JavaDoc name, Object JavaDoc value) {
81         session.setAttribute(name, value);
82     }
83
84     public Iterator JavaDoc getParameterNames() {
85         return session.getAttributeNames();
86     }
87
88 }
89
Popular Tags