01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * 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;
21: import java.util.Iterator;
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
30: BaseParameterProvider implements IParameterSetter {
31:
32: private IPentahoSession session;
33:
34: public PortletSessionParameterProvider(IPentahoSession session) {
35: this .session = session;
36: }
37:
38: public Object getParameter(String name) {
39: if ("name".equals(name)) { //$NON-NLS-1$
40: return session.getName();
41: }
42:
43: if (session instanceof PentahoPortletSession) {
44: PentahoPortletSession portletSession = (PentahoPortletSession) session;
45: Object value = portletSession.getAttribute(name,
46: PortletSession.PORTLET_SCOPE);
47: if (value != null) {
48: return value;
49: }
50: // now look at the application level
51: value = portletSession.getAttribute(name,
52: PortletSession.APPLICATION_SCOPE);
53: return value;
54: } else {
55: return session.getAttribute(name);
56: }
57: }
58:
59: public String getStringParameter(String name, String defaultValue) {
60: Object valueObject = getParameter(name);
61: if (valueObject != null) {
62: return valueObject.toString();
63: }
64: return defaultValue;
65: }
66:
67: protected String getValue(String name) {
68: return getStringParameter(name, null);
69: }
70:
71: public void setParameter(String name, String value) {
72: session.setAttribute(name, value);
73: }
74:
75: public void setParameter(String name, long value) {
76: setParameter(name, Long.toString(value));
77: }
78:
79: public void setParameter(String name, Date value) {
80: session.setAttribute(name, value);
81: }
82:
83: public void setParameter(String name, Object value) {
84: session.setAttribute(name, value);
85: }
86:
87: public Iterator getParameterNames() {
88: return session.getAttributeNames();
89: }
90:
91: }
|