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            public String getClassName() {
041                    return AssetTag.class.getName();
042            }
043    
044            public String getName(Locale locale) {
045                    String portletTitle = PortalUtil.getPortletTitle(
046                            PortletKeys.TAGS_ENTRIES_NAVIGATION, locale);
047    
048                    return portletTitle.concat(StringPool.SPACE).concat(
049                            LanguageUtil.get(locale, "template"));
050            }
051    
052            public String getResourceName() {
053                    return "com.liferay.portlet.assettagsnavigation";
054            }
055    
056            @Override
057            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
058                            long classPK, Locale locale)
059                    throws Exception {
060    
061                    Map<String, TemplateVariableGroup> templateVariableGroups =
062                            super.getTemplateVariableGroups(classPK, locale);
063    
064                    TemplateVariableGroup templateVariableGroup =
065                            templateVariableGroups.get("fields");
066    
067                    templateVariableGroup.empty();
068    
069                    templateVariableGroup.addCollectionVariable(
070                            "tags", List.class, PortletDisplayTemplateConstants.ENTRIES, "tag",
071                            AssetTag.class, "curTag");
072    
073                    TemplateVariableGroup assetServicesTemplateVariableGroup =
074                            new TemplateVariableGroup("tag-services");
075    
076                    assetServicesTemplateVariableGroup.setAutocompleteEnabled(false);
077    
078                    assetServicesTemplateVariableGroup.addServiceLocatorVariables(
079                            AssetTagLocalService.class, AssetTagService.class,
080                            AssetTagStatsLocalService.class);
081    
082                    templateVariableGroups.put(
083                            assetServicesTemplateVariableGroup.getLabel(),
084                            assetServicesTemplateVariableGroup);
085    
086                    return templateVariableGroups;
087            }
088    
089            @Override
090            protected String getTemplatesConfigPath() {
091                    return PropsValues.ASSET_TAGS_NAVIGATION_DISPLAY_TEMPLATES_CONFIG;
092            }
093    
094    }