/*
 * $Id: NewLdapServerForm.java,v 1.6 2004/11/24 17:26:26 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: NewLdapServerForm.java,v $
 * Revision 1.6  2004/11/24 17:26:26  jonyp
 * added getAuthenticationMethods
 *
 * Revision 1.5  2004/11/01 15:52:18  vchris
 * + Anpassungen an neues DB-Schema
 * + Behandlung von LastChangerId und LastChanged
 *
 * Revision 1.4  2004/10/26 15:00:30  jonyp
 * added support of mapping_language
 *
 * Revision 1.3  2004/10/21 14:24:30  vchris
 * Small Bugfix
 *
 * Revision 1.2  2004/10/21 13:24:06  vchris
 * Update für neue LDAP Funktionalitäten
 *
 * Revision 1.1  2004/10/18 00:27:30  vchris
 * Initiale Version
 *
 *
 */

package vkc.ldap.administration.form;

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

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import vkc.view.form.BasicActionForm;

public final class NewLdapServerForm extends BasicActionForm {

	private String serverUrl 			= "";
	private String description 			= "";
	private String baseDN 				= "";
	private String usersBaseRDN 		= "";
	private String groupsBaseRDN 		= "";
	private String mappingLoginAttr		= "";
	private String mappingUserId		= "";
	private String mappingEmail			= "";
	private String mappingFullName		= "";
	private String mappingLanguage      = "";
	private boolean enabled;
	private String authmethod;

	public void reset( ActionMapping mapping, HttpServletRequest request ) {
		super.reset( mapping, request );
    }   

    public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) {
        ActionErrors errors = new ActionErrors();

		if ( request.getParameter( "action.newServer" ) != null ) {
	        if ( isEmpty( getServerUrl() ) ) {
	            errors.add( "serverUrl", new ActionError( "vkc.administration.ldap.error.serverUrlRequired" ) );
	        }
	        
	        if ( isEmpty( getDescription() ) ) {
	        	errors.add( "description", new ActionError( "vkc.administration.ldap.error.descriptionRequired" ) );
	        }
	
	        if ( isEmpty( getAuthmethod() ) ) {
	            errors.add( "authmethod", new ActionError( "vkc.administration.ldap.error.authmethodRequired" ) );
	        }
	
	        if ( isEmpty( getBaseDN() ) ) {
	            errors.add( "basedn", new ActionError( "vkc.administration.ldap.error.basednRequired" ) );
	        }

			if ( isEmpty( getUsersBaseRDN() ) ) {
				errors.add( "usersBaseRDN", new ActionError ( "vkc.administration.ldap.error.usersBaseRDNRequired" ) );
			}

			if ( isEmpty( getGroupsBaseRDN() ) ) {
				errors.add( "groupsBaseRDN", new ActionError ( "vkc.administration.ldap.error.groupsBaseRDNRequired" ) );
			}

			if ( isEmpty( getMappingLoginAttr() ) ) {
				errors.add( "mapping.loginAttr", new ActionError ( "vkc.administration.ldap.error.mapping.loginAttrRequired" ) );
			}

			if ( isEmpty( getMappingUserId() ) ) {
				errors.add( "mapping.userId", new ActionError ( "vkc.administration.ldap.error.mapping.userIdRequired" ) );
			}
	
			if ( isEmpty( getMappingFullName() ) ) {
				errors.add( "mapping.fullName", new ActionError ( "vkc.administration.ldap.error.mapping.FullNameRequired" ) );
			}
	
		}

		return errors;
    }
	public String getAuthmethod() {
		return authmethod;
	}
	
	public void setAuthmethod(String authmethod) {
		this.authmethod = authmethod;
	}
	
	public String getBaseDN() {
		return baseDN;
	}
	
	public void setBaseDN(String baseDN) {
		this.baseDN = baseDN;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public boolean isEnabled() {
		return enabled;
	}
	
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	public String getServerUrl() {
		return serverUrl;
	}
	
	public void setServerUrl(String serverUrl) {
		this.serverUrl = serverUrl;
	}
	
	public String getGroupsBaseRDN() {
		return groupsBaseRDN;
	}

	public String getMappingEmail() {
		return mappingEmail;
	}

	public String getMappingFullName() {
		return mappingFullName;
	}

	public String getMappingLanguage() {
		return mappingLanguage;
	}
	
	public String getMappingLoginAttr() {
		return mappingLoginAttr;
	}

	public String getMappingUserId() {
		return mappingUserId;
	}

	public String getUsersBaseRDN() {
		return usersBaseRDN;
	}

	public void setGroupsBaseRDN(String string) {
		groupsBaseRDN = string;
	}

	public void setMappingEmail(String string) {
		mappingEmail = string;
	}

	public void setMappingFullName(String string) {
		mappingFullName = string;
	}

	public void setMappingLanguage(String string) {
		mappingLanguage = string;
	}
	
	public void setMappingLoginAttr(String string) {
		mappingLoginAttr = string;
	}

	public void setMappingUserId(String string) {
		mappingUserId = string;
	}

	public void setUsersBaseRDN(String string) {
		usersBaseRDN = string;
	}
	
	public List getAuthenticationMethods() {
	    
	    ArrayList authMethods = new ArrayList();    
	    
	    authMethods.add("simple");
	    
	    return authMethods;
	}
}