01: /*
02: * (C) Copyright 2006 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package com.nabhinc.portlet.mvcportlet.beanutil;
22:
23: import java.lang.reflect.Method;
24:
25: import javax.portlet.ActionRequest;
26: import javax.portlet.ActionResponse;
27: import javax.portlet.PortletException;
28: import javax.portlet.PortletRequest;
29:
30: import com.nabhinc.condition.AllowUsers;
31: import com.nabhinc.condition.ConditionConstants;
32: import com.nabhinc.condition.LoginRequired;
33: import com.nabhinc.condition.MembersOnly;
34: import com.nabhinc.util.StringUtil;
35:
36: /**
37: *
38: *
39: * @author Padmanabh Dabke
40: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
41: * @since 1.1
42: */
43: public class ConditionParameterSetter extends BaseParameterSetter {
44: private String selectedUsersParam = null;
45:
46: /**
47: * @param getMethod
48: */
49: public ConditionParameterSetter(Method getMethod,
50: String selUsersParam) {
51: super (getMethod);
52: this .selectedUsersParam = selUsersParam;
53: }
54:
55: public void setParameters(ActionRequest request,
56: ActionResponse response, String paramName, Object target,
57: String propertyName) throws PortletException {
58: try {
59: Object propValue = bpsGetMethod.invoke(target, bpsArgs);
60: //if (propValue != null) {
61: String paramValue = formatParameterValue(request, propValue);
62: response.setRenderParameter(paramName, paramValue);
63: if (ConditionConstants.COND_TYPE_SELECTED_USERS
64: .equals(paramValue)) {
65: AllowUsers cond = (AllowUsers) propValue;
66: if (cond.getUsers() != null)
67: response.setRenderParameter(
68: this .selectedUsersParam, StringUtil.join(
69: cond.getUsers(), "\n"));
70: }
71: //}
72: } catch (Exception e) {
73: throw new PortletException(
74: "Failed to retrieve object property "
75: + propertyName, e);
76: }
77:
78: }
79:
80: public String formatParameterValue(PortletRequest request,
81: Object value) {
82: if (value == null)
83: return ConditionConstants.COND_TYPE_ANYONE;
84: else if (value instanceof LoginRequired)
85: return ConditionConstants.COND_TYPE_LOGGED_IN_USERS;
86: else if (value instanceof MembersOnly)
87: return ConditionConstants.COND_TYPE_MEMBERS_ONLY;
88: else if (value instanceof AllowUsers)
89: return ConditionConstants.COND_TYPE_SELECTED_USERS;
90: throw new IllegalArgumentException(
91: "Unrecognized condition type: "
92: + value.getClass().getName());
93: }
94:
95: }
|