01: /*
02: * (C) Copyright 2004 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.actionprocessor;
22:
23: import java.io.IOException;
24:
25: import javax.portlet.ActionRequest;
26: import javax.portlet.ActionResponse;
27: import javax.portlet.PortletException;
28:
29: import org.w3c.dom.Element;
30:
31: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
32: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
33: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
34: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
35: import com.nabhinc.util.XMLUtil;
36:
37: /**
38: * Verify if required "param" parameter is specified.
39: *
40: * @author Padmanabh Dabke
41: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
42: */
43: public class CheckParameter extends BaseRequestProcessor implements
44: ActionProcessor {
45:
46: private String cpParamName = null;
47:
48: public void init(Element config,
49: ControllerPortletConfig controllerConfig)
50: throws PortletException {
51: super .init(config, controllerConfig);
52: cpParamName = XMLUtil.getSubElementText(config, "param");
53: if (cpParamName == null) {
54: throw new PortletException(
55: "Missing required config element: param");
56: }
57: }
58:
59: /**
60: * @param request
61: * @param response
62: * @param actionConfig
63: * @return <code>failure</code> if the param's value is null or empty String.
64: * Otherwise, return <code>success</code>.
65: * @throws PortletException
66: * @throws IOException
67: */
68: public String process(ActionRequest request,
69: ActionResponse response, ActionConfig actionConfig)
70: throws PortletException, IOException {
71: String paramValue = request.getParameter(cpParamName);
72: if (paramValue == null || paramValue.equals(""))
73: return "failure";
74: return "success";
75: }
76:
77: }
|