mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fixes bugs uncovered by JDK 7 upgrade
- nodeService's interceptors depended on nodeService, resulting in some 'interesting' interceptor ordering in the chain (3 * the normal number in a random order). Now we use a lazy interceptor to break the cycle. - When the Content Language was en_GB and an MLText property contained {en_US, en_GB} it would return the en_US one, not taking country codes into account when available git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@41904 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -32,6 +32,22 @@
|
||||
</bean>
|
||||
|
||||
<bean id="nodeService" class="org.springframework.aop.framework.ProxyFactoryBean" >
|
||||
<!-- Lazy init to avoid circular dependencies -->
|
||||
<property name="targetSource">
|
||||
<bean class="org.alfresco.config.NonBlockingLazyInitTargetSource">
|
||||
<property name="targetBeanName">
|
||||
<idref bean="_nodeService" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="proxyInterfaces">
|
||||
<list>
|
||||
<value>org.alfresco.service.cmr.repository.NodeService</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="_nodeService" class="org.springframework.aop.framework.ProxyFactoryBean" >
|
||||
<property name="targetName">
|
||||
<value>mlAwareNodeService</value>
|
||||
</property>
|
||||
|
@@ -66,14 +66,9 @@
|
||||
<value>org.alfresco.service.cmr.repository.NodeService</value>
|
||||
</list>
|
||||
</property>
|
||||
<!-- Lazy init to avoid circular dependencies -->
|
||||
<property name="targetSource">
|
||||
<bean class="org.alfresco.config.NonBlockingLazyInitTargetSource">
|
||||
<property name="targetBeanName">
|
||||
<idref bean="nodeService" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="target">
|
||||
<ref bean="nodeService"/>
|
||||
</property>
|
||||
<property name="interceptorNames">
|
||||
<list>
|
||||
<idref local="NodeService_transaction"/>
|
||||
|
@@ -28,6 +28,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
@@ -163,7 +164,7 @@ public class MLPropertyInterceptor implements MethodInterceptor
|
||||
|
||||
// What locale must be used for filtering - ALF-3756 fix, ignore the country and variant
|
||||
Serializable value = (Serializable) invocation.proceed();
|
||||
ret = convertOutboundProperty(contentLangLocale, nodeRef, pivotNodeRef, propertyQName, value);
|
||||
ret = convertOutboundProperty(nodeRef, pivotNodeRef, propertyQName, value);
|
||||
}
|
||||
else if (methodName.equals("getProperties"))
|
||||
{
|
||||
@@ -179,7 +180,7 @@ public class MLPropertyInterceptor implements MethodInterceptor
|
||||
{
|
||||
QName propertyQName = entry.getKey();
|
||||
Serializable value = entry.getValue();
|
||||
Serializable convertedValue = convertOutboundProperty(contentLangLocale, nodeRef, pivotNodeRef, propertyQName, value);
|
||||
Serializable convertedValue = convertOutboundProperty(nodeRef, pivotNodeRef, propertyQName, value);
|
||||
// Add it to the return map
|
||||
convertedProperties.put(propertyQName, convertedValue);
|
||||
}
|
||||
@@ -334,7 +335,6 @@ public class MLPropertyInterceptor implements MethodInterceptor
|
||||
* Ensure that content is spoofed for empty translations.
|
||||
*/
|
||||
private Serializable convertOutboundProperty(
|
||||
Locale contentLocale,
|
||||
NodeRef nodeRef,
|
||||
NodeRef pivotNodeRef,
|
||||
QName propertyQName,
|
||||
@@ -349,13 +349,13 @@ public class MLPropertyInterceptor implements MethodInterceptor
|
||||
{
|
||||
// It is MLText
|
||||
MLText mlText = (MLText) outboundValue;
|
||||
ret = mlText.getClosestValue(contentLocale);
|
||||
ret = getClosestValue(mlText);
|
||||
}
|
||||
else if(isCollectionOfMLText(outboundValue))
|
||||
{
|
||||
Collection<?> col = (Collection<?>)outboundValue;
|
||||
ArrayList<String> answer = new ArrayList<String>(col.size());
|
||||
Locale closestLocale = getClosestLocale(col, contentLocale);
|
||||
Locale closestLocale = getClosestLocale(col);
|
||||
for(Object o : col)
|
||||
{
|
||||
MLText mlText = (MLText) o;
|
||||
@@ -412,7 +412,32 @@ public class MLPropertyInterceptor implements MethodInterceptor
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Locale getClosestLocale(Collection<?> collection, Locale locale)
|
||||
private Serializable getClosestValue(MLText mlText)
|
||||
{
|
||||
Set<Locale> locales = mlText.getLocales();
|
||||
Locale contentLocale = I18NUtil.getContentLocale();
|
||||
Locale locale = I18NUtil.getNearestLocale(contentLocale, locales);
|
||||
if (locale != null)
|
||||
{
|
||||
return mlText.getValue(locale);
|
||||
}
|
||||
|
||||
// If the content locale is too specific, try relaxing it to just language
|
||||
Locale contentLocaleLang = I18NUtil.getContentLocaleLang();
|
||||
if (!contentLocaleLang.equals(locale))
|
||||
{
|
||||
locale = I18NUtil.getNearestLocale(contentLocaleLang, locales);
|
||||
if (locale != null)
|
||||
{
|
||||
return mlText.getValue(locale);
|
||||
}
|
||||
}
|
||||
|
||||
// Just return the default translation
|
||||
return mlText.getDefaultValue();
|
||||
}
|
||||
|
||||
public Locale getClosestLocale(Collection<?> collection)
|
||||
{
|
||||
if (collection.size() == 0)
|
||||
{
|
||||
@@ -425,17 +450,24 @@ public class MLPropertyInterceptor implements MethodInterceptor
|
||||
MLText mlText = (MLText)o;
|
||||
locales.addAll(mlText.keySet());
|
||||
}
|
||||
// Get a match
|
||||
// Try the content locale
|
||||
Locale locale = I18NUtil.getContentLocale();
|
||||
Locale match = I18NUtil.getNearestLocale(locale, locales);
|
||||
if (match == null)
|
||||
{
|
||||
// No close matches for the locale - go for the default locale
|
||||
locale = I18NUtil.getLocale();
|
||||
// Try just the content locale language
|
||||
locale = I18NUtil.getContentLocaleLang();
|
||||
match = I18NUtil.getNearestLocale(locale, locales);
|
||||
if (match == null)
|
||||
{
|
||||
// just get any locale
|
||||
match = I18NUtil.getNearestLocale(null, locales);
|
||||
// No close matches for the locale - go for the default locale
|
||||
locale = I18NUtil.getLocale();
|
||||
match = I18NUtil.getNearestLocale(locale, locales);
|
||||
if (match == null)
|
||||
{
|
||||
// just get any locale
|
||||
match = I18NUtil.getNearestLocale(null, locales);
|
||||
}
|
||||
}
|
||||
}
|
||||
return match;
|
||||
|
Reference in New Issue
Block a user