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.servlet.ServletException;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026: import javax.servlet.http.HttpSession;
027:
028: import com.nabhinc.portal.core.NavigationState;
029: import com.nabhinc.portal.core.PortalConstants;
030: import com.nabhinc.portal.core.PortalUtil;
031: import com.nabhinc.portal.core.SessionCache;
032: import com.nabhinc.portal.model.PortalApplicationView;
033: import com.nabhinc.portal.model.PortalPageState;
034: import com.nabhinc.portal.model.PortletWindow;
035:
036: /**
037: *
038: *
039: * @author Padmanabh Dabke
040: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
041: */
042: public class ChangePortletModeProcessor extends
043: BasePortalActionProcessor {
044: public void process(HttpServletRequest request,
045: HttpServletResponse response, SessionCache sCache,
046: PortalApplicationView portalAppView,
047: PortalPageState pageState, int startIndex,
048: String[] portalParams, String displayMode,
049: String targetWindowId, boolean isAJAXRequest)
050: throws ServletException, IOException {
051:
052: String newPortletMode = null;
053:
054: if (portalParams.length > startIndex) {
055: targetWindowId = portalParams[startIndex];
056: startIndex++;
057: if (portalParams.length > startIndex) {
058: newPortletMode = portalParams[startIndex];
059: startIndex++;
060: }
061: }
062:
063: if (targetWindowId == null || newPortletMode == null) {
064: throw new ServletException("Malformed mode change URL.");
065: }
066: PortletWindow pWindow = pageState.portalPage
067: .getPortletWindow(targetWindowId);
068: if (pWindow == null) {
069: // response.setStatus(HttpServletResponse.SC_NOT_FOUND);
070: response.sendError(HttpServletResponse.SC_NOT_FOUND);
071: return;
072: }
073: String globalWindowId = pWindow.getId();
074:
075: HttpSession session = request.getSession();
076: boolean isDetached = displayMode
077: .equals(PortalConstants.DISPLAY_MODE_DETACHED);
078: NavigationState ns = NavigationState.getNavigationState(
079: session, globalWindowId, isDetached);
080: if (ns == null)
081: ns = new NavigationState();
082: ns.setPortletMode(newPortletMode);
083: PortalUtil.uncacheContent(session, globalWindowId);
084: if (ns.paramMap.size() == 0 && ns.portletModeStr.equals("view")) {
085: NavigationState.removeNavigationState(session,
086: globalWindowId, isDetached);
087: } else {
088: NavigationState.setNavigationState(session, globalWindowId,
089: isDetached, ns);
090: }
091:
092: if (isAJAXRequest) {
093: PortalUtil.renderPortletWindow(request, response, pWindow,
094: portalAppView.getPortalApplication(), displayMode,
095: true);
096: } else {
097: ViewProcessor.getInstance().process(request, response,
098: sCache, portalAppView, pageState, startIndex,
099: portalParams, displayMode, targetWindowId,
100: isAJAXRequest);
101:
102: }
103:
104: }
105:
106: }
|