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