diff --git a/source/java/org/alfresco/web/app/Application.java b/source/java/org/alfresco/web/app/Application.java index a532c682a2..60688288de 100644 --- a/source/java/org/alfresco/web/app/Application.java +++ b/source/java/org/alfresco/web/app/Application.java @@ -49,12 +49,12 @@ 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.users.UserPreferencesBean; import org.alfresco.web.bean.wizard.WizardManager; import org.alfresco.web.config.ClientConfigElement; import org.alfresco.web.config.LanguagesConfigElement; @@ -578,9 +578,6 @@ 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 @@ -801,7 +798,7 @@ public class Application { locale = Locale.getDefault(); } - bundle = ResourceBundleWrapper.getResourceBundle(session.getServletContext(), MESSAGE_BUNDLE, locale); + bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale); session.setAttribute(MESSAGE_BUNDLE, bundle); } @@ -832,7 +829,7 @@ public class Application { locale = Locale.getDefault(); } - bundle = ResourceBundleWrapper.getResourceBundle(FacesContextUtils.getRequiredWebApplicationContext(context).getServletContext(), MESSAGE_BUNDLE, locale); + bundle = ResourceBundleWrapper.getResourceBundle(MESSAGE_BUNDLE, locale); session.put(MESSAGE_BUNDLE, bundle); } diff --git a/source/java/org/alfresco/web/app/ResourceBundleWrapper.java b/source/java/org/alfresco/web/app/ResourceBundleWrapper.java index 37b9bf5a16..45b61c3020 100644 --- a/source/java/org/alfresco/web/app/ResourceBundleWrapper.java +++ b/source/java/org/alfresco/web/app/ResourceBundleWrapper.java @@ -33,15 +33,14 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Vector; -import javax.servlet.ServletContext; +import javax.faces.context.FacesContext; -import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.i18n.MessageService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.web.bean.repository.Repository; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.web.context.support.WebApplicationContextUtils; +import org.springframework.web.jsf.FacesContextUtils; /** @@ -58,21 +57,148 @@ public final class ResourceBundleWrapper extends ResourceBundle implements Seria /** List of custom bundle names */ private static List addedBundleNames = new ArrayList(10); + + /** Serializable details of the resource bundles being wrapped */ + private Locale locale; + private String bundleName; /** List of delegate resource bundles */ transient private List delegates; + /** Message service */ + transient private MessageService messageService; + public static final String BEAN_RESOURCE_MESSAGE_SERVICE = "messageService"; public static final String PATH = "app:company_home/app:dictionary/app:webclient_extension"; /** * Constructor - * - * @param bundles the resource bundles including the default, custom and any added + * + * @param locale the locale + * @param bundleName the bundle name */ - private ResourceBundleWrapper(List bundles) + private ResourceBundleWrapper(Locale locale, String bundleName) { - this.delegates = bundles; + this.locale = locale; + this.bundleName = bundleName; + } + + /** + * Get the message service + * + * @return MessageService message service + */ + private MessageService getMessageService() + { + if (this.messageService == null && FacesContext.getCurrentInstance() != null) + { + this.messageService = (MessageService)FacesContextUtils.getRequiredWebApplicationContext( + FacesContext.getCurrentInstance()).getBean(BEAN_RESOURCE_MESSAGE_SERVICE); + } + return this.messageService; + } + + /** + * Get a list of the delegate resource bundles + * + * @return List list of delegate resource bundles + */ + private List getDelegates() + { + if (this.delegates == null) + { + this.delegates = new ArrayList(ResourceBundleWrapper.addedBundleNames.size() + 2); + + // Add the bundle + this.delegates.add(getResourceBundle(locale, this.bundleName)); + + // first try in the repo otherwise try the classpath + ResourceBundle customBundle = null; + + if (getMessageService() != null) + { + StoreRef storeRef = null; + String path = null; + + try + { + String customName = null; + int idx = this.bundleName.lastIndexOf("."); + if (idx != -1) + { + customName = this.bundleName.substring(idx+1, this.bundleName.length()); + } + else + { + customName = this.bundleName; + } + + storeRef = Repository.getStoreRef(); + + // TODO - make path configurable in one place ... + // Note: path here is XPath for selectNodes query + path = PATH + "/cm:" + customName; + customBundle = getMessageService().getRepoResourceBundle(Repository.getStoreRef(), path, locale); + } + catch (Throwable t) + { + // for now ... ignore the error, cannot be found or read from repo + logger.debug("Custom Web Client properties not found: " + storeRef + path); + } + } + + if (customBundle == null) + { + // also look up the custom version of the bundle in the extension package + String customName = determineCustomBundleName(this.bundleName); + customBundle = getResourceBundle(locale, customName); + } + + // Add the custom bundle to the list + if (customBundle != null) + { + this.delegates.add(customBundle); + } + + // Add the added bundles + for (String addedBundleName : ResourceBundleWrapper.addedBundleNames) + { + this.delegates.add(getResourceBundle(locale, addedBundleName)); + } + } + return this.delegates; + } + + /** + * Given a local and name, gets the resource bundle + * + * @param locale locale + * @param bundleName bundle name + * @return ResourceBundle resource bundle + */ + private ResourceBundle getResourceBundle(Locale locale, String bundleName) + { + ResourceBundle bundle = null; + try + { + // Load the bundle + bundle = ResourceBundle.getBundle(bundleName, locale); + this.delegates.add(bundle); + + if (logger.isDebugEnabled()) + { + logger.debug("Located and loaded bundle " + bundleName); + } + } + catch (MissingResourceException mre) + { + // ignore the error, just log some debug info + if (logger.isDebugEnabled()) + { + logger.debug("Unable to load bundle " + bundleName); + } + } + return bundle; } /** @@ -80,14 +206,14 @@ public final class ResourceBundleWrapper extends ResourceBundle implements Seria */ public Enumeration getKeys() { - if (this.delegates.size() == 1) + if (getDelegates().size() == 1) { - return this.delegates.get(0).getKeys(); + return getDelegates().get(0).getKeys(); } else { Vector allKeys = new Vector(100, 2); - for (ResourceBundle delegate : this.delegates) + for (ResourceBundle delegate : getDelegates()) { Enumeration keys = delegate.getKeys(); while(keys.hasMoreElements() == true) @@ -107,7 +233,7 @@ public final class ResourceBundleWrapper extends ResourceBundle implements Seria { Object result = null; - for (ResourceBundle delegate : this.delegates) + for (ResourceBundle delegate : getDelegates()) { try { @@ -147,107 +273,9 @@ public final class ResourceBundleWrapper extends ResourceBundle implements Seria * * @return Wrapped ResourceBundle instance for specified locale */ - public static ResourceBundle getResourceBundle(ServletContext servletContext, String name, Locale locale) + public static ResourceBundle getResourceBundle(String name, Locale locale) { - List bundles = new ArrayList(ResourceBundleWrapper.addedBundleNames.size() + 2); - - // Load the default bundle - ResourceBundle bundle = ResourceBundle.getBundle(name, locale); - if (bundle == null) - { - throw new AlfrescoRuntimeException("Unable to load Alfresco messages bundle: " + name); - } - bundles.add(bundle); - - // also look up the custom version of the bundle in the extension package - ResourceBundle customBundle = null; - - if (servletContext != null) - { - MessageService messageService = (MessageService)WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext).getBean(BEAN_RESOURCE_MESSAGE_SERVICE); - - // first try in the repo otherwise try the classpath - StoreRef storeRef = null; - String path = null; - - try - { - String customName = null; - int idx = name.lastIndexOf("."); - if (idx != -1) - { - customName = name.substring(idx+1, name.length()); - } - else - { - customName = name; - } - - storeRef = Repository.getStoreRef(); - - // TODO - make path configurable in one place ... - // Note: path here is XPath for selectNodes query - path = PATH + "/cm:" + customName; - customBundle = messageService.getRepoResourceBundle(Repository.getStoreRef(), path, locale); - } - catch (Throwable t) - { - // for now ... ignore the error, cannot be found or read from repo - logger.debug("Custom Web Client properties not found: " + storeRef + path); - } - } - - if (customBundle == null) - { - // also look up the custom version of the bundle in the extension package - String customName = determineCustomBundleName(name); - try - { - customBundle = ResourceBundle.getBundle(customName, locale); - - if (logger.isDebugEnabled()== true) - { - logger.debug("Located and loaded custom bundle: " + customName); - } - } - catch (MissingResourceException mre) - { - // ignore the error, just leave custom bundle as null - } - } - - // Add the custom bundle to the list - if (customBundle != null) - { - bundles.add(customBundle); - } - - // Add any additional bundles - for (String bundleName : ResourceBundleWrapper.addedBundleNames) - { - try - { - // Load the added bundle - ResourceBundle addedBundle = ResourceBundle.getBundle(bundleName, locale); - bundles.add(addedBundle); - - if (logger.isDebugEnabled()) - { - logger.debug("Located and loaded added bundle: " + bundleName); - } - } - catch (MissingResourceException mre) - { - // ignore the error, just log some debug info - if (logger.isDebugEnabled()) - { - logger.debug("Unable to load added bundle: " + bundleName); - } - } - } - - // apply our wrapper to catch MissingResourceException - return new ResourceBundleWrapper(bundles); + return new ResourceBundleWrapper(locale, name); } /** diff --git a/source/java/org/alfresco/web/app/ResourceBundleWrapperTest.java b/source/java/org/alfresco/web/app/ResourceBundleWrapperTest.java index acc5532218..c90f0f539a 100644 --- a/source/java/org/alfresco/web/app/ResourceBundleWrapperTest.java +++ b/source/java/org/alfresco/web/app/ResourceBundleWrapperTest.java @@ -30,7 +30,7 @@ public class ResourceBundleWrapperTest extends TestCase public void testAddingBundles() { // Check that the string's are not added to the bundle - ResourceBundle before = ResourceBundleWrapper.getResourceBundle(null, "alfresco.messages.webclient", Locale.US); + ResourceBundle before = ResourceBundleWrapper.getResourceBundle("alfresco.messages.webclient", Locale.US); Enumeration keys = before.getKeys(); assertFalse(containsValue(keys, KEY_1)); assertFalse(containsValue(keys, KEY_2)); @@ -51,7 +51,7 @@ public class ResourceBundleWrapperTest extends TestCase ResourceBundleWrapper.addResourceBundle(BUNDLE_NAME); // Check that the string's are now added to the bundle - ResourceBundle after = ResourceBundleWrapper.getResourceBundle(null, "alfresco.messages.webclient", Locale.US); + ResourceBundle after = ResourceBundleWrapper.getResourceBundle("alfresco.messages.webclient", Locale.US); Enumeration keys2 = after.getKeys(); assertTrue(containsValue(keys2, KEY_1)); assertEquals(after.getString(KEY_1), MSG_1); @@ -70,7 +70,7 @@ public class ResourceBundleWrapperTest extends TestCase bootstrap.setResourceBundles(bundles); // Check that the string's are now added to the bundle - ResourceBundle after = ResourceBundleWrapper.getResourceBundle(null, "alfresco.messages.webclient", Locale.US); + ResourceBundle after = ResourceBundleWrapper.getResourceBundle("alfresco.messages.webclient", Locale.US); Enumeration keys2 = after.getKeys(); assertTrue(containsValue(keys2, KEY_1)); assertTrue(containsValue(keys2, KEY_2)); diff --git a/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java b/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java index 46a6bd1d00..4a7a6be679 100644 --- a/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java +++ b/source/java/org/alfresco/web/app/servlet/AuthenticationHelper.java @@ -229,6 +229,7 @@ public final class AuthenticationHelper catch (AuthenticationException authErr) { // expired ticket + session.removeAttribute(AUTHENTICATION_USER); return AuthenticationStatus.Failure; } @@ -276,11 +277,11 @@ public final class AuthenticationHelper WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context); AuthenticationService auth = (AuthenticationService)wc.getBean(AUTHENTICATION_SERVICE); UserTransaction tx = null; + HttpSession session = httpRequest.getSession(); try { auth.validate(ticket); - HttpSession session = httpRequest.getSession(); User user = (User)session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER); if (user == null) { @@ -313,6 +314,7 @@ public final class AuthenticationHelper } catch (AuthenticationException authErr) { + session.removeAttribute(AUTHENTICATION_USER); return AuthenticationStatus.Failure; } catch (Throwable e) diff --git a/source/java/org/alfresco/web/bean/NavigationBean.java b/source/java/org/alfresco/web/bean/NavigationBean.java index d521ff8ebd..7852f0a33b 100644 --- a/source/java/org/alfresco/web/bean/NavigationBean.java +++ b/source/java/org/alfresco/web/bean/NavigationBean.java @@ -699,7 +699,7 @@ public class NavigationBean implements Serializable Path path = node.getNodePath(); // resolve CIFS network folder location for this node - FilesystemsConfigSection filesysConfig = (FilesystemsConfigSection) cifsServer.getConfiguration().getConfigSection(FilesystemsConfigSection.SectionName); + FilesystemsConfigSection filesysConfig = (FilesystemsConfigSection)getCifsServer().getConfiguration().getConfigSection(FilesystemsConfigSection.SectionName); DiskSharedDevice diskShare = null; SharedDeviceList shares = filesysConfig.getShares(); diff --git a/source/java/org/alfresco/web/bean/repository/Node.java b/source/java/org/alfresco/web/bean/repository/Node.java index 0500f282d0..674384bf4b 100644 --- a/source/java/org/alfresco/web/bean/repository/Node.java +++ b/source/java/org/alfresco/web/bean/repository/Node.java @@ -44,6 +44,8 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.namespace.NamespacePrefixResolver; +import org.alfresco.service.namespace.NamespacePrefixResolverProvider; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.web.app.Application; @@ -53,9 +55,9 @@ import org.alfresco.web.app.Application; * * @author gavinc */ -public class Node implements Serializable +public class Node implements Serializable, NamespacePrefixResolverProvider { - private static final long serialVersionUID = 3544390322739034169L; + private static final long serialVersionUID = 3544390322739034170L; protected NodeRef nodeRef; protected String name; @@ -94,7 +96,7 @@ public class Node implements Serializable this.nodeRef = nodeRef; this.id = nodeRef.getId(); - this.properties = new QNameNodeMap(getServiceRegistry().getNamespaceService(), this); + this.properties = new QNameNodeMap(this, this); } /** @@ -134,7 +136,7 @@ public class Node implements Serializable { if (this.assocsRetrieved == false) { - this.associations = new QNameNodeMap(getServiceRegistry().getNamespaceService(), this); + this.associations = new QNameNodeMap(this, this); List assocs = getServiceRegistry().getNodeService().getTargetAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL); @@ -196,7 +198,7 @@ public class Node implements Serializable { if (this.childAssocsRetrieved == false) { - this.childAssociations = new QNameNodeMap(getServiceRegistry().getNamespaceService(), this); + this.childAssociations = new QNameNodeMap(this, this); List assocs = getServiceRegistry().getNodeService().getChildAssocs(this.nodeRef); @@ -519,4 +521,9 @@ public class Node implements Serializable } return this.services; } + + public NamespacePrefixResolver getNamespacePrefixResolver() + { + return getServiceRegistry().getNamespaceService(); + } } diff --git a/source/java/org/alfresco/web/bean/repository/QNameNodeMap.java b/source/java/org/alfresco/web/bean/repository/QNameNodeMap.java index e8bf6e73f8..12cc23d169 100644 --- a/source/java/org/alfresco/web/bean/repository/QNameNodeMap.java +++ b/source/java/org/alfresco/web/bean/repository/QNameNodeMap.java @@ -28,7 +28,7 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import org.alfresco.service.namespace.NamespacePrefixResolver; +import org.alfresco.service.namespace.NamespacePrefixResolverProvider; import org.alfresco.service.namespace.QNameMap; /** @@ -38,19 +38,20 @@ import org.alfresco.service.namespace.QNameMap; */ public final class QNameNodeMap extends QNameMap implements Map, Cloneable, Serializable { + private static final long serialVersionUID = -1760755862411509263L; - private static final long serialVersionUID = -1760755862411509262L; private Node parent = null; private Map resolvers = new HashMap(8, 1.0f); + /** * Constructor * * @param parent Parent Node of the QNameNodeMap */ - public QNameNodeMap(NamespacePrefixResolver resolver, Node parent) + public QNameNodeMap(NamespacePrefixResolverProvider provider, Node parent) { - super(resolver); + super(provider); if (parent == null) { throw new IllegalArgumentException("Parent Node cannot be null!"); @@ -58,9 +59,8 @@ public final class QNameNodeMap extends QNameMap implements Map, Cloneable this.parent = parent; } - /** - * + * Serialization constructor */ protected QNameNodeMap() { @@ -141,7 +141,7 @@ public final class QNameNodeMap extends QNameMap implements Map, Cloneable @SuppressWarnings("unchecked") public Object clone() { - QNameNodeMap map = new QNameNodeMap(this.resolver, this.parent); + QNameNodeMap map = new QNameNodeMap(this.provider, this.parent); map.putAll(this); if (this.resolvers.size() != 0) { diff --git a/source/java/org/alfresco/web/bean/repository/TransientNode.java b/source/java/org/alfresco/web/bean/repository/TransientNode.java index 165569a3eb..23abab0b15 100644 --- a/source/java/org/alfresco/web/bean/repository/TransientNode.java +++ b/source/java/org/alfresco/web/bean/repository/TransientNode.java @@ -166,8 +166,8 @@ public class TransientNode extends Node DictionaryService ddService = this.getServiceRegistry().getDictionaryService(); // marshall the given properties and associations into the internal maps - this.associations = new QNameNodeMap(getServiceRegistry().getNamespaceService(), this); - this.childAssociations = new QNameNodeMap(getServiceRegistry().getNamespaceService(), this); + this.associations = new QNameNodeMap(this, this); + this.childAssociations = new QNameNodeMap(this, this); if (data != null) { diff --git a/source/java/org/alfresco/web/config/DialogsConfigElement.java b/source/java/org/alfresco/web/config/DialogsConfigElement.java index deffec3d6c..4ffd519e56 100644 --- a/source/java/org/alfresco/web/config/DialogsConfigElement.java +++ b/source/java/org/alfresco/web/config/DialogsConfigElement.java @@ -352,8 +352,10 @@ public class DialogsConfigElement extends ConfigElementAdapter * * @author gavinc */ - public static class DialogAttributes + public static class DialogAttributes implements Serializable { + private static final long serialVersionUID = -6897300549207773138L; + protected String name; protected String page; protected String managedBean;