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.WindowState;
024: import javax.portlet.WindowStateException;
025: import javax.servlet.ServletException;
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import com.nabhinc.core.MimeTypes;
030: import com.nabhinc.portal.core.ClientInfo;
031: import com.nabhinc.portal.core.PortalConstants;
032: import com.nabhinc.portal.core.PortalUtil;
033: import com.nabhinc.portal.core.SessionCache;
034: import com.nabhinc.portal.model.CompositeRenderable;
035: import com.nabhinc.portal.model.PortalApplication;
036: import com.nabhinc.portal.model.PortalApplicationView;
037: import com.nabhinc.portal.model.PortalPage;
038: import com.nabhinc.portal.model.PortalPageState;
039: import com.nabhinc.portal.model.PortletWindow;
040:
041: /**
042: *
043: *
044: * @author Padmanabh Dabke
045: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
046: */
047: public class ViewProcessor extends BasePortalActionProcessor {
048:
049: private static ViewProcessor SELF = null;
050:
051: public static ViewProcessor getInstance() {
052: return SELF;
053: }
054:
055: public ViewProcessor() {
056: ViewProcessor.SELF = this ;
057: }
058:
059: public void process(HttpServletRequest request,
060: HttpServletResponse response, SessionCache sCache,
061: PortalApplicationView portalAppView,
062: PortalPageState pageState, int startIndex,
063: String[] portalParams, String displayMode,
064: String targetWindowId, boolean isAJAXRequest)
065: throws ServletException, IOException {
066:
067: PortalPage targetPage = pageState.portalPage;
068: PortalApplication portalApp = portalAppView
069: .getPortalApplication();
070: // sCache.renderResponse.setBaseURL(PortalUtil.computeBaseURL(request,
071: // targetPage, displayMode, targetWindowId));
072: // sCache.renderResponse.setDetached(false);
073: if (displayMode.equals(PortalConstants.DISPLAY_MODE_DESKTOP)) {
074: try {
075: sCache.renderRequest
076: .setWindowState(WindowState.MAXIMIZED);
077: } catch (WindowStateException e) {
078: this .LOGGER
079: .warn(
080: "Failed to maximize portlet window in the desktop mode.",
081: e);
082: }
083: request.getRequestDispatcher(
084: portalApp.getDisplayInfo().desktopTemplate)
085: .include(request, response);
086: return;
087: }
088:
089: if (displayMode.equals(PortalConstants.DISPLAY_MODE_NORMAL)) {
090: CompositeRenderable currentRenderable = targetPage
091: .getRenderable();
092: if (currentRenderable != null) {
093: currentRenderable.setRenderAttributes(request, sCache);
094: try {
095: sCache.renderRequest
096: .setWindowState(WindowState.NORMAL);
097: } catch (WindowStateException e) {
098: LOGGER.error(
099: "Failed to change window state to normal.",
100: e);
101: }
102: }
103: pageState.setNormalPageMode(request.getSession());
104: PortletWindow targetWindow = targetWindowId == null ? null
105: : targetPage.getPortletWindow(targetWindowId);
106: dispatchRequest(request, response, portalApp
107: .getDisplayInfo().normalTemplate,
108: sCache.clientInfo, targetWindow);
109:
110: } else {
111: PortletWindow targetWindow = targetPage
112: .getPortletWindow(targetWindowId);
113: if (targetWindow == null) {
114: // response.setStatus(HttpServletResponse.SC_NOT_FOUND);
115: response.sendError(HttpServletResponse.SC_NOT_FOUND);
116: return;
117: }
118:
119: if (displayMode
120: .equals(PortalConstants.DISPLAY_MODE_MAXIMIZED)) {
121: try {
122: sCache.renderRequest
123: .setWindowState(WindowState.MAXIMIZED);
124: } catch (WindowStateException e) {
125: LOGGER
126: .warn(
127: "Failed to change window state to maximized.",
128: e);
129:
130: }
131: request.setAttribute(
132: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
133: targetWindow);
134: pageState.setMaximizedPageMode(targetWindow, request
135: .getSession());
136: dispatchRequest(request, response, portalApp
137: .getDisplayInfo().maximizedTemplate,
138: sCache.clientInfo, targetWindow);
139: } else if (displayMode
140: .startsWith(PortalConstants.DISPLAY_MODE_DETACHED)) {
141: //sCache.renderResponse.setDetached(true);
142: try {
143: if (request
144: .getSession()
145: .getAttribute(
146: PortalConstants.DETACHED_WINDOW_STATE_ATTRIBUTE
147: + targetWindow.getId()) == null)
148: sCache.renderRequest
149: .setWindowState(WindowState.NORMAL);
150: else
151: sCache.renderRequest
152: .setWindowState(WindowState.MAXIMIZED);
153: } catch (WindowStateException e) {
154: LOGGER
155: .warn(
156: "Failed to change window state to maximized.",
157: e);
158:
159: }
160: request.setAttribute(
161: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
162: targetWindow);
163: PortalUtil.setNoCacheHeaders(request, response);
164: request.getRequestDispatcher(
165: portalApp.getDisplayInfo().detachedTemplate)
166: .include(request, response);
167: } else {
168: // response.setStatus(HttpServletResponse.SC_NOT_FOUND);
169: response.sendError(HttpServletResponse.SC_NOT_FOUND);
170: }
171: }
172:
173: }
174:
175: protected static void dispatchRequest(HttpServletRequest request,
176: HttpServletResponse response, String htmlTemplate,
177: ClientInfo clInfo, PortletWindow targetWindow)
178: throws ServletException, IOException {
179: PortalUtil.setNoCacheHeaders(request, response);
180: if (clInfo.isMobileClient) {
181: String template = null;
182: if (clInfo.mimeType.equals(MimeTypes.WML)) {
183: if (targetWindow == null) {
184: template = "/templates/mobile/portal_page_wml.jsp";
185: } else {
186: template = "/templates/mobile/portlet_window_wml.jsp";
187: request
188: .setAttribute(
189: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
190: targetWindow);
191: }
192: } else {
193: if (targetWindow == null) {
194: template = "/templates/mobile/portal_page_xhtmlmp.jsp";
195: } else {
196: template = "/templates/mobile/portlet_window_xhtmlmp.jsp";
197: request
198: .setAttribute(
199: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
200: targetWindow);
201: }
202:
203: }
204: request.getRequestDispatcher(template).include(request,
205: response);
206: } else {
207: request.getRequestDispatcher(htmlTemplate).include(request,
208: response);
209: }
210: }
211:
212: }
|