EditPortalAppProcessor.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 » EditPortalAppProcessor.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.condition.AlwaysTrue;
import com.nabhinc.condition.Condition;
import com.nabhinc.portal.api.EntityLockedException;
import com.nabhinc.portal.api.PortalInformationStore;
import com.nabhinc.portal.api.PortalInformationStoreLocator;
import com.nabhinc.portal.core.PortalEventMonitor;
import com.nabhinc.portal.core.PortalConstants;
import com.nabhinc.portal.core.PortalUtil;
import com.nabhinc.portal.core.SessionCache;
import com.nabhinc.portal.model.PortalApplication;
import com.nabhinc.portal.model.PortalApplicationView;
import com.nabhinc.portal.model.PortalConfiguration;
import com.nabhinc.portal.model.PortalPageState;
import com.nabhinc.util.StringUtil;
import com.nabhinc.ws.core.WebServiceSecurityException;

/**
 * 
 *
 * @author Padmanabh Dabke
 * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
 */
public class EditPortalAppProcessor extends AdminAppPortalActionProcessor {
  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 {
    
    String errorMessage = "";
    if (!isAJAXRequest) {
      response.sendRedirect(pageState.getPageURL());
      return;
    } else if (request.getParameter("is_submit") == null) {
      request.getRequestDispatcher("/admin/edit_portal_app.jsp").forward(request, response);
      return;
    }// else {
      PortalApplication portalApp = portalAppView.getPortalApplication();
      String appTitle = request.getParameter(PortalConstants.TITLE_PARAM);
      if (StringUtil.isNotNullOrEmpty(appTitle)) portalApp.setTitle(appTitle);
      
      String appTagline = request.getParameter(PortalConstants.TAGLINE_PARAM);
      if (StringUtil.isNotNullOrEmpty(appTagline)) portalApp.setTagline(appTagline);
      
      String appTheme = request.getParameter(PortalConstants.THEME_PARAM);
      if (StringUtil.isNotNullOrEmpty(appTheme)) {
        portalApp.setTheme(appTheme);
        PortalUtil.setTemplatePaths(portalApp, request);
      }
      
      if (request.getParameter(PortalConstants.REMOVE_PASSWORD_PARAM) != null) {
        portalApp.setPassword(null);
      }
      String password = request.getParameter(PortalConstants.PASSWORD_PARAM);
      if (StringUtil.isNotNullOrEmpty(password)) {
        portalApp.setPassword(password);
      }
      
      String editPerm = request.getParameter(PortalConstants.EDIT_PERM_TYPE_PARAM);
      if (StringUtil.isNotNullOrEmpty(editPerm)) {
        try {
          portalApp.setEditPermission(PortalUtil.createCondition(request, editPerm, PortalConstants.EDIT_ROLES_PARAM, PortalConstants.EDIT_USERS_PARAM));
        } catch (IllegalArgumentException ex) {
          errorMessage += "- Edit Permission: " + ex.getMessage() + "\n";
        }        
      }
      String viewPerm = request.getParameter(PortalConstants.VIEW_PERM_TYPE_PARAM);
      if (StringUtil.isNotNullOrEmpty(viewPerm)) {
        Condition oldCondition = portalApp.getViewPermission();
        try {
          portalApp.setViewPermission(PortalUtil.createCondition(request, viewPerm, PortalConstants.VIEW_ROLES_PARAM,
            PortalConstants.VIEW_USERS_PARAM));
          Condition newCondition = portalApp.getViewPermission();
          boolean oldFlag = oldCondition != null && (! (oldCondition instanceof AlwaysTrue));
          boolean newFlag = newCondition != null && (! (newCondition instanceof AlwaysTrue));
          if (oldFlag != newFlag) {
            PortalEventMonitor monitor = PortalConfiguration.getInstance().getEventMonitor();
            if (monitor != null) monitor.viewPermissionChanged(portalApp.getPath());
          }
        } catch (IllegalArgumentException ex) {
          errorMessage += "- View Permission: " + ex.getMessage() + "\n";
        }
      }
      String dPerm = request.getParameter(PortalConstants.DELETE_PERM_TYPE_PARAM);
      if (StringUtil.isNotNullOrEmpty(dPerm)) {
        try {
          portalApp.setDeletePermission(PortalUtil.createCondition(request, dPerm, PortalConstants.DELETE_ROLES_PARAM,
            PortalConstants.DELETE_USERS_PARAM));
        } catch (IllegalArgumentException ex) {
          errorMessage += "- Delete Permission: " + ex.getMessage() + "\n";
        }
      }
      String cPerm = request.getParameter(PortalConstants.CREATE_PSITE_PERM_TYPE_PARAM);
      if (StringUtil.isNotNullOrEmpty(cPerm)) {
        try { 
          portalApp.setCreatePsitePermission(PortalUtil.createCondition(request, cPerm, PortalConstants.CREATE_PSITE_ROLES_PARAM,
            PortalConstants.CREATE_PSITE_USERS_PARAM));
        } catch (IllegalArgumentException ex) {
          errorMessage += "- Create Permission: " + ex.getMessage() + "\n";
        }
      }
      
      String logoPath = request.getParameter(PortalConstants.LOGO_IMAGE_PARAM);
      if (StringUtil.isNotNullOrEmpty(logoPath)) {
        portalApp.setLogo(logoPath.trim());
      } else {
        portalApp.setLogo(null);
      }
      
      String headerStyle = request.getParameter(PortalConstants.HEADER_STYLE_PARAM);
      if (StringUtil.isNotNullOrEmpty(PortalConstants.HEADER_STYLE_PARAM)) {
        portalApp.setHeaderStyle(headerStyle.trim());
      } else {
        portalApp.setHeaderStyle("");
      }
      
      if (StringUtil.isNullOrEmpty(request.getParameter(PortalConstants.DISPLAY_TITLE_PARAM))) {
        portalApp.setDisplayTitle(false);
      } else {
        portalApp.setDisplayTitle(true);
      }
      
      String memberStr = request.getParameter(PortalConstants.MEMBERS_PARAM);
      String[] members = null;
      if (StringUtil.isNotNullOrEmpty(memberStr)) {
        members = StringUtil.split(memberStr, "\n \t\r");
      }
      
      if (!"".equals(errorMessage)) {
        response.getWriter().write("Errors occurred:\n" + errorMessage);
        return;
      }
      
      try {
        PortalInformationStore store = PortalInformationStoreLocator.getPortalInformationStore();
        store.setPortalApplicationMembers(portalApp.getPath(), members);
        if (request.getParameter(PortalConstants.LOCK_PSITE_PARAM) != null) {
          store.lockPortalApplication(portalApp.getPath());
        } else if (request.getParameter(PortalConstants.UNLOCK_PSITE_PARAM) != null) {
          store.unlockPortalApplication(portalApp.getPath());
        }
        
      } catch (WebServiceSecurityException e) {
      } catch (EntityLockedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      response.getWriter().write("ok");
      /*if (! oldTheme.equals(appTheme)) */
        // PortalUtil.redirectRequest(pageState.getPageURL(), response, isAJAXRequest);
    //}
  }
  
}
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.