Yannick Pignot (European Commission) multilingual services

- EditionService for versioning of groups of translations
 - Quite a bit of trimming of whitespace that I have no intention of undoing.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5927 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-13 01:13:25 +00:00
parent 9abfab20ab
commit 35c3659f14
27 changed files with 5891 additions and 4335 deletions

View File

@@ -15,11 +15,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.bean;
@@ -28,6 +28,8 @@ import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -45,6 +47,7 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransacti
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
import org.alfresco.service.cmr.ml.EditionService;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -62,54 +65,57 @@ import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
import org.alfresco.web.ui.common.component.UIActionLink;
/**
* Backing bean providing access to the details of a document
*
*
* @author gavinc
*/
public class DocumentDetailsBean extends BaseDetailsBean
{
private static final String OUTCOME_RETURN = "showDocDetails";
private static final String MSG_HAS_FOLLOWING_CATEGORIES = "has_following_categories";
private static final String MSG_NO_CATEGORIES_APPLIED = "no_categories_applied";
private static final String MSG_SUCCESS_UNLOCK = "success_unlock";
private static final String MSG_CURRENT = "current";
private static final String MSG_ERROR_ASPECT_INLINEEDITABLE = "error_aspect_inlineeditable";
private static final String MSG_ERROR_ASPECT_VERSIONING = "error_aspect_versioning";
private static final String MSG_ERROR_ASPECT_CLASSIFY = "error_aspect_classify";
private static final String MSG_ERROR_UPDATE_CATEGORY = "error_update_category";
private static final String ML_VERSION_PANEL_ID = "ml-versions-panel";
protected LockService lockService;
protected VersionService versionService;
protected CheckOutCheckInService cociService;
protected MultilingualContentService multilingualContentService;
protected ContentFilterLanguagesService contentFilterLanguagesService;
protected EditionService editionService;
private NodeRef addedCategory;
private List categories;
// ------------------------------------------------------------------------------
// Construction
// Construction
/**
* Default constructor
*/
public DocumentDetailsBean()
{
super();
// initial state of some panels that don't use the default
panels.put("version-history-panel", false);
panels.put("ml-info-panel", false);
panels.put("related-translation-panel", false);
}
// ------------------------------------------------------------------------------
// Bean property getters and setters
// Bean property getters and setters
/**
* Resets any state that may be held by this bean
*/
@@ -117,25 +123,25 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
// reset the workflow cache
this.workflowProperties = null;
// reset the category caches
this.categories = null;
this.addedCategory = null;
}
/**
* Returns the URL to download content for the current document
*
*
* @return Content url to download the current document
*/
public String getUrl()
{
return (String)getDocument().getProperties().get("url");
}
/**
* Returns the URL to the content for the current document
*
*
* @return Content url to the current document
*/
public String getBrowserUrl()
@@ -146,7 +152,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
/**
* Returns the download URL to the content for the current document
*
*
* @return Download url to the current document
*/
public String getDownloadUrl()
@@ -154,10 +160,10 @@ public class DocumentDetailsBean extends BaseDetailsBean
Node doc = getLinkResolvedNode();
return Utils.generateURL(FacesContext.getCurrentInstance(), doc, URLMode.HTTP_DOWNLOAD);
}
/**
* Resolve the actual document Node from any Link object that may be proxying it
*
*
* @return current document Node or document Node resolved from any Link object
*/
protected Node getLinkResolvedNode()
@@ -173,17 +179,17 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
return document;
}
/**
* Determines whether the current document is versionable
*
*
* @return true if the document has the versionable aspect
*/
public boolean isVersionable()
{
return getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE);
}
/**
* @return true if the current document has the 'inlineeditable' aspect applied
*/
@@ -191,7 +197,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
return getDocument().hasAspect(ApplicationModel.ASPECT_INLINEEDITABLE);
}
/**
* @return true if the current document has the 'inlineeditable' aspect applied
*/
@@ -199,21 +205,35 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
return getDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
}
/**
* Returns a list of objects representing the versions of the
* current document
*
* Save the state of the panel that was expanded/collapsed
*/
public void expandPanel(ActionEvent event)
{
super.expandPanel(event);
String id = event.getComponent().getId();
if(id.startsWith(ML_VERSION_PANEL_ID))
{
this.currentEditionCursorPosition = Integer.parseInt(id.substring("ml-versions-panel".length())) - 1;
}
}
/**
* Returns a list of objects representing the versions of the
* current document
*
* @return List of previous versions
*/
public List getVersionHistory()
{
List<MapNode> versions = new ArrayList<MapNode>();
if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE))
{
VersionHistory history = this.versionService.getVersionHistory(getDocument().getNodeRef());
if (history != null)
{
for (Version version : history.getAllVersions())
@@ -224,39 +244,208 @@ public class DocumentDetailsBean extends BaseDetailsBean
clientVersion.put("notes", version.getDescription());
clientVersion.put("author", version.getCreator());
clientVersion.put("versionDate", version.getCreatedDate());
clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(),
clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(),
clientVersion.getName()));
// add the client side version to the list
versions.add(clientVersion);
}
}
}
return versions;
}
/**
* Returns a list of objects representing the editions of the
* logical document
*
* The comparator to sort a version list according their version label ascending
*
* TODO add this code in the repository as Version Util class ?
*/
private Comparator versionComparator = new Comparator()
{
public int compare(Object o1, Object o2)
{
String label01 = ((Version) o1).getVersionLabel();
String label02 = ((Version) o2).getVersionLabel();
// sort the list ascending
return label02.compareTo(label01);
}
};
/** List of client light weight edition histories */
private List<SingleEditionBean> editionHistory = null;
/** For the client side iteration on the edition hitories list, it represents the index of the list */
private int currentEditionCursorPosition;
/**
* For the client side iteration on the edition hitories list, returns the number of editions.
*
* @return the number of edition of the current mlContainer
*/
public int getEditionSize()
{
// return the size of the list
return editionHistory.size();
}
/**
* Init the mlContainer histories and returns an empty list to fill a rich list value without content.
*
* @return an empty list
*/
public List getEmptyListAndInitEditions()
{
// this call ensures that the edition of the mlContainer must be
// re-initialized.
// remove each old mlContainer's translations of the panel list
List<String> panelsToRemove = new ArrayList<String>();
for(Map.Entry<String, Boolean> panel : panels.entrySet())
{
if(panel.getKey().startsWith(ML_VERSION_PANEL_ID))
{
//panels.remove(panel.getKey());
panelsToRemove.add(panel.getKey());
}
}
for(String panelId : panelsToRemove)
{
panels.remove(panelId);
}
// init the Edition histories
initEditionHistory();
currentEditionCursorPosition = -1;
return new ArrayList(0);
}
/**
* For the client side iteration on the edition hitories list,
* return the next edition history.
*
* @return a light weight representation of an edition history
*/
public SingleEditionBean getNextSingleEditionBean()
{
currentEditionCursorPosition++;
return getCurrentSingleEditionBean();
}
/**
* For the client side iteration on the edition hitories list,
* return the current edition history.
*
* @return a light weight representation of an edition history
*/
public SingleEditionBean getCurrentSingleEditionBean()
{
return editionHistory.get(currentEditionCursorPosition);
}
/**
* Constructs a list of objects representing the editions of the
* logical document
*
* @return List of editions
*/
public List getEditionHistory()
@SuppressWarnings("unchecked")
private List<SingleEditionBean> initEditionHistory()
{
List<MapNode> editions = new ArrayList<MapNode>();
if (getDocument().getType().equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
// get the mlContainer
NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
// get all editions and sort them ascending according their version label
List<Version> orderedEditionList = new ArrayList<Version>(editionService.getEditions(mlContainer).getAllVersions());
Collections.sort(orderedEditionList, versionComparator);
// the list of Single Edition Bean to return
editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
boolean firstEdition = true;
// for each edition, init a SingleEditionBean
for (Version edition : orderedEditionList)
{
SingleEditionBean editionBean = new SingleEditionBean();
MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
String editionLabel = edition.getVersionLabel();
if (firstEdition)
{
editionLabel += " (" + Application.getMessage(FacesContext.getCurrentInstance(), MSG_CURRENT) + ")";
}
clientEdition.put("editionLabel", editionLabel);
clientEdition.put("editionNotes", edition.getDescription());
clientEdition.put("editionAuthor", edition.getCreator());
clientEdition.put("editionDate", edition.getCreatedDate());
// Set the edition of the edition bean
editionBean.setEdition(clientEdition);
// get translations
List<VersionHistory> translationHistories = null;
if (firstEdition)
{
// Get the translations because the current edition doesn't content link with its
// translation in the version store.
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(mlContainer);
translationHistories = new ArrayList<VersionHistory>(translations.size());
for (NodeRef translation : translations.values())
{
translationHistories.add(versionService.getVersionHistory(translation));
}
}
else
{
translationHistories = editionService.getVersionedTranslations(edition);
}
// add each translation in the SingleEditionBean
for (VersionHistory versionHistory : translationHistories)
{
// get the list of versions and sort them ascending according their version label
List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
Collections.sort(orderedVersions, versionComparator);
// the last version is the first version of the list
Version lastVersion = orderedVersions.get(0);
// get the properties of the lastVersion
Map<QName, Serializable> lastVersionProperties = editionService.getVersionedMetadatas(lastVersion);
Locale language = (Locale) lastVersionProperties.get(ContentModel.PROP_LOCALE);
// create a map node representation of the last version
MapNode clientLastVersion = new MapNode(lastVersion.getFrozenStateNodeRef());
clientLastVersion.put("versionName", lastVersionProperties.get(ContentModel.PROP_NAME));
clientLastVersion.put("versionDescription", lastVersionProperties.get(ContentModel.PROP_DESCRIPTION));
clientLastVersion.put("versionAuthor", lastVersionProperties.get(ContentModel.PROP_AUTHOR));
clientLastVersion.put("versionCreatedDate", lastVersionProperties.get(ContentModel.PROP_CREATED));
clientLastVersion.put("versionModifiedDate", lastVersionProperties.get(ContentModel.PROP_MODIFIED));
clientLastVersion.put("versionLanguage", this.contentFilterLanguagesService.convertToNewISOCode(language.getLanguage()).toUpperCase());
clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
// add a translation of the editionBean
editionBean.addTranslations(clientLastVersion);
}
editionHistory.add(editionBean);
firstEdition = false;
}
return editions;
return editionHistory;
}
/**
* Returns a list of objects representing the translations of the
* current document
* Returns a list of objects representing the translations of the current document
*
* @return List of translations
*/
@@ -272,18 +461,18 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
for (Map.Entry entry : translationsMap.entrySet())
{
NodeRef nodeRef = (NodeRef) entry.getValue();
NodeRef nodeRef = (NodeRef) entry.getValue();
// create a map node representation of the translation
MapNode mapNode = new MapNode(nodeRef);
MapNode mapNode = new MapNode(nodeRef);
Locale locale = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
Locale locale = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
String lgge = (locale != null) ?
String lgge = (locale != null) ?
// convert the locale into new ISO codes
contentFilterLanguagesService.convertToNewISOCode(locale.getLanguage()).toUpperCase()
contentFilterLanguagesService.convertToNewISOCode(locale.getLanguage()).toUpperCase()
: null;
mapNode.put("name", nodeService.getProperty(nodeRef, ContentModel.PROP_NAME));
mapNode.put("language", lgge);
mapNode.put("url", DownloadContentServlet.generateBrowserURL(nodeRef, mapNode.getName()));
@@ -293,47 +482,47 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
}
}
return translations;
}
/**
* Determines whether the current document has any categories applied
*
*
* @return true if the document has categories attached
*/
public boolean isCategorised()
{
return getDocument().hasAspect(ContentModel.ASPECT_GEN_CLASSIFIABLE);
}
/**
* Returns a list of objects representing the categories applied to the
* Returns a list of objects representing the categories applied to the
* current document
*
*
* @return List of categories
*/
public String getCategoriesOverviewHTML()
{
String html = null;
if (isCategorised())
{
// we know for now that the general classifiable aspect only will be
// applied so we can retrive the categories property direclty
Collection<NodeRef> categories = (Collection<NodeRef>)this.nodeService.getProperty(
getDocument().getNodeRef(), ContentModel.PROP_CATEGORIES);
if (categories == null || categories.size() == 0)
{
html = Application.getMessage(FacesContext.getCurrentInstance(), MSG_NO_CATEGORIES_APPLIED);
}
else
{
StringBuilder builder = new StringBuilder(Application.getMessage(FacesContext.getCurrentInstance(),
StringBuilder builder = new StringBuilder(Application.getMessage(FacesContext.getCurrentInstance(),
MSG_HAS_FOLLOWING_CATEGORIES));
builder.append("<ul>");
for (NodeRef ref : categories)
{
@@ -345,48 +534,48 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
}
builder.append("</ul>");
html = builder.toString();
}
}
return html;
}
/**
* Event handler called to setup the categories for editing
*
*
* @param event The event
*/
public void setupCategoriesForEdit(ActionEvent event)
{
this.categories = (List)this.nodeService.getProperty(getDocument().getNodeRef(),
this.categories = (List)this.nodeService.getProperty(getDocument().getNodeRef(),
ContentModel.PROP_CATEGORIES);
}
/**
* Returns a Map of the initial categories on the node keyed by the NodeRef
*
*
* @return Map of initial categories
*/
public List getCategories()
{
return this.categories;
}
/**
* Sets the categories Map
*
*
* @param categories
*/
public void setCategories(List categories)
{
this.categories = categories;
}
/**
* Returns the last category added from the multi value editor
*
*
* @return The last category added
*/
public NodeRef getAddedCategory()
@@ -586,11 +775,11 @@ public class DocumentDetailsBean extends BaseDetailsBean
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_INLINEEDITABLE), e.getMessage()), e);
}
// force recreation of the details view - this means the properties sheet component will reinit
return OUTCOME_RETURN;
}
/**
* Navigates to next item in the list of content for the current Space
*/
@@ -623,7 +812,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
// handle wrapping case
next = nodes.get(0);
}
// prepare for showing details for this node
this.browseBean.setupContentAction(next.getId(), false);
break;
@@ -632,7 +821,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
}
}
/**
* Navigates to the previous item in the list of content for the current Space
*/
@@ -662,7 +851,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
// handle wrapping case
previous = nodes.get(nodes.size() - 1);
}
// prepare for showing details for this node
this.browseBean.setupContentAction(previous.getId(), false);
break;
@@ -671,7 +860,7 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
}
}
/**
* @see org.alfresco.web.bean.BaseDetailsBean#getPropertiesPanelId()
*/
@@ -679,59 +868,59 @@ public class DocumentDetailsBean extends BaseDetailsBean
{
return "document-props";
}
/**
* Returns a model for use by a template on the Document Details page.
*
*
* @return model containing current document and current space info.
*/
public Map getTemplateModel()
{
Map<String, Object> model = new HashMap<String, Object>(2, 1.0f);
model.put("document", getDocument().getNodeRef());
model.put("space", this.navigator.getCurrentNode().getNodeRef());
model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
return model;
}
/**
* Returns whether the current document is locked
*
*
* @return true if the document is checked out
*/
public boolean isLocked()
{
return getDocument().isLocked();
}
/**
* Returns whether the current document is a working copy
*
*
* @return true if the document is a working copy
*/
public boolean isWorkingCopy()
{
return getDocument().hasAspect(ContentModel.ASPECT_WORKING_COPY);
}
/**
* @return the working copy document Node for this document if found and the
* @return the working copy document Node for this document if found and the
* current has permission or null if not
*/
public Node getWorkingCopyDocument()
{
Node workingCopyNode = null;
if (isLocked())
{
NodeRef workingCopyRef = this.cociService.getWorkingCopy(getDocument().getNodeRef());
if (workingCopyRef != null)
{
workingCopyNode = new Node(workingCopyRef);
// if the current user does not have read permission on
// if the current user does not have read permission on
// working copy return null
if (workingCopyNode.hasPermission(PermissionService.READ) == false)
{
@@ -739,33 +928,33 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
}
}
return workingCopyNode;
}
/**
* Returns whether the current document is a working copy owned by the current User
*
*
* @return true if the document is a working copy owner by the current User
*/
public boolean isOwner()
{
return getDocument().isWorkingCopyOwner();
}
/**
* Returns the Node this bean is currently representing
*
*
* @return The Node
*/
public Node getNode()
{
return this.browseBean.getDocument();
}
/**
* Returns the document this bean is currently representing
*
*
* @return The document Node
*/
public Node getDocument()
@@ -775,19 +964,19 @@ public class DocumentDetailsBean extends BaseDetailsBean
/**
* Returns the ml container of the document this bean is currently representing
*
*
* @return The document multilingual container NodeRef
*/
public Node getDocumentMlContainer()
{
NodeRef nodeRef = getNode().getNodeRef();
return new Node(multilingualContentService.getTranslationContainer(nodeRef));
}
/**
* Sets the lock service instance the bean should use
*
*
* @param lockService The LockService
*/
public void setLockService(LockService lockService)
@@ -797,17 +986,17 @@ public class DocumentDetailsBean extends BaseDetailsBean
/**
* Sets the version service instance the bean should use
*
*
* @param versionService The VersionService
*/
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
/**
* Sets the checkincheckout service instance the bean should use
*
*
* @param cociService The CheckOutCheckInService
*/
public void setCheckOutCheckInService(CheckOutCheckInService cociService)
@@ -816,19 +1005,29 @@ public class DocumentDetailsBean extends BaseDetailsBean
}
/**
* @param multilingualContentService the multilingualContentService to set
* @param multilingualContentService the multilingual ContentService to set
*/
public void setMultilingualContentService(
MultilingualContentService multilingualContentService)
public void setMultilingualContentService(MultilingualContentService multilingualContentService)
{
this.multilingualContentService = multilingualContentService;
}
/**
* @param contentFilterLanguagesService The ContentFilterLanguagesService to set.
* @param contentFilterLanguagesService The Content Filter Languages Service to set.
*/
public void setContentFilterLanguagesService(ContentFilterLanguagesService contentFilterLanguagesService)
{
this.contentFilterLanguagesService = contentFilterLanguagesService;
}
/**
* @param EditionService The Edition Service to set.
*/
public void setEditionService(EditionService editionService)
{
this.editionService = editionService;
}
}