001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.assettagsnavigation.template;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
019    import com.liferay.portal.kernel.template.TemplateVariableGroup;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.util.PortalUtil;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portal.util.PropsValues;
024    import com.liferay.portlet.asset.model.AssetTag;
025    import com.liferay.portlet.asset.service.AssetTagLocalService;
026    import com.liferay.portlet.asset.service.AssetTagService;
027    import com.liferay.portlet.asset.service.AssetTagStatsLocalService;
028    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
029    
030    import java.util.List;
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * @author Juan Fern??ndez
036     */
037    public class AssetTagsNavigationPortletDisplayTemplateHandler
038            extends BasePortletDisplayTemplateHandler {
039    
040            @Override
041            public String getClassName() {
042                    return AssetTag.class.getName();
043            }
044    
045            @Override
046            public String getName(Locale locale) {
047                    String portletTitle = PortalUtil.getPortletTitle(
048                            PortletKeys.ASSET_TAGS_NAVIGATION, locale);
049    
050                    return portletTitle.concat(StringPool.SPACE).concat(
051                            LanguageUtil.get(locale, "template"));
052            }
053    
054            @Override
055            public String getResourceName() {
056                    return PortletKeys.ASSET_TAGS_NAVIGATION;
057            }
058    
059            @Override
060            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
061                            long classPK, String language, Locale locale)
062                    throws Exception {
063    
064                    Map<String, TemplateVariableGroup> templateVariableGroups =
065                            super.getTemplateVariableGroups(classPK, language, locale);
066    
067                    TemplateVariableGroup templateVariableGroup =
068                            templateVariableGroups.get("fields");
069    
070                    templateVariableGroup.empty();
071    
072                    templateVariableGroup.addCollectionVariable(
073                            "tags", List.class, PortletDisplayTemplateConstants.ENTRIES, "tag",
074                            AssetTag.class, "curTag", "name");
075    
076                    String[] restrictedVariables = getRestrictedVariables(language);
077    
078                    TemplateVariableGroup assetServicesTemplateVariableGroup =
079                            new TemplateVariableGroup("tag-services", restrictedVariables);
080    
081                    assetServicesTemplateVariableGroup.setAutocompleteEnabled(false);
082    
083                    assetServicesTemplateVariableGroup.addServiceLocatorVariables(
084                            AssetTagLocalService.class, AssetTagService.class,
085                            AssetTagStatsLocalService.class);
086    
087                    templateVariableGroups.put(
088                            assetServicesTemplateVariableGroup.getLabel(),
089                            assetServicesTemplateVariableGroup);
090    
091                    return templateVariableGroups;
092            }
093    
094            @Override
095            protected String getTemplatesConfigPath() {
096                    return PropsValues.ASSET_TAGS_NAVIGATION_DISPLAY_TEMPLATES_CONFIG;
097            }
098    
099    }