/*
 * $Id: DisplayAclSummaryViewForm.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: DisplayAclSummaryViewForm.java,v $
 * Revision 1.4  2005/05/31 15:33:32  marbobo
 * + Anpassungen wegen Virtoweb (betrifft backAction)
 *
 * Revision 1.3  2005/05/30 16:13:03  jonyp
 * cleanup code for instant use, throw away some overhead
 *
 * Revision 1.2  2005/05/25 15:23:06  jonyp
 * *** empty log message ***
 *
 * Revision 1.1  2005/05/24 14:45:19  jonyp
 * first strike
 *
 */
package vkc.view.form;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

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

import vkc.db.serializer.VKCAclSerializer;
import vkc.db.serializer.VKCCategorySerializer;
import vkc.db.serializer.VKCPermissionSerializer;
import vkc.exception.DBException;
import vkc.security.VKCAcl;
import vkc.view.PageId;

/*
 * TODO: evt so erweitern, das eine default acl auch angezeigt werden kann 
 */


public class DisplayAclSummaryViewForm extends ActionForm {
	private static final String PERMISSION_CONTEXT 	= "category";

	private Integer categoryId = null;
	private Integer sourcePageId = PageId.CATEGORY_VIEW;
	private Integer targetId = null;
	private Integer subTargetId = null;

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset(mapping, request);
		
		categoryId = null;
		sourcePageId = PageId.CATEGORY_VIEW;
		targetId = null;
		subTargetId = null;
	}
	
	public List getEnabledPermissions() {
        try {
            return VKCPermissionSerializer.retrieveContextPermissions(DisplayAclSummaryViewForm.PERMISSION_CONTEXT, true);    
        } catch (Exception e) {
            return new ArrayList();
        } 
	}

	public VKCAcl getAcl() {
	    try {
	        return VKCAclSerializer.getAclByCategoryId(categoryId);	        
	    } catch (Exception e) {
	        return null;
	    }
	}
    
	public String getCategoryName() throws DBException {
	    if (categoryId != null) {
	        return VKCCategorySerializer.retrieveCategory(categoryId).getName();
	    }
	    
	    return "";
    }

	public Integer getCategoryId() {
        return categoryId;
    }

	public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public Integer getSourcePageId() {
        return sourcePageId;
    }

    public void setSourcePageId(Integer sourcePageId) {
        this.sourcePageId = sourcePageId;
    }

    public Integer getSubTargetId() {
        return subTargetId;
    }

    public void setSubTargetId(Integer subTargetId) {
        this.subTargetId = subTargetId;
    }

    public Integer getTargetId() {
        return targetId;
    }

    public void setTargetId(Integer targetId) {
        this.targetId = targetId;
    }
}