Merged V3.0 to HEAD

12795: ALFCOM-2419: ResourceBundleWrapper is no longer (de)serializable after changes merged from 2.1-A rev 8323
   12826: Fix for ETHREEOH-37 and ETHREEOH-176.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12828 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2009-01-16 14:20:15 +00:00
parent 10a62367d6
commit f70b674593
9 changed files with 173 additions and 137 deletions

View File

@@ -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);
}

View File

@@ -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;
/**
@@ -59,20 +58,147 @@ public final class ResourceBundleWrapper extends ResourceBundle implements Seria
/** List of custom bundle names */
private static List<String> addedBundleNames = new ArrayList<String>(10);
/** Serializable details of the resource bundles being wrapped */
private Locale locale;
private String bundleName;
/** List of delegate resource bundles */
transient private List<ResourceBundle> 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<ResourceBundle> 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<ResourceBundle> list of delegate resource bundles
*/
private List<ResourceBundle> getDelegates()
{
if (this.delegates == null)
{
this.delegates = new ArrayList<ResourceBundle>(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<String> getKeys()
{
if (this.delegates.size() == 1)
if (getDelegates().size() == 1)
{
return this.delegates.get(0).getKeys();
return getDelegates().get(0).getKeys();
}
else
{
Vector<String> allKeys = new Vector<String>(100, 2);
for (ResourceBundle delegate : this.delegates)
for (ResourceBundle delegate : getDelegates())
{
Enumeration<String> 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<ResourceBundle> bundles = new ArrayList<ResourceBundle>(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);
}
/**

View File

@@ -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<String> 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<String> 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<String> keys2 = after.getKeys();
assertTrue(containsValue(keys2, KEY_1));
assertTrue(containsValue(keys2, KEY_2));

View File

@@ -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)

View File

@@ -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();

View File

@@ -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<String, Object>(getServiceRegistry().getNamespaceService(), this);
this.properties = new QNameNodeMap<String, Object>(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<AssociationRef> 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<ChildAssociationRef> assocs = getServiceRegistry().getNodeService().getChildAssocs(this.nodeRef);
@@ -519,4 +521,9 @@ public class Node implements Serializable
}
return this.services;
}
public NamespacePrefixResolver getNamespacePrefixResolver()
{
return getServiceRegistry().getNamespaceService();
}
}

View File

@@ -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<K, V> extends QNameMap implements Map, Cloneable, Serializable
{
private static final long serialVersionUID = -1760755862411509263L;
private static final long serialVersionUID = -1760755862411509262L;
private Node parent = null;
private Map<String, NodePropertyResolver> resolvers = new HashMap<String, NodePropertyResolver>(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<K, V> extends QNameMap implements Map, Cloneable
this.parent = parent;
}
/**
*
* Serialization constructor
*/
protected QNameNodeMap()
{
@@ -141,7 +141,7 @@ public final class QNameNodeMap<K, V> 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)
{

View File

@@ -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)
{

View File

@@ -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;