/*
ESUP-portail is a french academic project developed under the GPL (General Public License) augmented according to the following :
A binary or source file developped by ESUP-portail can be used or compiled with products under Apache license.
The official english text of the GPL can be found here : http://www.gnu.org/licenses/gpl.html .
A non official french translation can be found here : http://www.linux-France.org/article/these/gpl.html .
The different kinds of licenses governing the products developed by the Apache foundation can be found here : http://www.apache.org/licenses .
It follows that you can as well as use download contents as well modify and redistribute them provided you respect the GPL terms.
Downloading and using such contents do not provide any guaranty.
Be sure that you have well understood the terms of the license before using the contents it covers.
The ESUP-portail distribution includes the following distributions :
    * UPortal : 
      software developed by JA-SIG (Java Architecture - Special Interest Group)
      You can find the license page here : http://mis105.udel.edu/ja-sig/uportal/license.html
    * CAS :
      SSO solution developed by Yale University
      You can find the project page here : http://www.yale.edu/tp/auth
    * Cocoon :
      XML framework distributed by the Apache foundation under Apache license;
      Please find the full text here : http://cocoon.apache.org/2.1/license.html
    * Mod_dav:
      A DAV module for Apache web server
      You can find the project page here : http://www.webdav.org/mod_dav
    * IMP :
      webmail from Horde application framework
      You can find the project page here : http://www.horde.org
    * …. To be completed
*/
package org.esupportail.portal.channels.CStockage.config;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.ArrayList;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.esupportail.portal.channels.CStockage.exception.PropertiesException;
import org.jasig.portal.security.IPerson;

/**
 * Id: Server.java,v 1.0 14 avril 2005<br/>
 * Copyright (c) 2004 Esup Portail (www.esup-portail.org)<br/>
 * Classes: Server<br/>
 * Original Author: Yohan Colmant<br/>
 * This represents a server in the configuration file<br/>
 */
public class Server {


	/**
	 * Logger object
	 */
	protected static final Log log = LogFactory.getLog(Server.class);
	



	/**
	 * CAS authentication
	 */
	private static final String AUTH_CAS = "cas";
	
	/**
	 * TRUSTED authentication
	 */
	private static final String AUTH_TRUSTED = "trusted";
	
	/**
	 * ASKED authentication
	 */
	private static final String AUTH_ASKED = "asked";
	
	
	/**
	 * The spaces list into this server
	 */
	private ArrayList spaces = new ArrayList();
	
	/**
	 * The name of the server
	 */
	private String name;
	
	/**
	 * The server id
	 */
	private String id;
	
	/**
	 * The server url
	 */
	private String url;
	
	/**
	 * The server type
	 */
	private String serverType;

	/**
	 * The authentication mode. "cas" or "trusted"
	 */
	private String authenticationMode;
	
	/**
	 * The login if trusted authentication
	 */
	private String login;

	/**
	 * The login if trusted authentication
	 */
	private String initialLoginFromTheConfigurationFile;
	
	/**
	 * If the login is from the configuration file
	 */
	private boolean loginIsFromConfigurationFile = false;
	
	
	/**
	 * The password if trusted authentication, or is asked authentication
	 */
	private String password;

	/**
	 * The ACL namespace
	 */
	private String aclNamespace;
	
	/**
	 * The user prefix for the ACL
	 */
	private String aclUserPrefix;
	
	/**
	 * The group prefix for the ACL
	 */
	private String aclGroupPrefix;

	/**
	 * The uPortal group node for the ACL
	 */
	private String aclUportalGroup;

	
	/**
	 * The cifs domain
	 */
	private String cifsDomain;
	
	/**
	 * The Cifs resolve order
	 */
	private String cifsResolveOrder;
	
	/**
	 * The cifs disable plain text password
	 */
	private String cifsDisablePlainTextPassword;
	
	/**
	 * The Cifs use unicode
	 */
	private String cifsUseUnicode;
	
	/**
	 * The Cifs encoding
	 */
	private String cifsEncoding;
	
	/**
	 * The NFS Uid Number
	 */
	public String nfsUidNumber;
	/**
	 * The NFS Gid Number
	 */
	private String nfsGidNumber;
	
	/**
	 * The URL to access the server in public mode
	 */
	private String unauthenticatedServerUrl;
	
	/**
	 * The URL to access the injac preview
	 */
	private String injacPreviewUrl;
	
	/**
	 * The URL to access final URL
	 */
	private String injacFinalUrl;
	
	

	/**
	 * The class name used to manage the actions
	 */
	private String serverAccessClass;

	

	
	
	
	
	/**
	 * @return Returns the spaces.
	 */
	public ArrayList getSpaces() {
		return spaces;
	}
	/**
	 * @param space The space to set.
	 */
	public void addSpace(Space space) {
		spaces.add(space);
	}
	/*public void initSpaces() {
		spaces = null;
	}*/
	/**
	 * @param spaces The spaces to set.
	 */
	public void setSpaces(ArrayList spaces) {
		this.spaces = spaces;
	}
	

	
	/**
	 * @return Returns the injacPreviewUrl.
	 */
	public String getInjacPreviewUrl() {
		return injacPreviewUrl;
	}
	/**
	 * @param injacPreviewUrl The injacPreviewUrl to set.
	 */
	public void setInjacPreviewUrl(String injacPreviewUrl) {
		this.injacPreviewUrl = injacPreviewUrl;
		if (this.injacPreviewUrl.endsWith("/")) {
			this.injacPreviewUrl = this.injacPreviewUrl.substring(0, this.injacPreviewUrl.length()-1);
		}
	}
	
	
	
	public String getInjacFinalUrl() {
		return injacFinalUrl;
	}
	public void setInjacFinalUrl(String injacFinalUrl) {
		this.injacFinalUrl = injacFinalUrl;
		if (this.injacFinalUrl.endsWith("/")) {
			this.injacFinalUrl = this.injacFinalUrl.substring(0, this.injacFinalUrl.length()-1);
		}
	}
	
	/**
	 * @return Returns the unauthenticatedServerUrl.
	 */
	public String getUnauthenticatedServerUrl() {
		return unauthenticatedServerUrl;
	}
	/**
	 * @param unauthenticatedServerUrl The unauthenticatedServerUrl to set.
	 */
	public void setUnauthenticatedServerUrl(String unauthenticatedServerUrl) {
		this.unauthenticatedServerUrl = unauthenticatedServerUrl;
		if (this.unauthenticatedServerUrl.endsWith("/")) {
			this.unauthenticatedServerUrl = this.unauthenticatedServerUrl.substring(0, this.unauthenticatedServerUrl.length()-1);
		}
	}
	
	
	/**
	 * @return Returns the manageAcl.
	 */
	public boolean managesAcl() {		
		boolean parametersSet = hasAclParameterSet() && manageAcl.equals("true");
		if (!parametersSet) {
			log.debug("managesAcl :: there is no acl access parameters set for space "+getId());
			return false;
		}
		return parametersSet;
	}
	
	
	
	String manageAcl = "true";
	
	public String getManageAcl() {		
		return managesAcl()+"";
	}
	
	public void setManageAcl(String manageAcl) {		
		this.manageAcl = manageAcl;
	}
	
	

	/**
	 * @return check if the server allow the personalization
	 */
	protected boolean allowsPersonalization() throws PropertiesException {		
		boolean managesAcl = managesAcl();
		boolean spacesPersonalization = ChannelConfiguration.getInstance().isSpacesPersonalization();
		if (!managesAcl && spacesPersonalization) {
			log.debug("allowPersonalization :: there is no acl access parameters set for space "+getId());
			return false;
		}
		return managesAcl && spacesPersonalization;
	}
	
	
	
	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return Returns the cifsDisablePlainTextPassword.
	 */
	public String getCifsDisablePlainTextPassword() {
		return cifsDisablePlainTextPassword;
	}
	/**
	 * @param cifsDisablePlainTextPassword The cifsDisablePlainTextPassword to set.
	 */
	public void setCifsDisablePlainTextPassword(
			String cifsDisablePlainTextPassword) {
		this.cifsDisablePlainTextPassword = cifsDisablePlainTextPassword;
	}
	/**
	 * @return Returns the cifsDomain.
	 */
	public String getCifsDomain() {
		return cifsDomain;
	}
	
	
	
	
	/**
	 * @param cifsDomain The cifsDomain to set.
	 */
	public void setCifsDomain(String cifsDomain) {
		this.cifsDomain = cifsDomain;
	}
	/**
	 * @return Returns the cifsResolveOrder.
	 */
	public String getCifsResolveOrder() {
		return cifsResolveOrder;
	}
	/**
	 * @param cifsResolveOrder The cifsResolveOrder to set.
	 */
	public void setCifsResolveOrder(String cifsResolveOrder) {
		this.cifsResolveOrder = cifsResolveOrder;
	}
	
	/**
	 * @return Returns the cifsEncoding.
	 */
	public String getCifsEncoding() {
		return cifsEncoding;
	}
	/**
	 * @param cifsEncoding The cifsEncoding to set.
	 */
	public void setCifsEncoding(String cifsEncoding) {
		this.cifsEncoding = cifsEncoding;
	}
	/**
	 * @return Returns the cifsUseUnicode.
	 */
	public String getCifsUseUnicode() {
		return cifsUseUnicode;
	}
	/**
	 * @param cifsUseUnicode The cifsUseUnicode to set.
	 */
	public void setCifsUseUnicode(String cifsUseUnicode) {
		this.cifsUseUnicode = cifsUseUnicode;
	}
	/**
	 * @return Returns the serverType.
	 */
	public String getServerType() {
		return serverType;
	}
	/**
	 * @param serverType The serverType to set.
	 */
	public void setServerType(String serverType) {
		this.serverType = serverType;
	}
	/**
	 * @return Returns the aclUportalGroup.
	 */
	public String getAclUportalGroup() {
		return aclUportalGroup;
	}
	/**
	 * @param aclUportalGroup The aclUportalGroup to set.
	 */
	public void setAclUportalGroup(String aclUportalGroup) {
		this.aclUportalGroup = aclUportalGroup;
	}
	/**
	 * @return Returns the aclGroupPrefix.
	 */
	public String getAclGroupPrefix() {
		return aclGroupPrefix;
	}
	/**
	 * @param aclGroupPrefix The aclGroupPrefix to set.
	 */
	public void setAclGroupPrefix(String aclGroupPrefix) {
		this.aclGroupPrefix = aclGroupPrefix;
	}
	/**
	 * @return Returns the aclNamespace.
	 */
	public String getAclNamespace() {
		return aclNamespace;
	}
	/**
	 * @param aclNamespace The aclNamespace to set.
	 */
	public void setAclNamespace(String aclNamespace) {
		this.aclNamespace = aclNamespace;
	}
	/**
	 * @return Returns the supportAcl.
	 */
	public boolean hasAclParameterSet() {
		if (aclNamespace==null || aclUserPrefix == null || aclGroupPrefix == null || aclUportalGroup == null)
			return false;				
		else return true;			
	}
	
	/**
	 * @return Returns the aclUserPrefix.
	 */
	public String getAclUserPrefix() {
		return aclUserPrefix;
	}
	/**
	 * @param aclUserPrefix The aclUserPrefix to set.
	 */
	public void setAclUserPrefix(String aclUserPrefix) {
		this.aclUserPrefix = aclUserPrefix;
	}
	
	/**
	 * If the selected authentication is CAS
	 * @return trus is cas is selected
	 */
	public boolean isCasAuthentication() throws PropertiesException {
		if (authenticationMode==null) {
			log.error("isCasAuthentication :: there is no authentication mode set for space "+getId());
			throw new PropertiesException();
		}
		return authenticationMode.equals(AUTH_CAS);
	}
	/**
	 * If the selected authentication is TRUSTED
	 * @return true if trusted is selected
	 */
	public boolean isTrustedAuthentication() throws PropertiesException {
		if (authenticationMode==null) {
			log.error("isTrustedAuthentication :: there is no authentication mode set for space "+getId());
			throw new PropertiesException();
		}
		return authenticationMode.equals(AUTH_TRUSTED);
	}
	/**
	 * If the selected authentication is ASKED
	 * @return true if asked is selected
	 */
	public boolean isAskedAuthentication() throws PropertiesException {
		if (authenticationMode==null) {
			log.error("isAskedAuthentication :: there is no authentication mode set for space "+getId());
			throw new PropertiesException();
		}
		return authenticationMode.equals(AUTH_ASKED);
	}
	

	/**
	 * @return Returns the login.
	 */
	public String getLogin() {
		return login;
	}
	/**
	 * @param login The login to set.
	 */
	public void setLogin(String login) {
		this.login = login;
	}
	/**
	 * @param initialLoginFromTheConfigurationFile The login to set.
	 */
	public void setInitialLoginFromTheConfigurationFile(String initialLoginFromTheConfigurationFile) {
		this.login = initialLoginFromTheConfigurationFile;
		this.initialLoginFromTheConfigurationFile = new String(initialLoginFromTheConfigurationFile);
		this.loginIsFromConfigurationFile = true;
	}
	
	
	/**
	 * @return Returns the loginIsFromConfigurationFile.
	 */
	public boolean isLoginIsFromConfigurationFile() {
		return loginIsFromConfigurationFile;
	}
	
	/**
	 * @return Returns the initialLoginFromTheConfigurationFile.
	 */
	public String getInitialLoginFromTheConfigurationFile() {
		return initialLoginFromTheConfigurationFile;
	}
	/**
	 * @param loginIsFromConfigurationFile The loginIsFromConfigurationFile to set.
	 */
	/*public void setLoginIsFromConfigurationFile(
			boolean loginIsFromConfigurationFile) {
		this.loginIsFromConfigurationFile = loginIsFromConfigurationFile;
	}*/
	/**
	 * @return Returns the login used with this space.
	 */
	/*public String getUsedLogin() {
		if (trustedLogin!=null)
			return trustedLogin;
		else return usedLogin;
	}*/	
	/**
	 * @param usedLogin The usedLogin to set.
	 */
	/*public void setUsedLogin(String usedLogin) {
		this.usedLogin = usedLogin;
	}*/
	
	
	
	/**
	 * @return Returns the trustedLogin.
	 */
	/*public String getTrustedLogin() {
		return trustedLogin;
	}*/
	/**
	 * @param trustedLogin The trustedLogin to set.
	 */
	/*public void setTrustedLogin(String trustedLogin) {
		this.trustedLogin = trustedLogin;
	}*/
	
	
	
	/**
	 * @return Returns the password.
	 */
	public String getPassword() throws PropertiesException {
		if (isTrustedAuthentication() && password==null) {
			log.error("getPassword :: there is no password set for trusted authentication for space "+getId());
			throw new PropertiesException();
		}
		return password;
	}
	/**
	 * @param password The trustedPassword to set.
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return Returns the url.
	 */
	public String getUrl() throws PropertiesException {
		if (url==null) {
			log.error("getUrl :: there is no URL set for space "+getId());
			throw new PropertiesException();
		}
		return url;
	}
	/**
	 * @param url The url to set.
	 */
	public void setUrl(String url) {
		this.url = url;
	}
	/**
	 * @param authenticationMode The authenticationMode to set.
	 */
	public void setAuthenticationMode(String authenticationMode) {
		this.authenticationMode = authenticationMode;
	}
	/**
	 * @return Returns the authenticationMode.
	 */
	public String getAuthenticationMode() {
		return authenticationMode;
	}
	
	/**
	 * @return Returns the serverAccessClass.
	 */
	public String getServerAccessClass() {
		return serverAccessClass;
	}
	/**
	 * @param serverAccessClass The serverAccessClass to set.
	 */
	public void setServerAccessClass(String serverAccessClass) {
		this.serverAccessClass = serverAccessClass;
	}
	
	
	
	
	/**
	 * @return Returns the id.
	 */
	public String getId() {
		return id;
	}
	
	/**
	 * @param id The id to set.
	 */
	public void setId(String id) {
		this.id = id;
	}
	
	
	
	
	
	
	
	
	/**
	 * we look for a {...} form in the attribute. If yes, we replace it with the real value
	 * @param attributeName to check 
	 * @param person uPortal person object
	 */
	public void checkAttribute(String attributeName, IPerson person) {
		
		Class c = this.getClass();
		String value;
		try {
			// we use java refexion to find getter and setter for attributeName
		    BeanInfo bi = Introspector.getBeanInfo(c);
		    PropertyDescriptor[] propertyDescriptor = bi.getPropertyDescriptors();
		    for (int i=0; i<propertyDescriptor.length; i++) {
		    	if (propertyDescriptor[i].getName().equals(attributeName)) {
		    		Method method = propertyDescriptor[i].getReadMethod();
		    		value = (String)method.invoke(this, new Object[0]);
		    		
					if (value!=null) {
						// find and replace {...}
						int firstIndex = value.indexOf("{");
						int lastIndex = value.indexOf("}");
						
						if (firstIndex!=-1 && lastIndex!=-1) {
						
							String begin = value.substring(0, firstIndex);
							String med = value.substring(firstIndex+1, lastIndex);
							String end = value.substring(lastIndex+1, value.length());
							
							String realMedValue = (String)person.getAttribute(med);
							
							String newString = begin+realMedValue+end;								
							
							method = propertyDescriptor[i].getWriteMethod();
							Object[] arg = {newString};
							method.invoke(this, arg);
							if (log.isDebugEnabled()){
								log.debug("checkAttribute"+" :: replace "+attributeName+" value "+value+" with "+newString);
							}

						}	
						
					}
		    		// no more nead to scan propertyDescriptor[] --> exit for statement
		    		i = propertyDescriptor.length;
		    	}
		    }
		}
		catch (InvocationTargetException e) {
			log.error("checkAttribute"+" :: "+e);			
		}
		catch (IntrospectionException e) {
			log.error("checkAttribute"+" :: "+e);			
		}
		catch (IllegalAccessException e) {
			log.error("checkAttribute"+" :: "+e);			
		}
	}
	
	
	

	/**
	 * @return Returns the nfsGidNumber.
	 */
	public String getNfsGidNumber() {
		return nfsGidNumber;
	}
	/**
	 * @param nfsGidNumber The nfsGidNumber to set.
	 */
	public void setNfsGidNumber(String nfsGidNumber) {
		this.nfsGidNumber = nfsGidNumber;
	}
	/**
	 * @return Returns the nfsUidNumber.
	 */
	public String getNfsUidNumber() {
		return nfsUidNumber;
	}
	/**
	 * @param nfsUidNumber The nfsUidNumber to set.
	 */
	public void setNfsUidNumber(String nfsUidNumber) {
		this.nfsUidNumber = nfsUidNumber;
	}
	
	

	/**
	 * init the server access object for this space
	 * @param person the uportal person object
	 * @throws MalformedURLException
	 * @throws PropertiesException
	 */
	public void initServerAccessObjectForEachSpace(IPerson person) throws MalformedURLException, PropertiesException {
		for (int i=0; spaces!=null && i<spaces.size(); i++) {
			Space space = (Space)spaces.get(i);
			
			space.checkPath(person);
			
			space.getServerAccessObject().init(space);
		}
	}
	
	
	
	/**
	 * Compare this to another object
	 * @param o object to compare
	 */
	public boolean equals(Object o) {
		
		Server server = (Server)o;
		
		if ( ( (server.url==null) && (server.url!=this.url) ) || ( (server.url!=null) && (!server.url.equals(this.url)) ) )
			return false;
		
		if ( ( (server.serverType==null) && (server.serverType!=this.serverType) ) || ( (server.serverType!=null) && (!server.serverType.equals(this.serverType)) ) )
			return false;
		
		if ( ( (server.serverAccessClass==null) && (server.serverAccessClass!=this.serverAccessClass) ) || ( (server.serverAccessClass!=null) && (!server.serverAccessClass.equals(this.serverAccessClass)) ) )
			return false;
		
		if ( ( (server.authenticationMode==null) && (server.authenticationMode!=this.authenticationMode) ) || ( (server.authenticationMode!=null) && (!server.authenticationMode.equals(this.authenticationMode)) ) )
			return false;
		
		if ( ( (server.login==null) && (server.login!=this.login) ) || ( (server.login!=null) && (!server.login.equals(this.login)) ) )
			return false;
		
		if (server.loginIsFromConfigurationFile != this.loginIsFromConfigurationFile)
			return false;
		
		if ( ( (server.initialLoginFromTheConfigurationFile==null) && (server.initialLoginFromTheConfigurationFile!=this.initialLoginFromTheConfigurationFile) ) || ( (server.initialLoginFromTheConfigurationFile!=null) && (!server.initialLoginFromTheConfigurationFile.equals(this.initialLoginFromTheConfigurationFile)) ) )
			return false;
		
		if ( ( (server.password==null) && (server.password!=this.password) ) || ( (server.password!=null) && (!server.password.equals(this.password)) ) )
			return false;
		
		if ( ( (server.aclNamespace==null) && (server.aclNamespace!=this.aclNamespace) ) || ( (server.aclNamespace!=null) && (!server.aclNamespace.equals(this.aclNamespace)) ) )
			return false;
		
		if ( ( (server.aclUserPrefix==null) && (server.aclUserPrefix!=this.aclUserPrefix) ) || ( (server.aclUserPrefix!=null) && (!server.aclUserPrefix.equals(this.aclUserPrefix)) ) )
			return false;
		
		if ( ( (server.aclGroupPrefix==null) && (server.aclGroupPrefix!=this.aclGroupPrefix) ) || ( (server.aclGroupPrefix!=null) && (!server.aclGroupPrefix.equals(this.aclGroupPrefix)) ) )
			return false;
		
		if ( ( (server.aclUportalGroup==null) && (server.aclUportalGroup!=this.aclUportalGroup) ) || ( (server.aclUportalGroup!=null) && (!server.aclUportalGroup.equals(this.aclUportalGroup)) ) )
			return false;
		
		if ( ( (server.cifsDomain==null) && (server.cifsDomain!=this.cifsDomain) ) || ( (server.cifsDomain!=null) && (!server.cifsDomain.equals(this.cifsDomain)) ) )
			return false;
		
		if ( ( (server.cifsResolveOrder==null) && (server.cifsResolveOrder!=this.cifsResolveOrder) ) || ( (server.cifsResolveOrder!=null) && (!server.cifsResolveOrder.equals(this.cifsResolveOrder)) ) )
			return false;
		
		if ( ( (server.cifsDisablePlainTextPassword==null) && (server.cifsDisablePlainTextPassword!=this.cifsDisablePlainTextPassword) ) || ( (server.cifsDisablePlainTextPassword!=null) && (!server.cifsDisablePlainTextPassword.equals(this.cifsDisablePlainTextPassword)) ) )
			return false;
		
		if ( ( (server.nfsUidNumber==null) && (server.nfsUidNumber!=this.nfsUidNumber) ) || ( (server.nfsUidNumber!=null) && (!server.nfsUidNumber.equals(this.nfsUidNumber)) ) )
			return false;
		
		if ( ( (server.nfsGidNumber==null) && (server.nfsGidNumber!=this.nfsGidNumber) ) || ( (server.nfsGidNumber!=null) && (!server.nfsGidNumber.equals(this.nfsGidNumber)) ) )
			return false;
		
		return true;
	}
	
	
	
	

	
	/**
	 * Return a String representation of this space
	 */
	public String toString() {
		return 
		"id: "+id+"\n"+
		"url: "+url;
	}
	
	
	
	
	/**
	 * Clone this object
	 * @return a clone of this object
	 */
	public Object clone() {
		Server server = new Server();
		
		if (spaces!=null) {
			ArrayList spacesClone = new ArrayList(spaces.size());
			for (int i=0; i<spaces.size(); i++) {
				Space spaceClone = (Space)((Space)spaces.get(i)).cloneWithoutServer();
				spaceClone.setServer(server);
				spacesClone.add(spaceClone);
			}
			server.spaces = spacesClone;
		}
		
		
		server.name = this.name;
		
		server.id = this.id;
		server.url = this.url;
		server.unauthenticatedServerUrl = this.unauthenticatedServerUrl;
		server.injacPreviewUrl = this.injacPreviewUrl;
		server.injacFinalUrl = this.injacFinalUrl;
		server.serverType = this.serverType;
		server.serverAccessClass = this.serverAccessClass;
		server.authenticationMode = this.authenticationMode;
		server.login = this.login;
		server.loginIsFromConfigurationFile = this.loginIsFromConfigurationFile;
		server.initialLoginFromTheConfigurationFile = this.initialLoginFromTheConfigurationFile;
		server.password = this.password;
		
		server.aclNamespace = this.aclNamespace;
		server.aclUserPrefix = this.aclUserPrefix;
		server.aclGroupPrefix = this.aclGroupPrefix;
		server.aclUportalGroup = this.aclUportalGroup;
		
		server.cifsDomain = this.cifsDomain;
		server.cifsResolveOrder = this.cifsResolveOrder;
		server.cifsDisablePlainTextPassword = this.cifsDisablePlainTextPassword;
		server.cifsUseUnicode = this.cifsUseUnicode;
		server.cifsEncoding = this.cifsEncoding;
		
		server.nfsUidNumber = this.nfsUidNumber;
		server.nfsGidNumber = this.nfsGidNumber;
		
		return server;
	}
	
	
	

	/**
	 * Get the xml in the configuration file style
	 * @return the xml in the configuration file style
	 */
	public StringBuffer getLocalXmlBegin() {
		
		StringBuffer xmlServer = new StringBuffer();		
		xmlServer.append("<SERVER");
		
		// url
		try {
			String url = this.getUrl();
			if (url!=null && !url.trim().equals(""))
				xmlServer.append(" url=\""+url+"\"\n");
		}
		catch(PropertiesException e) {
			if (log.isDebugEnabled())
				log.error("getXml :: " + e.toString());
		}

		// serverType
		String serverType = this.getServerType();
		if (serverType!=null && !serverType.trim().equals(""))
			xmlServer.append(" serverType=\""+serverType+"\"\n");

		// authenticationMode
		String authenticationMode = this.getAuthenticationMode();
		if (authenticationMode!=null && !authenticationMode.trim().equals(""))
			xmlServer.append(" authenticationMode=\""+authenticationMode+"\"\n");

		// login
		try {
			if (this.isTrustedAuthentication() || this.isAskedAuthentication()) {

				if (this.isLoginIsFromConfigurationFile()) {
					String login = this.getInitialLoginFromTheConfigurationFile();
					if (login!=null && !login.trim().equals(""))
						xmlServer.append(" login=\""+login+"\"\n");
				}
				
			}
		}
		catch(PropertiesException e) {
			if (log.isDebugEnabled())
				log.error("getXml :: " + e.toString());
		}
		
		// password
		try {
			if (this.isTrustedAuthentication()) {
				try {				
					String trustedPassword = this.getPassword();
					if (trustedPassword!=null && !trustedPassword.trim().equals(""))
						xmlServer.append(" password=\""+trustedPassword+"\"\n");
				}
				catch(PropertiesException e) {
					if (log.isDebugEnabled())
						log.error("getXml :: " + e.toString());
				}
			}
		}
		catch(PropertiesException e) {
			if (log.isDebugEnabled())
				log.error("getXml :: " + e.toString());
		}
		
		// manageAcl
		/*boolean manageAcl = this.managesAcl();
		xmlServer.append(" manageAcl=\""+manageAcl+"\"\n");*/
		

		// aclNamespace
		String aclNamespace = this.getAclNamespace();
		if (aclNamespace!=null && !aclNamespace.trim().equals(""))
			xmlServer.append(" aclNamespace=\""+aclNamespace+"\"\n");

		// aclUserPrefix
		String aclUserPrefix = this.getAclUserPrefix();
		if (aclUserPrefix!=null && !aclUserPrefix.trim().equals(""))
			xmlServer.append(" aclUserPrefix=\""+aclUserPrefix+"\"\n");

		// aclGroupPrefix
		String aclGroupPrefix = this.getAclGroupPrefix();
		if (aclGroupPrefix!=null && !aclGroupPrefix.trim().equals(""))
			xmlServer.append(" aclGroupPrefix=\""+aclGroupPrefix+"\"\n");
		
		// aclUportalGroup
		String aclUportalGroup = this.getAclUportalGroup();
		if (aclUportalGroup!=null && !aclUportalGroup.trim().equals(""))
			xmlServer.append(" aclUportalGroup=\""+aclUportalGroup+"\"\n");

		// cifsDomain
		String cifsDomain = this.getCifsDomain();
		if (cifsDomain!=null && !cifsDomain.trim().equals(""))
			xmlServer.append(" cifsDomain=\""+cifsDomain+"\"\n");

		// cifsResolveOrder
		String cifsResolveOrder = this.getCifsResolveOrder();
		if (cifsResolveOrder!=null && !cifsResolveOrder.trim().equals(""))
			xmlServer.append(" cifsResolveOrder=\""+cifsResolveOrder+"\"\n");

		// cifsDisablePlainTextPassword
		String cifsDisablePlainTextPassword = this.getCifsDisablePlainTextPassword();
		if (cifsDisablePlainTextPassword!=null && !cifsDisablePlainTextPassword.trim().equals(""))
			xmlServer.append(" cifsDisablePlainTextPassword=\""+cifsDisablePlainTextPassword+"\"\n");

		// cifsEncoding
		String cifsEncoding = this.getCifsEncoding();
		if (cifsEncoding!=null && !cifsEncoding.trim().equals(""))
			xmlServer.append(" cifsEncoding=\""+cifsEncoding+"\"\n");

		// cifsUseUnicode
		String cifsUseUnicode = this.getCifsUseUnicode();
		if (cifsUseUnicode!=null && !cifsUseUnicode.trim().equals(""))
			xmlServer.append(" cifsUseUnicode=\""+cifsUseUnicode+"\"\n");
		
		// nfsUidNumber
		String nfsUidNumber = this.getNfsUidNumber();
		if (nfsUidNumber!=null && !nfsUidNumber.trim().equals(""))
			xmlServer.append(" nfsUidNumber=\""+nfsUidNumber+"\"\n");

		// nfsGidNumber
		String nfsGidNumber = this.getNfsGidNumber();
		if (nfsGidNumber!=null && !nfsGidNumber.trim().equals(""))
			xmlServer.append(" nfsGidNumber=\""+nfsGidNumber+"\"\n");

		// unauthenticatedServerUrl
		String unauthenticatedServerUrl = this.getUnauthenticatedServerUrl();
		if (unauthenticatedServerUrl!=null && !unauthenticatedServerUrl.trim().equals(""))
			xmlServer.append(" unauthenticatedServerUrl=\""+unauthenticatedServerUrl+"\"\n");

		// injacPreviewUrl
		String injacPreviewUrl = this.getInjacPreviewUrl();
		if (injacPreviewUrl!=null && !injacPreviewUrl.trim().equals(""))
			xmlServer.append(" injacPreviewUrl=\""+injacPreviewUrl+"\"\n");

		// injacFinalUrl
		String injacFinalUrl = this.getInjacFinalUrl();
		if (injacFinalUrl!=null && !injacFinalUrl.trim().equals(""))
			xmlServer.append(" injacFinalUrl=\""+injacFinalUrl+"\"\n");
		
		
		xmlServer.append(" >\n");
		
		return xmlServer;
		
	}
	
	
	
	

	/**
	 * Get the xml in the configuration file style
	 * @return the xml in the configuration file style
	 */
	public StringBuffer getLocalXmlEnd() {
		return new StringBuffer("</SERVER>\n");
		
	}
	
	

	/**
	 * Get the xml in the configuration file style
	 * @return the xml in the configuration file style
	 */
	public String getXml() {
		
		StringBuffer xml = new StringBuffer();
		
		xml.append(getLocalXmlBegin());
		
		for (int i=0; i<this.spaces.size(); i++) {
			Space s = (Space)spaces.get(i);
			xml.append(s.getLocalXml());
		}
		
		xml.append(getLocalXmlEnd());
		
		return xml.toString();
	}
	
}
