Merged V2.2 to HEAD

8121: Merged V2.1 to V2.2
      8088: Turned off debug logging.
      8090: Tweaked session cache limiting for AVM.
      8095: Fix for issue raised in ACT 402
      8108: Fix for AWC-1816
      8115: Build fix 
      8117: Fix AR-1217: OpenOffice connection is actively maintained

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8480 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-03-10 15:22:43 +00:00
parent 086838b020
commit c560aef6bd
7 changed files with 210 additions and 94 deletions

View File

@@ -25,6 +25,7 @@
package org.alfresco.web.app;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@@ -39,6 +40,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigService;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.importer.ImporterBootstrap;
@@ -47,12 +49,15 @@ import org.alfresco.web.app.servlet.AuthenticationHelper;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.ErrorBean;
import org.alfresco.web.bean.SidebarBean;
import org.alfresco.web.bean.users.UserPreferencesBean;
import org.alfresco.web.bean.dashboard.DashboardManager;
import org.alfresco.web.bean.dialog.DialogManager;
import org.alfresco.web.bean.repository.PreferencesService;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.bean.wizard.WizardManager;
import org.alfresco.web.config.ClientConfigElement;
import org.alfresco.web.config.LanguagesConfigElement;
import org.apache.commons.logging.Log;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
@@ -555,6 +560,7 @@ public class Application
}
/**
<<<<<<< .working
* @return the Projects folder name
*/
public static String getProjectsFolderName(ServletContext context)
@@ -572,6 +578,9 @@ public class Application
/**
* Set the language locale for the current user context
=======
* Set the language locale for the current user session.
>>>>>>> .merge-right.r8121
*
* @param context FacesContext for current user
* @param code The ISO locale code to set
@@ -589,20 +598,27 @@ public class Application
// clear the current message bundle - so it's reloaded with new locale
context.getExternalContext().getSessionMap().remove(MESSAGE_BUNDLE);
// Set the current locale in the server thread
I18NUtil.setLocale(locale);
}
/**
* Set the language locale for the current user session
* Set the language locale for the current user session.
*
* @param session HttpSession for current user
* @param code The ISO locale code to set
*/
@Deprecated
public static void setLanguage(HttpSession session, String code)
{
Locale locale = I18NUtil.parseLocale(code);
session.setAttribute(LOCALE, locale);
session.removeAttribute(MESSAGE_BUNDLE);
// Set the current locale in the server thread
I18NUtil.setLocale(locale);
}
/**
@@ -610,12 +626,45 @@ public class Application
*
* @param context FacesContext for the current user
*
* @return Current language Locale set or the VM default if none set
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(FacesContext context)
public static Locale getLanguage(FacesContext fc)
{
Locale locale = (Locale)context.getExternalContext().getSessionMap().get(LOCALE);
return locale != null ? locale : Locale.getDefault();
Locale locale = (Locale)fc.getExternalContext().getSessionMap().get(LOCALE);
if (locale == null)
{
// first check saved user preferences
String strLocale = null;
if (getCurrentUser(fc) != null)
{
strLocale = (String)PreferencesService.getPreferences(fc).getValue(
UserPreferencesBean.PREF_INTERFACELANGUAGE);
if (strLocale != null)
{
locale = I18NUtil.parseLocale(strLocale);
}
}
else
{
// else get from web-client config - the first item in the configured list of languages
Config config = Application.getConfigService(fc).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
if (languages != null && languages.size() != 0)
{
locale = I18NUtil.parseLocale(languages.get(0));
}
else
{
// failing that, use the server default locale
locale = Locale.getDefault();
}
}
// save in user session
fc.getExternalContext().getSessionMap().put(LOCALE, locale);
}
return locale;
}
/**
@@ -623,12 +672,45 @@ public class Application
*
* @param session HttpSession for the current user
*
* @return Current language Locale set or the VM default if none set
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(HttpSession session)
{
Locale locale = (Locale)session.getAttribute(LOCALE);
return locale != null ? locale : Locale.getDefault();
if (locale == null)
{
// first check saved user preferences
String strLocale = null;
if (getCurrentUser(session) != null)
{
strLocale = (String)PreferencesService.getPreferences(session).getValue(
UserPreferencesBean.PREF_INTERFACELANGUAGE);
if (strLocale != null)
{
locale = I18NUtil.parseLocale(strLocale);
}
}
else
{
// else get from web-client config - the first item in the configured list of languages
Config config = Application.getConfigService(session.getServletContext()).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
if (languages != null && languages.size() != 0)
{
locale = I18NUtil.parseLocale(languages.get(0));
}
else
{
// failing that, use the server default locale
locale = Locale.getDefault();
}
}
// save in user session
session.setAttribute(LOCALE, locale);
}
return locale;
}
/**
@@ -636,12 +718,33 @@ public class Application
*
* @param session PortletSession for the current user
*
* @return Current language Locale set or the VM default if none set
* @return Current language Locale set or the VM default if none set - never null
*/
public static Locale getLanguage(PortletSession session)
{
Locale locale = (Locale)session.getAttribute(LOCALE);
return locale != null ? locale : Locale.getDefault();
if (locale == null)
{
// get from web-client config - the first item in the configured list of languages
WebApplicationContext ctx = (WebApplicationContext)session.getPortletContext().getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
Config config = ((ConfigService)ctx.getBean(Application.BEAN_CONFIG_SERVICE)).getConfig("Languages");
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
LanguagesConfigElement.CONFIG_ELEMENT_ID);
List<String> languages = langConfig.getLanguages();
if (languages != null && languages.size() != 0)
{
locale = I18NUtil.parseLocale(languages.get(0));
}
else
{
// failing that, use the server default locale
locale = Locale.getDefault();
}
// save in user session
session.setAttribute(LOCALE, locale);
}
return locale;
}
/**

View File

@@ -27,6 +27,7 @@ package org.alfresco.web.bean;
import java.io.IOException;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Map;
import javax.faces.application.FacesMessage;
@@ -374,6 +375,7 @@ public class LoginBean implements Serializable
// need to capture this value before invalidating the session
boolean externalAuth = isAlfrescoAuth();
Locale language = Application.getLanguage(context);
// Invalidate Session for this user.
if (Application.inPortalServer() == false)
@@ -407,12 +409,8 @@ public class LoginBean implements Serializable
Map session = context.getExternalContext().getSessionMap();
session.put(AuthenticationHelper.SESSION_INVALIDATED, true);
// set language to last used
String language = preferences.getLanguage();
if (language != null && language.length() != 0)
{
Application.setLanguage(context, language);
}
// set language to last used on the login page
Application.setLanguage(context, language.toString());
return externalAuth ? "logout" : "relogin";
}

View File

@@ -25,6 +25,7 @@
package org.alfresco.web.bean.repository;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import org.alfresco.web.app.Application;
@@ -57,15 +58,16 @@ public final class PreferencesService
public static Preferences getPreferences(FacesContext fc)
{
User user = Application.getCurrentUser(fc);
return getPreferences(user);
return user != null ? user.getPreferences(fc) : null;
}
/**
* @param user User instance
* @return The Preferences for the current User instance.
*/
public static Preferences getPreferences(User user)
public static Preferences getPreferences(HttpSession session)
{
return user.getPreferences();
User user = Application.getCurrentUser(session);
return user != null ? user.getPreferences(session.getServletContext()) : null;
}
}

View File

@@ -29,7 +29,10 @@ import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.configuration.ConfigurableService;
@@ -40,7 +43,9 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.jsf.FacesContextUtils;
/**
* Bean that represents the currently logged in user
@@ -180,65 +185,90 @@ public final class User implements Serializable
/**
* @return The Preferences for the User
*/
Preferences getPreferences()
Preferences getPreferences(FacesContext fc)
{
if (this.preferences == null)
{
this.preferences = new Preferences(getUserPreferencesRef());
this.preferences = new Preferences(getUserPreferencesRef(
FacesContextUtils.getRequiredWebApplicationContext(fc)));
}
return this.preferences;
}
/**
* @return The Preferences for the User
*/
Preferences getPreferences(ServletContext sc)
{
if (this.preferences == null)
{
this.preferences = new Preferences(getUserPreferencesRef(
WebApplicationContextUtils.getRequiredWebApplicationContext(sc)));
}
return this.preferences;
}
/**
* Get or create the node used to store user preferences.
* Utilises the 'configurable' aspect on the Person linked to this user.
*/
synchronized NodeRef getUserPreferencesRef()
synchronized NodeRef getUserPreferencesRef(WebApplicationContext context)
{
FacesContext fc = FacesContext.getCurrentInstance();
ServiceRegistry registry = Repository.getServiceRegistry(fc);
ServiceRegistry registry = (ServiceRegistry)context.getBean("ServiceRegistry");
NodeService nodeService = registry.getNodeService();
SearchService searchService = registry.getSearchService();
NamespaceService namespaceService = registry.getNamespaceService();
ConfigurableService configurableService = Repository.getConfigurableService(fc);
ConfigurableService configurableService = (ConfigurableService)context.getBean("ConfigurableService");
UserTransaction txn = registry.getTransactionService().getUserTransaction();
NodeRef person = getPerson();
if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false)
NodeRef prefRef = null;
try
{
// create the configuration folder for this Person node
configurableService.makeConfigurable(person);
txn.begin();
NodeRef person = getPerson();
if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false)
{
// create the configuration folder for this Person node
configurableService.makeConfigurable(person);
}
// target of the assoc is the configurations folder ref
NodeRef configRef = configurableService.getConfigurationFolder(person);
if (configRef == null)
{
throw new IllegalStateException("Unable to find associated 'configurations' folder for node: " + person);
}
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
List<NodeRef> nodes = searchService.selectNodes(
configRef,
xpath,
null,
namespaceService,
false);
if (nodes.size() == 1)
{
prefRef = nodes.get(0);
}
else
{
// create the preferences Node for this user
ChildAssociationRef childRef = nodeService.createNode(
configRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"),
ContentModel.TYPE_CMOBJECT);
prefRef = childRef.getChildRef();
}
txn.commit();
}
// target of the assoc is the configurations folder ref
NodeRef configRef = configurableService.getConfigurationFolder(person);
if (configRef == null)
catch (Throwable err)
{
throw new IllegalStateException("Unable to find associated 'configurations' folder for node: " + person);
}
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
List<NodeRef> nodes = searchService.selectNodes(
configRef,
xpath,
null,
namespaceService,
false);
NodeRef prefRef;
if (nodes.size() == 1)
{
prefRef = nodes.get(0);
}
else
{
// create the preferences Node for this user
ChildAssociationRef childRef = nodeService.createNode(
configRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"),
ContentModel.TYPE_CMOBJECT);
prefRef = childRef.getChildRef();
try { txn.rollback(); } catch (Exception tex) {}
throw new AlfrescoRuntimeException("Error during getUserPreferencesRef(): " + err.getMessage(), err);
}
return prefRef;

View File

@@ -34,7 +34,6 @@ import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.config.Config;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
import org.alfresco.service.cmr.ml.MultilingualContentService;
@@ -58,8 +57,8 @@ public class UserPreferencesBean implements Serializable
private static final long serialVersionUID = -1262481849503163054L;
private static final String PREF_STARTLOCATION = "start-location";
private static final String PREF_CONTENTFILTERLANGUAGE = "content-filter-language";
public static final String PREF_INTERFACELANGUAGE = "interface-language";
/**
* Remplacement message for set the filter at 'all languages'.
@@ -67,9 +66,6 @@ public class UserPreferencesBean implements Serializable
*/
public static final String MSG_CONTENTALLLANGUAGES = "content_all_languages";
/** language locale selection */
private String language = null;
/** content language locale selection */
private String contentFilterLanguage = null;
@@ -87,48 +83,31 @@ public class UserPreferencesBean implements Serializable
*/
public SelectItem[] getLanguages()
{
// Get the item selection list
SelectItem[] items = getLanguageItems();
// Change the current language
if (this.language == null)
{
// first try to get the language that the current user is using
Locale lastLocale = Application.getLanguage(FacesContext.getCurrentInstance());
if (lastLocale != null)
{
this.language = lastLocale.toString();
}
// else we default to the first item in the list
else if (items.length > 0)
{
this.language = (String) items[0].getValue();
}
else
{
throw new AlfrescoRuntimeException("The language list is empty");
}
}
return items;
// Get the item selection list for the list of languages
return getLanguageItems();
}
/**
* @return Returns the language selection.
* @return Returns the language selection for the current user session.
*/
public String getLanguage()
{
return this.language;
return Application.getLanguage(FacesContext.getCurrentInstance()).toString();
}
/**
* @param language The language selection to set.
*/
public void setLanguage(String language)
{
this.language = language;
// set the language for the current session
Application.setLanguage(FacesContext.getCurrentInstance(), language);
// Set the current locale in the server
I18NUtil.setLocale(I18NUtil.parseLocale(language));
// save user preference
if (Application.getCurrentUser(FacesContext.getCurrentInstance()) != null)
{
PreferencesService.getPreferences().setValue(PREF_INTERFACELANGUAGE, language);
}
}
/**

View File

@@ -32,6 +32,8 @@ import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import org.alfresco.web.ui.common.Utils;
/**
* JSF component that renders an AJAX based tree for browsing the
* repository.
@@ -405,7 +407,7 @@ public class UITree extends UIComponentBase
xml.append("<node ref=\"");
xml.append(this.nodeRef);
xml.append("\" name=\"");
xml.append(this.name);
xml.append(Utils.encode(this.name));
xml.append("\" icon=\"");
xml.append(this.icon);
xml.append("\"/>");

View File

@@ -96,14 +96,16 @@ else
PersonService personService = (PersonService)context.getBean("personService");
NodeRef guestRef = personService.getPerson(PermissionService.GUEST_AUTHORITY);
user = new User(authService.getCurrentUserName(), authService.getCurrentTicket(), guestRef);
session.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user);
// ensure construction of the FacesContext before attemping a service call
FacesContext fc = FacesHelper.getFacesContext(request, response, application);
String preference = (String)PreferencesService.getPreferences(user).getValue("start-location");
String preference = (String)PreferencesService.getPreferences(session).getValue("start-location");
if (preference != null)
{
location = preference;
}
session.removeAttribute(AuthenticationHelper.AUTHENTICATION_USER);
tx.commit();
}