001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }