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.PortalUtil;
029: import com.nabhinc.portal.core.SessionCache;
030: import com.nabhinc.portal.model.NavigationalLayout;
031: import com.nabhinc.portal.model.PortalApplication;
032: import com.nabhinc.portal.model.PortalApplicationView;
033: import com.nabhinc.portal.model.PortalPageState;
034: import com.nabhinc.portal.model.PortletWindow;
035: import com.nabhinc.portal.model.RenderableList;
036: import com.nabhinc.util.StringUtil;
037:
038: /**
039: *
040: *
041: * @author Padmanabh Dabke
042: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
043: */
044: public class ReorderContentProcessor extends
045: EditPagePortalActionProcessor {
046: public void process(HttpServletRequest request,
047: HttpServletResponse response, SessionCache sCache,
048: PortalApplicationView portalAppView,
049: PortalPageState pageState, int startIndex,
050: String[] portalParams, String displayMode,
051: String targetWindowId, boolean isAJAXRequest)
052: throws ServletException, IOException {
053: int oldRowIndex = Integer.parseInt(request
054: .getParameter("old_index"));
055: int newRowIndex = Integer.parseInt(request
056: .getParameter("new_index"));
057: String oldNodeId = request.getParameter("old_id");
058:
059: if (oldNodeId.startsWith(PortalConstants.MENU_NODE_ID_PREFIX)) {
060: String parentIndexStr = request
061: .getParameter("parent_index");
062: int parentIndex = StringUtil.isNullOrEmpty(parentIndexStr) ? -1
063: : Integer.parseInt(parentIndexStr);
064: String rId = PortalUtil.getRenderableId(oldNodeId);
065: NavigationalLayout nl = (NavigationalLayout) pageState.portalPage
066: .getRenderable(rId);
067: nl.reorderRows(oldRowIndex, newRowIndex, parentIndex);
068: } else if (oldNodeId
069: .startsWith(PortalConstants.PORTLET_LIST_NODE_ID_PREFIX)) {
070: String newNodeId = request.getParameter("new_id");
071: if (oldNodeId.equals(newNodeId)) {
072: // Portlet has been moved within current column
073: String rId = PortalUtil.getRenderableId(oldNodeId);
074: RenderableList rl = (RenderableList) pageState.portalPage
075: .getRenderable(rId);
076: rl.reorderPortletWindows(oldRowIndex, newRowIndex);
077: } else {
078: String oldRenderableId = PortalUtil
079: .getRenderableId(oldNodeId);
080: RenderableList oldList = (RenderableList) pageState.portalPage
081: .getRenderable(oldRenderableId);
082:
083: String newRenderableId = PortalUtil
084: .getRenderableId(newNodeId);
085: RenderableList newList = (RenderableList) pageState.portalPage
086: .getRenderable(newRenderableId);
087:
088: PortletWindow pWindow = oldList
089: .removePortletWindowAt(oldRowIndex);
090: newList.addPortletWindow(newRowIndex, pWindow);
091: PortalApplication portalApp = portalAppView
092: .getPortalApplication();
093: pWindow.computeTemplatePath(request.getSession()
094: .getServletContext(), portalApp.getPath(),
095: portalApp.getTheme(), newList
096: .getComponentTemplate());
097: request.setAttribute(
098: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
099: pWindow);
100: request.getRequestDispatcher(pWindow.getTemplatePath())
101: .include(request, response);
102: return;
103: }
104: }
105: response.getWriter().write("ok");
106: }
107:
108: }
|