/*
 * $Id: TreeViewAction.java,v 1.15 2005/02/15 09:26:52 bigmac Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: TreeViewAction.java,v $
 * Revision 1.15  2005/02/15 09:26:52  bigmac
 * Refactorings
 *
 * Revision 1.14  2004/11/02 21:42:31  marbobo
 * + Einige Funktionen für Gast-Benutzer gesperrt
 * + WebShare.LOGIN_PAGE mit WebShare.getLoginPage() ersetzt
 *
 * Revision 1.13  2004/06/15 20:21:33  marbobo
 * Refactoring
 *
 * Revision 1.12  2003/11/12 01:11:11  koppy
 * Navigatorverhalten optimiert
 *
 * Revision 1.11  2003/11/11 02:39:09  koppy
 * Redesign/ Refactoring
 *
 * Revision 1.10  2003/10/16 08:27:55  bigmac
 * *** empty log message ***
 *
 * Revision 1.9  2003/09/16 00:21:59  koppy
 * *** empty log message ***
 *
 * Revision 1.8  2003/08/03 15:34:19  bigmac
 * *** empty log message ***
 *
 * Revision 1.7  2003/05/20 01:38:40  koppy
 * <No Comment Entered>
 *
 * Revision 1.6  2003/05/13 12:52:37  koppy
 * ...
 *
 * Revision 1.5  2003/05/05 15:08:01  koppy
 * ...
 *
 * Revision 1.4  2003/05/01 22:46:04  koppy
 * <No Comment Entered>
 *
 * Revision 1.3  2003/04/30 01:12:03  koppy
 * Optional filter embedded
 *
 * Revision 1.2  2003/04/29 15:12:42  koppy
 * mit showDocs parametrisiert
 *
 * Revision 1.1  2003/04/29 11:08:24  koppy
 * Initiale Version
 *
 */
package vkc.util.treeview;

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.db.entities.VKCUser;
import vkc.util.ObjectCloner;
import vkc.util.ServletUtils;

/**
 * This class is used for building a tree and afterwards forwarding to a
 * TreeView JSP
 *
 * @author koppy
 */
public final class TreeViewAction extends Action {
	public ActionForward execute( ActionMapping mapping,
	        					  ActionForm form,
	        					  HttpServletRequest request,
	        					  HttpServletResponse response )
	throws Exception {
		VKCUser user = ServletUtils.getUser(request);
		TreeViewForm tForm = (TreeViewForm) form;
		TreeViewManager tm = TreeViewManager.getInstance();
		 
		// TreeView aktualisieren
		if ( tm.updateRequested() || tForm.refresh() ) {
			tm.buildGlobalTree();
		}
						
		TreeView tree = (TreeView)request.getSession().getAttribute( TreeView.TREE_KEY ); 

		if ( tree == null || !tree.isUpToDate() ) {
			tree = (TreeView)ObjectCloner.deepCopy( tm.getGlobalTreeView() );			
			tree.setUser( user );	
			tree.clearTreeViewItems();										
			request.getSession().setAttribute( TreeView.TREE_KEY, tree );
		}				

		return new ActionForward( "/templates/${template.name}/common/NavigatorView.jsp" );
	}
}