001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Aug 2, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.ui.portlet;
018:
019: import java.io.IOException;
020: import java.io.PrintWriter;
021: import javax.portlet.ActionRequest;
022: import javax.portlet.PortletException;
023: import javax.portlet.PortletPreferences;
024: import javax.portlet.RenderRequest;
025: import javax.portlet.RenderResponse;
026:
027: import org.pentaho.messages.Messages;
028:
029: public abstract class ViewPortlet extends BasePortlet {
030:
031: public void doPortletHelp(RenderRequest request,
032: RenderResponse response, PentahoPortletSession userSession)
033: throws PortletException, IOException {
034: response.setContentType("text/html"); //$NON-NLS-1$
035: PrintWriter out = response.getWriter();
036: out
037: .println(Messages
038: .getString(
039: "ViewPortlet.CODE_MESSAGE_TEMPLATE", Messages.getString("ViewPortlet.USER_HELP_NOT_AVAILABLE"))); //$NON-NLS-1$ //$NON-NLS-2$
040: }
041:
042: public void doPortletEdit(RenderRequest request,
043: RenderResponse response, PentahoPortletSession userSession)
044: throws PortletException, IOException {
045: response.setContentType("text/html"); //$NON-NLS-1$
046: PrintWriter out = response.getWriter();
047: // TODO sbarkdull, ViewPortlet.CODE_MESSAGE_TEMPLATE probably shouldnt be in resource file
048: out
049: .println(Messages
050: .getString(
051: "ViewPortlet.CODE_MESSAGE_TEMPLATE", Messages.getString("ViewPortlet.USER_OPTIONS_NOT_AVAILABLE"))); //$NON-NLS-1$ //$NON-NLS-2$
052: }
053:
054: protected String getSetting(String name, String defaultValue,
055: ActionRequest request,
056: PortletRequestParameterProvider requestParameters) {
057:
058: PortletPreferences prefs = request.getPreferences();
059: String value = request.getParameter(name);
060: if (value == null) {
061: // get the default value from the preferences
062: value = prefs.getValue(name, null);
063: if (value != null && requestParameters != null) {
064: requestParameters.setParameter(name, value);
065: } else {
066: value = defaultValue;
067: }
068: }
069: return value;
070: }
071:
072: /**
073: * Using <code>name</code> as a key, look for the key first in the portal's RenderRequest,
074: * if it is found, return its value.
075: * If it is not found in the RenderRequest, look in the PortletPreferences. If it is
076: * found, and the PortletRequestParameterProvider is not null, add the key/value
077: * pair to the PortletRequestParameterProvider, and return the value.
078: * If it is not found in either the RenderRequest or the PortletPreferences,
079: * return the <code>defaultValue</code> parameter.
080: *
081: * @param name
082: * @param defaultValue String returned if name cannot be found in the RenderRequest or the PortletPreferences.
083: * @param request RendRequest active during this request cycle.
084: * @param requestParameters PortletRequestParameterProvider active during this request cycle
085: * @return the value associated with the key specified by the <code>name</code> parameter.
086: */
087: protected String getSetting(String name, String defaultValue,
088: RenderRequest request,
089: PortletRequestParameterProvider requestParameters) {
090:
091: PortletPreferences prefs = request.getPreferences();
092: String value = request.getParameter(name);
093: if (value == null) {
094: // get the default value from the preferences
095: value = prefs.getValue(name, null);
096: if (value != null) {
097: if (requestParameters != null) {
098: requestParameters.setParameter(name, value);
099: }
100: } else {
101: value = defaultValue;
102: }
103: }
104: return value;
105: }
106:
107: protected long getSetting(String name, long defaultValue,
108: RenderRequest request,
109: PortletRequestParameterProvider requestParameters) {
110:
111: String valueStr = getSetting(name, Long.toString(defaultValue),
112: request, requestParameters);
113:
114: try {
115: return Long.parseLong(valueStr);
116: } catch (Exception e) {
117: return defaultValue;
118: }
119: }
120: }
|