001/*
002 *  Copyright 2015 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.contentstree;
017
018import java.util.HashMap;
019import java.util.Map;
020
021import org.apache.avalon.framework.component.Component;
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024import org.apache.avalon.framework.service.Serviceable;
025
026import org.ametys.cms.contenttype.ContentTypesHelper;
027import org.ametys.cms.repository.Content;
028import org.ametys.core.ui.Callable;
029import org.ametys.plugins.repository.AmetysObjectResolver;
030
031/**
032 * Component to provide the root content
033 */
034public class TreeRootProvider implements Component, Serviceable
035{
036    /** Avalon role. */
037    public static final String ROLE = TreeRootProvider.class.getName();
038    
039    /** The ametys object resolver instance */
040    protected AmetysObjectResolver _resolver;
041    /** The content types helper instance */
042    protected ContentTypesHelper _contentTypesHelper;
043    
044    @Override
045    public void service(ServiceManager smanager) throws ServiceException
046    {
047        _resolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE);
048        _contentTypesHelper = (ContentTypesHelper) smanager.lookup(ContentTypesHelper.ROLE);
049    }
050    
051    /**
052     * Get the root node informations
053     * @param contentId The content
054     * @return The informations
055     */
056    @Callable
057    public Map<String, Object> getRootNodeInformations(String contentId)
058    {
059        Content content = _resolver.resolveById(contentId);
060        
061        Map<String, Object> rootInfos = new HashMap<>();
062        
063        rootInfos.put("contentId", content.getId());
064        rootInfos.put("contenttypesIds", content.getTypes());
065        rootInfos.put("name", content.getName());
066        rootInfos.put("title", content.getTitle());
067
068        rootInfos.put("iconGlyph", _contentTypesHelper.getIconGlyph(content));
069        rootInfos.put("iconDecorator", _contentTypesHelper.getIconDecorator(content));
070        rootInfos.put("iconSmall", _contentTypesHelper.getSmallIcon(content));
071        rootInfos.put("iconMedium", _contentTypesHelper.getMediumIcon(content));
072        rootInfos.put("iconLarge", _contentTypesHelper.getLargeIcon(content));
073        
074        return rootInfos;
075    }
076
077}