Search in sources :

Example 21 with MapNode

use of org.alfresco.web.bean.repository.MapNode in project acs-community-packaging by Alfresco.

the class MultilingualManageDialog method getTranslations.

/**
 * Returns a list of objects representing the translations of the current document
 *
 * @return List of translations
 */
public List getTranslations() {
    List<MapNode> translations = new ArrayList<MapNode>();
    Node document = getDocument();
    boolean canNewEdtion = MultilingualUtils.canStartNewEditon(document, FacesContext.getCurrentInstance());
    if (document.hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) || ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(document.getType())) {
        Map<Locale, NodeRef> translationsMap = getMultilingualContentService().getTranslations(getDocument().getNodeRef());
        if (translationsMap != null && translationsMap.size() > 0) {
            for (Map.Entry entry : translationsMap.entrySet()) {
                NodeRef nodeRef = (NodeRef) entry.getValue();
                // create a map node representation of the translation
                MapNode mapNode = new MapNode(nodeRef);
                Locale locale = (Locale) getNodeService().getProperty(nodeRef, ContentModel.PROP_LOCALE);
                String lgge = (locale != null) ? // convert the locale into new ISO codes
                getContentFilterLanguagesService().convertToNewISOCode(locale.getLanguage()).toUpperCase() : null;
                mapNode.put("name", getNodeService().getProperty(nodeRef, ContentModel.PROP_NAME));
                mapNode.put("language", lgge);
                mapNode.put("url", DownloadContentServlet.generateBrowserURL(nodeRef, mapNode.getName()));
                boolean isEmpty = new Boolean(getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
                mapNode.put("notEmpty", !isEmpty);
                mapNode.put("userHasRight", new Boolean(canNewEdtion && !isEmpty));
                // add the client side version to the list
                translations.add(mapNode);
            }
        }
    }
    return translations;
}
Also used : Locale(java.util.Locale) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MapNode (org.alfresco.web.bean.repository.MapNode)21 NodeRef (org.alfresco.service.cmr.repository.NodeRef)18 Node (org.alfresco.web.bean.repository.Node)12 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)10 UserTransaction (javax.transaction.UserTransaction)9 ArrayList (java.util.ArrayList)8 FacesContext (javax.faces.context.FacesContext)8 QName (org.alfresco.service.namespace.QName)8 AbortProcessingException (javax.faces.event.AbortProcessingException)5 Version (org.alfresco.service.cmr.version.Version)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 Map (java.util.Map)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)4 SearcherException (org.alfresco.repo.search.SearcherException)3 Serializable (java.io.Serializable)2 List (java.util.List)2 PagingRequest (org.alfresco.query.PagingRequest)2