001    /**
002     * Copyright (c) 2000-present 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.breadcrumb.template;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
019    import com.liferay.portal.kernel.servlet.taglib.ui.BreadcrumbEntry;
020    import com.liferay.portal.kernel.servlet.taglib.ui.BreadcrumbUtil;
021    import com.liferay.portal.kernel.template.TemplateVariableGroup;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.model.Layout;
024    import com.liferay.portal.util.PortalUtil;
025    import com.liferay.portal.util.PortletKeys;
026    import com.liferay.portal.util.PropsValues;
027    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
028    
029    import java.util.HashMap;
030    import java.util.List;
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * @author Jos?? Manuel Navarro
036     */
037    public class BreadcrumbPortletDisplayTemplateHandler
038            extends BasePortletDisplayTemplateHandler {
039    
040            @Override
041            public String getClassName() {
042                    return Layout.class.getName();
043            }
044    
045            @Override
046            public Map<String, Object> getCustomContextObjects() {
047                    Map<String, Object> customContextObjects = new HashMap<String, Object>(
048                            1);
049    
050                    customContextObjects.put("breadcrumbUtil", BreadcrumbUtil.class);
051    
052                    return customContextObjects;
053            }
054    
055            @Override
056            public String getName(Locale locale) {
057                    String portletTitle = PortalUtil.getPortletTitle(
058                            getResourceName(), locale);
059    
060                    return portletTitle.concat(StringPool.SPACE).concat(
061                            LanguageUtil.get(locale, "template"));
062            }
063    
064            @Override
065            public String getResourceName() {
066                    return PortletKeys.BREADCRUMB;
067            }
068    
069            @Override
070            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
071                            long classPK, String language, Locale locale)
072                    throws Exception {
073    
074                    Map<String, TemplateVariableGroup> templateVariableGroups =
075                            super.getTemplateVariableGroups(classPK, language, locale);
076    
077                    TemplateVariableGroup fieldsTemplateVariableGroup =
078                            templateVariableGroups.get("fields");
079    
080                    fieldsTemplateVariableGroup.addCollectionVariable(
081                            "breadcrumb-entries", List.class,
082                            PortletDisplayTemplateConstants.ENTRIES, "breadcrumb-entry",
083                            BreadcrumbEntry.class, "curEntry", "getTitle()");
084                    fieldsTemplateVariableGroup.addVariable(
085                            "breadcrumb-entry", BreadcrumbEntry.class,
086                            PortletDisplayTemplateConstants.ENTRY, "getTitle()");
087                    fieldsTemplateVariableGroup.addVariable(
088                            "breadcrumb-util", BreadcrumbUtil.class, "breadcrumbUtil");
089    
090                    return templateVariableGroups;
091            }
092    
093            @Override
094            protected String getTemplatesConfigPath() {
095                    return PropsValues.BREADCRUMB_DISPLAY_TEMPLATES_CONFIG;
096            }
097    
098    }