001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portal.processor;
020:
021: import java.io.IOException;
022:
023: import javax.portlet.PortletException;
024: import javax.portlet.PortletMode;
025: import javax.portlet.PortletModeException;
026: import javax.portlet.PortletSecurityException;
027: import javax.servlet.ServletException;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import javax.servlet.http.HttpSession;
031:
032: import com.nabhinc.portal.core.NavigationState;
033: import com.nabhinc.portal.core.PortalConstants;
034: import com.nabhinc.portal.core.PortalUtil;
035: import com.nabhinc.portal.core.SessionCache;
036: import com.nabhinc.portal.model.PortalApplicationView;
037: import com.nabhinc.portal.model.PortalPageState;
038: import com.nabhinc.portal.model.PortletWindow;
039:
040: /**
041: *
042: *
043: * @author Padmanabh Dabke
044: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
045: */
046: public class RenderProcessor extends BasePortalActionProcessor {
047: public void process(HttpServletRequest request,
048: HttpServletResponse response, SessionCache sCache,
049: PortalApplicationView portalAppView,
050: PortalPageState pageState, int startIndex,
051: String[] portalParams, String displayMode,
052: String targetWindowId, boolean isAJAXRequest)
053: throws ServletException, IOException {
054:
055: if (portalParams.length > startIndex) {
056: targetWindowId = portalParams[startIndex];
057: startIndex++;
058: }
059:
060: PortletWindow pWindow = getPortletWindow(targetWindowId,
061: pageState);
062: if (pWindow == null) {
063: // response.setStatus(HttpServletResponse.SC_NOT_FOUND);
064: response.sendError(HttpServletResponse.SC_NOT_FOUND);
065: return;
066: }
067:
068: if (PortalUtil.redirectProtectedActions(request, response,
069: pWindow.getName(), isAJAXRequest))
070: return;
071: String globalWindowId = pWindow.getId();
072:
073: // Check if the render URL is changing portlet mode or window state
074: String newPortletMode = null;
075: String newWindowState = null;
076: boolean isDetached = displayMode
077: .equals(PortalConstants.DISPLAY_MODE_DETACHED);
078: HttpSession session = request.getSession();
079:
080: if (portalParams.length > startIndex) {
081: String cmd = portalParams[startIndex];
082: startIndex++;
083: if (cmd.equals(PortalConstants.PORTLET_MODE_TOKEN)) {
084: newPortletMode = portalParams[startIndex];
085: } else if (cmd.equals(PortalConstants.WINDOW_STATE_TOKEN)) {
086: newWindowState = portalParams[startIndex];
087: }
088: startIndex++;
089: }
090: if (portalParams.length > startIndex) {
091: String cmd = portalParams[startIndex];
092: startIndex++;
093: if (cmd.equals(PortalConstants.PORTLET_MODE_TOKEN)) {
094: newPortletMode = portalParams[startIndex];
095: } else if (cmd.equals(PortalConstants.WINDOW_STATE_TOKEN)) {
096: newWindowState = portalParams[startIndex];
097: }
098: startIndex++;
099: }
100: String oldDisplayMode = displayMode;
101: NavigationState ns = createNewNavState(session, globalWindowId,
102: isDetached, newPortletMode, pWindow, request, sCache);
103: if (ns != null) {
104: if (ns.paramMap.size() == 0
105: && ns.portletModeStr.equals("view")) {
106: NavigationState.removeNavigationState(session,
107: globalWindowId, isDetached);
108: } else {
109: NavigationState.setNavigationState(session,
110: globalWindowId, isDetached, ns);
111: }
112: if (newWindowState != null) {
113: displayMode = PortalUtil.setupWindowState(isDetached,
114: newWindowState, session, globalWindowId,
115: displayMode);
116: }
117: }
118:
119: if (!oldDisplayMode.equals(displayMode)) {
120: request.setAttribute(PortalConstants.CURRENT_DISPLAY_MODE,
121: displayMode);
122: if (displayMode.equals(PortalConstants.DISPLAY_MODE_NORMAL)) {
123: pageState.setNormalPageMode(session);
124: } else if (displayMode
125: .equals(PortalConstants.DISPLAY_MODE_MAXIMIZED)) {
126: pageState.setMaximizedPageMode(pWindow, session);
127: }
128: if (!displayMode
129: .equals(PortalConstants.DISPLAY_MODE_DETACHED)) {
130: sCache.renderResponse
131: .setBaseURL(pageState.getPageURL());
132: }
133: }
134: PortalUtil.uncacheContent(session, globalWindowId);
135:
136: if (isAJAXRequest) {
137: if (oldDisplayMode.equals(displayMode)) {
138: PortalUtil.renderPortletWindow(request, response,
139: pWindow, portalAppView.getPortalApplication(),
140: displayMode, true);
141: } else {
142: PortalUtil.directToURL(request, response, pageState
143: .getPageURL());
144: }
145:
146: } else {
147: ViewProcessor.getInstance().process(request, response,
148: sCache, portalAppView, pageState, startIndex,
149: portalParams, displayMode, targetWindowId,
150: isAJAXRequest);
151: }
152:
153: }
154:
155: private NavigationState createNewNavState(HttpSession session,
156: String globalWindowId, boolean isDetached,
157: String newPortletMode, PortletWindow pWindow,
158: HttpServletRequest request, SessionCache sCache) {
159: NavigationState ns = NavigationState.getNavigationState(
160: session, globalWindowId, isDetached);
161: if (ns == null)
162: ns = new NavigationState();
163: try {
164: if (newPortletMode != null) {
165: pWindow.checkPortletMode(
166: new PortletMode(newPortletMode),
167: sCache.clientInfo.mimeType, request);
168: ns.setPortletMode(newPortletMode);
169: }
170:
171: ns.setParams(request);
172: return ns;
173: } catch (PortletSecurityException e) {
174: LOGGER.info(
175: "Access denied to new portlet mode/window state on "
176: + "/" + pWindow.getName(), e);
177: session.setAttribute(
178: PortalConstants.PORTAL_ERROR_MESSAGE_ATTRIB,
179: "Access denied.");
180: } catch (PortletModeException e) {
181: session.setAttribute(
182: PortalConstants.PORTAL_ERROR_MESSAGE_ATTRIB,
183: "Invalid portlet mode.");
184: } catch (PortletException e) {
185: session.setAttribute(
186: PortalConstants.PORTAL_ERROR_MESSAGE_ATTRIB, e
187: .getMessage());
188: }
189: return null;
190: }
191:
192: protected PortletWindow getPortletWindow(String targetWindowId,
193: PortalPageState pageState) {
194: if (targetWindowId == null)
195: return null;
196: return pageState.portalPage.getPortletWindow(targetWindowId);
197:
198: }
199:
200: }
|