/*
 * $Id: DisplayAclSummaryViewAction.java,v 1.4 2005/05/31 15:33:32 marbobo Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: DisplayAclSummaryViewAction.java,v $
 * Revision 1.4  2005/05/31 15:33:32  marbobo
 * + Anpassungen wegen Virtoweb (betrifft backAction)
 *
 * Revision 1.3  2005/05/30 16:16:10  jonyp
 * changed action to back_action according renamed back-button
 *
 * Revision 1.2  2005/05/30 16:12:50  jonyp
 * cleanup code for instant use, throw away some overhead
 *
 * Revision 1.1  2005/05/24 14:45:34  jonyp
 * first strike
 *
*/
package vkc.view.action;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import vkc.view.form.DisplayAclSummaryViewForm;


public class DisplayAclSummaryViewAction extends Action {
    //private boolean ldapEnabled = Integer.parseInt( WebShare.getSysParameterValue( "LDAP", "EnableLdapSupport", "0" ) ) != 0 ? true : false;
    private ActionForward defaultInputForward = null; 

	public ActionForward execute( ActionMapping mapping, 
	        					  ActionForm f, 
	        					  HttpServletRequest request, 
	        					  HttpServletResponse response ) 
	throws ServletException	{
		// Form holen
		DisplayAclSummaryViewForm form = (DisplayAclSummaryViewForm)f;
		
		defaultInputForward = mapping.getInputForward();	
		
		// Close Action
		if ( request.getParameter( "back_action" ) != null ) {
			request.getSession().removeAttribute( "previousAccessor" );
			request.getSession().removeAttribute( "modifiedAcl" );
			request.getSession().removeAttribute( "EditCatAclForm" );

			return handleBackAction(form);
		}

		return defaultInputForward;
	}

	protected ActionForward handleBackAction(DisplayAclSummaryViewForm form) {
		Integer targetId = form.getTargetId();
		Integer subTargetId = form.getSubTargetId();
		
		if ( targetId == null && subTargetId == null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&sourcePageId=" + form.getSourcePageId() );
		}
		
		if ( targetId != null && subTargetId != null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&targetId=" + targetId + 
				"&subTargetId=" + subTargetId + 
				"&sourcePageId=" + form.getSourcePageId() );
		}
		
		if ( targetId != null && subTargetId == null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&targetId=" + targetId + 
				"&sourcePageId=" + form.getSourcePageId() );
		}
		
		if ( targetId == null && subTargetId != null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&subTargetId=" + subTargetId + 
				"&sourcePageId=" + form.getSourcePageId() );
		}

		return new ActionForward( 
			"/editCategoryAcl.do" + 
			"?categoryId=" + form.getCategoryId() + 
			"&init=true" + 
			"&sourcePageId=" + form.getSourcePageId() );
	}
}