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.assetcategoriesnavigation.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.AssetCategory;
025    import com.liferay.portlet.asset.model.AssetVocabulary;
026    import com.liferay.portlet.asset.service.AssetCategoryLocalService;
027    import com.liferay.portlet.asset.service.AssetCategoryService;
028    import com.liferay.portlet.asset.service.AssetVocabularyLocalService;
029    import com.liferay.portlet.asset.service.AssetVocabularyService;
030    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
031    
032    import java.util.List;
033    import java.util.Locale;
034    import java.util.Map;
035    
036    /**
037     * @author Juan Fernández
038     */
039    public class AssetCategoriesNavigationPortletDisplayTemplateHandler
040            extends BasePortletDisplayTemplateHandler {
041    
042            public String getClassName() {
043                    return AssetCategory.class.getName();
044            }
045    
046            public String getName(Locale locale) {
047                    String portletTitle = PortalUtil.getPortletTitle(
048                            PortletKeys.TAGS_CATEGORIES_NAVIGATION, locale);
049    
050                    return portletTitle.concat(StringPool.SPACE).concat(
051                            LanguageUtil.get(locale, "template"));
052            }
053    
054            public String getResourceName() {
055                    return "com.liferay.portlet.assetcategoriesnavigation";
056            }
057    
058            @Override
059            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
060                            long classPK, Locale locale)
061                    throws Exception {
062    
063                    Map<String, TemplateVariableGroup> templateVariableGroups =
064                            super.getTemplateVariableGroups(classPK, locale);
065    
066                    TemplateVariableGroup templateVariableGroup =
067                            templateVariableGroups.get("fields");
068    
069                    templateVariableGroup.empty();
070    
071                    templateVariableGroup.addCollectionVariable(
072                            "vocabularies", List.class, PortletDisplayTemplateConstants.ENTRIES,
073                            "vocabulary", AssetVocabulary.class, "curVocabulary");
074    
075                    TemplateVariableGroup categoriesServicesTemplateVariableGroup =
076                            new TemplateVariableGroup("category-services");
077    
078                    categoriesServicesTemplateVariableGroup.setAutocompleteEnabled(false);
079    
080                    categoriesServicesTemplateVariableGroup.addServiceLocatorVariables(
081                            AssetVocabularyLocalService.class, AssetVocabularyService.class,
082                            AssetCategoryLocalService.class, AssetCategoryService.class);
083    
084                    templateVariableGroups.put(
085                            categoriesServicesTemplateVariableGroup.getLabel(),
086                            categoriesServicesTemplateVariableGroup);
087    
088                    return templateVariableGroups;
089            }
090    
091            @Override
092            protected String getTemplatesConfigPath() {
093                    return PropsValues.ASSET_CATEGORIES_NAVIGATION_DISPLAY_TEMPLATES_CONFIG;
094            }
095    
096    }