01: /*
02: * SurveysPortlet.java
03: *
04: * Created on December 15, 2005, 10:40 AM
05: *
06: * To change this template, choose Tools | Options and locate the template under
07: * the Source Creation and Management node. Right-click the template and choose
08: * Open. You can then make changes to the template in the Source Editor.
09: */
10:
11: package com.sun.portal.app.collab.survey.faces;
12:
13: import com.sun.faces.portlet.FacesPortlet;
14:
15: import com.sun.portal.portlet.impl.PortletRequestConstants;
16: import javax.servlet.http.HttpServletRequest;
17: import javax.portlet.*;
18: import java.io.*;
19: import java.net.URL;
20:
21: /**
22: *
23: * @author ac120954
24: */
25: public class SurveysFacesPortlet implements Portlet {
26: private Portlet _facesPortlet;
27: public static final String searchRequestID = "SearchResultSurveyID";
28: public static final String redirectUrl = "RedirectUrl";
29:
30: /** Creates a new instance of SurveysPortlet */
31: public SurveysFacesPortlet() {
32: _facesPortlet = new FacesPortlet();
33: }
34:
35: /**
36: * Initializes the survey portlet by reading any init parameters.
37: * @param portletConfig the portlet configuration
38: */
39: public void init(PortletConfig portletConfig)
40: throws PortletException {
41: _facesPortlet.init(portletConfig);
42: }
43:
44: public void processAction(ActionRequest req, ActionResponse res)
45: throws PortletException, IOException {
46: String id = req.getParameter(searchRequestID);
47: String redirectURL = req.getParameter(redirectUrl);
48: HttpServletRequest httpReq = (HttpServletRequest) req
49: .getAttribute(PortletRequestConstants.HTTP_SERVLET_REQUEST);
50:
51: if (id != null) {
52: req.getPortletSession().setAttribute(searchRequestID, id);
53: if (redirectURL != null) {
54: try {
55: URL url = new URL(redirectURL);
56: String visibleurl = req.getPreferences().getValue(
57: "ps.visibleurl", null);
58: if (visibleurl != null
59: && visibleurl.startsWith("?")) {
60: res.sendRedirect(redirectURL + "&"
61: + visibleurl.substring(1));
62: } else {
63: res.sendRedirect(redirectURL);
64: }
65: } catch (Exception e) {
66: res.sendRedirect(httpReq.getRequestURI()
67: + redirectURL);
68: }
69: } else {
70: redirectURL = req.getPreferences().getValue(
71: "ps.visibleurl", null);
72: if (redirectURL != null
73: && !redirectURL.equalsIgnoreCase("DUMMY")) {
74: res.sendRedirect(httpReq.getRequestURI()
75: + redirectURL);
76: } else {
77:
78: //res.sendRedirect(httpReq.getRequestURI());
79: }
80: }
81: return;
82: }
83: _facesPortlet.processAction(req, res);
84: }
85:
86: public void render(RenderRequest renderRequest,
87: RenderResponse renderResponse) throws PortletException,
88: IOException {
89: _facesPortlet.render(renderRequest, renderResponse);
90: }
91:
92: public void destroy() {
93: _facesPortlet = null;
94: }
95:
96: }
|