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:
027: import com.nabhinc.portal.core.PortalConstants;
028: import com.nabhinc.portal.core.SessionCache;
029: import com.nabhinc.portal.model.NavigationalLayout;
030: import com.nabhinc.portal.model.PortalApplicationView;
031: import com.nabhinc.portal.model.PortalPageState;
032: import com.nabhinc.portal.model.Renderable;
033: import com.nabhinc.util.StringUtil;
034:
035: /**
036: *
037: *
038: * @author Padmanabh Dabke
039: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
040: */
041: public class SelectProcessor extends BasePortalActionProcessor {
042: public void process(HttpServletRequest request,
043: HttpServletResponse response, SessionCache sCache,
044: PortalApplicationView portalAppView,
045: PortalPageState pageState, int startIndex,
046: String[] portalParams, String displayMode,
047: String targetWindowId, boolean isAJAXRequest)
048: throws ServletException, IOException {
049:
050: String renderableId = null;
051: String rowIndex = null;
052:
053: if (portalParams.length > startIndex) {
054: renderableId = portalParams[startIndex];
055: startIndex++;
056: if (portalParams.length > startIndex) {
057: rowIndex = portalParams[startIndex];
058: }
059: }
060:
061: if (renderableId == null || rowIndex == null) {
062: throw new ServletException("Malformed select URL.");
063: }
064: NavigationalLayout nav = (NavigationalLayout) pageState.portalPage
065: .getRenderable(renderableId);
066: if (nav == null) {
067: // response.setStatus(HttpServletResponse.SC_NOT_FOUND);
068: response.sendError(HttpServletResponse.SC_NOT_FOUND);
069: return;
070: }
071: // nav.setRowIndex(Integer.parseInt(rowIndex));
072: request.setAttribute(
073: PortalConstants.NAV_LAYOUT_SELECTION_ATTRIB
074: + nav.getNumericId(), rowIndex);
075: String oldNavState = pageState.getNavigationState();
076: if (oldNavState.equals(PortalConstants.NAV_SELECTION_TOKEN)) {
077: pageState.setNavigationState(oldNavState + "_"
078: + renderableId + "_" + rowIndex, request
079: .getSession());
080: } else {
081: StringBuffer sb = new StringBuffer(oldNavState.length() + 6);
082: String[] navArray = StringUtil.split(oldNavState, "_");
083: boolean newSelectAdded = false;
084: sb.append(PortalConstants.NAV_SELECTION_TOKEN);
085: for (int i = 1; i < navArray.length; i += 2) {
086: sb.append("_");
087: sb.append(navArray[i]);
088: sb.append("_");
089: if (navArray[i].equals(renderableId)) {
090: sb.append(rowIndex);
091: newSelectAdded = true;
092: } else {
093: sb.append(navArray[i + 1]);
094: }
095: }
096: if (!newSelectAdded) {
097: sb.append("_");
098: sb.append(renderableId);
099: sb.append("_");
100: sb.append(rowIndex);
101: }
102: pageState.setNavigationState(sb.toString(), request
103: .getSession());
104:
105: }
106: sCache.renderResponse.setBaseURL(pageState.getPageURL());
107: if (isAJAXRequest) {
108: Renderable r = nav.getCurrentRenderable(request);
109: if (r == null) {
110: response.getWriter().write("No Content");
111: } else {
112: r.render(request, response);
113: }
114: } else {
115: ViewProcessor.getInstance().process(request, response,
116: sCache, portalAppView, pageState, startIndex,
117: portalParams, displayMode, targetWindowId,
118: isAJAXRequest);
119: }
120:
121: }
122:
123: }
|