ReorderContentProcessor.java :  » Portal » stringbeans-3.5 » com » nabhinc » portal » processor » Java Open Source

Java Open Source » Portal » stringbeans 3.5 
stringbeans 3.5 » com » nabhinc » portal » processor » ReorderContentProcessor.java
/* 
 * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc. 
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 */
package com.nabhinc.portal.processor;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nabhinc.portal.core.PortalConstants;
import com.nabhinc.portal.core.PortalUtil;
import com.nabhinc.portal.core.SessionCache;
import com.nabhinc.portal.model.NavigationalLayout;
import com.nabhinc.portal.model.PortalApplication;
import com.nabhinc.portal.model.PortalApplicationView;
import com.nabhinc.portal.model.PortalPageState;
import com.nabhinc.portal.model.PortletWindow;
import com.nabhinc.portal.model.RenderableList;
import com.nabhinc.util.StringUtil;

/**
 * 
 *
 * @author Padmanabh Dabke
 * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
 */
public class ReorderContentProcessor extends EditPagePortalActionProcessor{
  public void process(HttpServletRequest request,
      HttpServletResponse response, SessionCache sCache,
      PortalApplicationView portalAppView, PortalPageState pageState,
      int startIndex, String[] portalParams, String displayMode,
      String targetWindowId, boolean isAJAXRequest)
      throws ServletException, IOException {
    int oldRowIndex = Integer.parseInt(request.getParameter("old_index"));
    int newRowIndex = Integer.parseInt(request.getParameter("new_index"));
    String oldNodeId = request.getParameter("old_id");
    
    if (oldNodeId.startsWith(PortalConstants.MENU_NODE_ID_PREFIX)) {
      String parentIndexStr = request.getParameter("parent_index");
      int parentIndex = StringUtil.isNullOrEmpty(parentIndexStr) ? -1 : Integer.parseInt(parentIndexStr);
      String rId = PortalUtil.getRenderableId(oldNodeId);
      NavigationalLayout nl = (NavigationalLayout) pageState.portalPage.getRenderable(rId);
      nl.reorderRows(oldRowIndex, newRowIndex, parentIndex);
    } else if (oldNodeId.startsWith(PortalConstants.PORTLET_LIST_NODE_ID_PREFIX)) {
      String newNodeId = request.getParameter("new_id");
      if (oldNodeId.equals(newNodeId)) {
        // Portlet has been moved within current column
        String rId = PortalUtil.getRenderableId(oldNodeId);
        RenderableList rl = (RenderableList) pageState.portalPage.getRenderable(rId);
        rl.reorderPortletWindows(oldRowIndex, newRowIndex);
      } else {
        String oldRenderableId = PortalUtil.getRenderableId(oldNodeId);
        RenderableList oldList = (RenderableList) pageState.portalPage.getRenderable(oldRenderableId);
        
        String newRenderableId = PortalUtil.getRenderableId(newNodeId);
        RenderableList newList = (RenderableList) pageState.portalPage.getRenderable(newRenderableId);

        PortletWindow pWindow = oldList.removePortletWindowAt(oldRowIndex);
        newList.addPortletWindow(newRowIndex, pWindow);
        PortalApplication portalApp = portalAppView.getPortalApplication();
        pWindow.computeTemplatePath(request.getSession().getServletContext(), portalApp.getPath(), portalApp.getTheme(),
            newList.getComponentTemplate());
        request.setAttribute(PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE, pWindow);
          request.getRequestDispatcher(pWindow.getTemplatePath()).include(request, response);
          return;
      }
    }
    response.getWriter().write("ok");
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.