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.sitemap.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.model.Layout;
022    import com.liferay.portal.model.LayoutSet;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portal.util.PropsValues;
026    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
027    
028    import java.util.List;
029    import java.util.Locale;
030    import java.util.Map;
031    
032    /**
033     * @author Juan Fern??ndez
034     */
035    public class SiteMapPortletDisplayTemplateHandler
036            extends BasePortletDisplayTemplateHandler {
037    
038            @Override
039            public String getClassName() {
040                    return LayoutSet.class.getName();
041            }
042    
043            @Override
044            public String getName(Locale locale) {
045                    String portletTitle = PortalUtil.getPortletTitle(
046                            PortletKeys.SITE_MAP, locale);
047    
048                    return portletTitle.concat(StringPool.SPACE).concat(
049                            LanguageUtil.get(locale, "template"));
050            }
051    
052            @Override
053            public String getResourceName() {
054                    return PortletKeys.SITE_MAP;
055            }
056    
057            @Override
058            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
059                            long classPK, String language, Locale locale)
060                    throws Exception {
061    
062                    Map<String, TemplateVariableGroup> templateVariableGroups =
063                            super.getTemplateVariableGroups(classPK, language, locale);
064    
065                    TemplateVariableGroup templateVariableGroup =
066                            templateVariableGroups.get("fields");
067    
068                    templateVariableGroup.empty();
069    
070                    templateVariableGroup.addCollectionVariable(
071                            "pages", List.class, PortletDisplayTemplateConstants.ENTRIES,
072                            "page", Layout.class, "curPage", "getName(locale)");
073    
074                    return templateVariableGroups;
075            }
076    
077            @Override
078            protected String getTemplatesConfigPath() {
079                    return PropsValues.SITEMAP_DISPLAY_TEMPLATES_CONFIG;
080            }
081    
082    }