Plugged in the correct mlTranslationInterceptor for FileFolderService and removed the NodeService interceptor.

Removed some unecessary interceptor work.
Fixed content filtering to default to the pivot translation if there is no translation for a required language.
Fixed content filtering when switching back to ALL LANGUAGES.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5802 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-05-29 15:55:28 +00:00
parent 7fbc59a0a9
commit 7b5349005c
12 changed files with 129 additions and 327 deletions

View File

@@ -30,7 +30,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -123,7 +122,6 @@ public class FileFolderServiceImpl implements FileFolderService
private CopyService copyService;
private SearchService searchService;
private ContentService contentService;
private MultilingualContentService multilingualContentService;
private MimetypeService mimetypeService;
// TODO: Replace this with a more formal means of identifying "system" folders (i.e. aspect or UUID)
@@ -167,11 +165,6 @@ public class FileFolderServiceImpl implements FileFolderService
this.contentService = contentService;
}
public void setMultilingualContentService(MultilingualContentService multilingualContentService)
{
this.multilingualContentService = multilingualContentService;
}
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
@@ -217,40 +210,15 @@ public class FileFolderServiceImpl implements FileFolderService
*/
private FileInfo toFileInfo(NodeRef nodeRef, boolean addTranslations) throws InvalidTypeException
{
// get the file attributes
// Get the file attributes
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
// is it a folder
// Is it a folder
QName typeQName = nodeService.getType(nodeRef);
boolean isFolder = isFolder(typeQName);
Map<Locale, FileInfo> translations = null;
if (!isFolder && addTranslations)
{
// Get any translations
translations = new HashMap<Locale, FileInfo>(13);
// Check for the ML aspect
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
{
// Get all the translations
Map<Locale, NodeRef> translationsToConvert = multilingualContentService.getTranslations(nodeRef);
for (Map.Entry<Locale, NodeRef> entry : translationsToConvert.entrySet())
{
Locale locale = entry.getKey();
NodeRef nodeRefToConvert = entry.getValue();
FileInfo convertedFileInfo = toFileInfo(nodeRefToConvert, false);
// Add to map
translations.put(locale, convertedFileInfo);
}
}
}
else
{
translations = Collections.<Locale, FileInfo>emptyMap();
}
// construct the file info and add to the results
FileInfo fileInfo = new FileInfoImpl(nodeRef, isFolder, properties, translations);
// done
// Construct the file info and add to the results
FileInfo fileInfo = new FileInfoImpl(nodeRef, isFolder, properties);
// Done
return fileInfo;
}

View File

@@ -25,9 +25,7 @@
package org.alfresco.repo.model.filefolder;
import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import org.alfresco.model.ContentModel;
@@ -46,7 +44,6 @@ public class FileInfoImpl implements FileInfo
{
private NodeRef nodeRef;
private NodeRef linkNodeRef;
private Map<Locale, FileInfo> translations;
private boolean isFolder;
private boolean isLink;
private Map<QName, Serializable> properties;
@@ -54,33 +51,14 @@ public class FileInfoImpl implements FileInfo
/**
* Package-level constructor
*/
/* package */ FileInfoImpl(NodeRef nodeRef, boolean isFolder, Map<QName, Serializable> properties)
{
this(nodeRef, isFolder, properties, Collections.<Locale, FileInfo>emptyMap());
}
/**
* Package-level constructor
*
* @param translations a map of translations including this instance. It may be null.
*/
/* package */ FileInfoImpl(
NodeRef nodeRef,
boolean isFolder,
Map<QName, Serializable> properties,
Map<Locale, FileInfo> translations)
Map<QName, Serializable> properties)
{
this.nodeRef = nodeRef;
this.isFolder = isFolder;
this.properties = properties;
if (translations == null || isFolder)
{
this.translations = Collections.<Locale, FileInfo>emptyMap();
}
else
{
this.translations = translations;
}
// Check if this is a link node
if ( properties.containsKey( ContentModel.PROP_LINK_DESTINATION))
@@ -97,7 +75,15 @@ public class FileInfoImpl implements FileInfo
@Override
public boolean equals(Object obj)
{
if (obj == null || this.getClass().isInstance(obj))
if (obj == null)
{
return false;
}
else if (this == obj)
{
return true;
}
else if (obj instanceof FileInfoImpl == false)
{
return false;
}
@@ -130,8 +116,6 @@ public class FileInfoImpl implements FileInfo
sb.append(linkNodeRef);
}
sb.append(", translations=").append(translations.size());
sb.append("]");
return sb.toString();
}
@@ -156,11 +140,6 @@ public class FileInfoImpl implements FileInfo
return linkNodeRef;
}
public Map<Locale, FileInfo> getTranslations()
{
return translations;
}
public String getName()
{
return (String) properties.get(ContentModel.PROP_NAME);

View File

@@ -97,6 +97,7 @@ public class MLTranslationInterceptor implements MethodInterceptor
private NodeService nodeService;
private MultilingualContentService multilingualContentService;
private FileFolderService fileFolderService;
/**
* Constructor.
@@ -115,6 +116,11 @@ public class MLTranslationInterceptor implements MethodInterceptor
this.multilingualContentService = multilingualContentService;
}
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
/**
* Converts the node referenice where an alternative translation should be used.
*
@@ -133,13 +139,14 @@ public class MLTranslationInterceptor implements MethodInterceptor
{
return nodeRef;
}
// Find the translation
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(nodeRef);
Locale filterLocale = I18NUtil.getContentLocaleOrNull();
Set<Locale> possibleLocales = translations.keySet();
Locale localeToUse = I18NUtil.getNearestLocale(filterLocale, possibleLocales);
// Select the node
NodeRef translatedNodeRef = translations.get(localeToUse);
if (filterLocale == null)
{
// We aren't doing any filtering
return nodeRef;
}
// Find the best translation. This won't return null.
NodeRef translatedNodeRef = multilingualContentService.getTranslationForLocale(nodeRef, filterLocale);
// Done
if (logger.isDebugEnabled())
{
@@ -152,7 +159,7 @@ public class MLTranslationInterceptor implements MethodInterceptor
logger.debug("NodeRef substitution: " + nodeRef + " (no change)");
}
}
return nodeRef;
return translatedNodeRef;
}
/**
@@ -160,8 +167,6 @@ public class MLTranslationInterceptor implements MethodInterceptor
*
* @param fileInfo the basic file or folder info
* @return Returns a replacement if required
*
* @see FileInfo#getTranslations()
*/
private FileInfo getTranslatedFileInfo(FileInfo fileInfo)
{
@@ -175,28 +180,20 @@ public class MLTranslationInterceptor implements MethodInterceptor
{
return fileInfo;
}
// Ignore files without translations
Map<Locale, FileInfo> translations = fileInfo.getTranslations();
if (translations.size() == 0)
NodeRef nodeRef = fileInfo.getNodeRef();
// Get the best translation for the node
NodeRef translatedNodeRef = getTranslatedNodeRef(nodeRef);
// Convert to FileInfo, if required
FileInfo translatedFileInfo = null;
if (nodeRef.equals(translatedNodeRef))
{
return fileInfo;
// No need to do any more work
translatedFileInfo = fileInfo;
}
// Get the locale to use
Set<Locale> possibleLocales = translations.keySet();
Locale filterLocale = I18NUtil.getContentLocaleOrNull();
Locale localeToUse = I18NUtil.getNearestLocale(filterLocale, possibleLocales);
FileInfo translatedFileInfo = translations.get(localeToUse);
// Done
if (logger.isDebugEnabled())
else
{
if (fileInfo.equals(translatedFileInfo))
{
logger.debug("FileInfo substitution: " + fileInfo + " --> " + translatedFileInfo);
}
else
{
logger.debug("FileInfo substitution: " + fileInfo + " (no change)");
}
// Get the FileInfo
translatedFileInfo = fileFolderService.getFileInfo(translatedNodeRef);
}
return translatedFileInfo;
}
@@ -207,7 +204,12 @@ public class MLTranslationInterceptor implements MethodInterceptor
Object ret = null;
String methodName = invocation.getMethod().getName();
if (METHOD_NAMES_LIST.contains(methodName))
if (I18NUtil.getContentLocaleOrNull() == null)
{
// This can shortcut anything as there is no filtering going on
return invocation.proceed();
}
else if (METHOD_NAMES_LIST.contains(methodName))
{
List<FileInfo> fileInfos = (List<FileInfo>) invocation.proceed();
// Compile a set to ensure we don't get duplicates
@@ -223,13 +225,14 @@ public class MLTranslationInterceptor implements MethodInterceptor
Set<FileInfo> alreadyPresent = new HashSet<FileInfo>(fileInfos.size() * 2 + 1);
for (FileInfo info : fileInfos)
{
if (alreadyPresent.contains(info))
FileInfo translatedFileInfo = translatedFileInfos.get(info);
if (alreadyPresent.contains(translatedFileInfo))
{
// We've done this one
continue;
}
alreadyPresent.add(info);
orderedResults.add(translatedFileInfos.get(info));
alreadyPresent.add(translatedFileInfo);
orderedResults.add(translatedFileInfo);
}
ret = orderedResults;
}