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.wiki.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.portletdisplaytemplate.util.PortletDisplayTemplateConstants;
025    import com.liferay.portlet.wiki.model.WikiPage;
026    import com.liferay.portlet.wiki.service.WikiNodeLocalService;
027    import com.liferay.portlet.wiki.service.WikiNodeService;
028    import com.liferay.portlet.wiki.service.WikiPageLocalService;
029    import com.liferay.portlet.wiki.service.WikiPageService;
030    
031    import java.util.Locale;
032    import java.util.Map;
033    
034    /**
035     * @author Juan Fern??ndez
036     */
037    public class WikiPortletDisplayTemplateHandler
038            extends BasePortletDisplayTemplateHandler {
039    
040            @Override
041            public String getClassName() {
042                    return WikiPage.class.getName();
043            }
044    
045            @Override
046            public String getName(Locale locale) {
047                    String portletTitle = PortalUtil.getPortletTitle(
048                            PortletKeys.WIKI, locale);
049    
050                    return portletTitle.concat(StringPool.SPACE).concat(
051                            LanguageUtil.get(locale, "template"));
052            }
053    
054            @Override
055            public String getResourceName() {
056                    return PortletKeys.WIKI;
057            }
058    
059            @Override
060            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
061                            long classPK, String language, Locale locale)
062                    throws Exception {
063    
064                    Map<String, TemplateVariableGroup> templateVariableGroups =
065                            super.getTemplateVariableGroups(classPK, language, locale);
066    
067                    TemplateVariableGroup fieldsTemplateVariableGroup =
068                            templateVariableGroups.get("fields");
069    
070                    fieldsTemplateVariableGroup.empty();
071    
072                    fieldsTemplateVariableGroup.addVariable(
073                            "wiki-page", WikiPage.class, PortletDisplayTemplateConstants.ENTRY);
074                    fieldsTemplateVariableGroup.addVariable(
075                            "wiki-page-content", String.class, "formattedContent");
076    
077                    TemplateVariableGroup wikiServicesTemplateVariableGroup =
078                            new TemplateVariableGroup("wiki-services");
079    
080                    wikiServicesTemplateVariableGroup.setAutocompleteEnabled(false);
081    
082                    wikiServicesTemplateVariableGroup.addServiceLocatorVariables(
083                            WikiPageLocalService.class, WikiPageService.class,
084                            WikiNodeLocalService.class, WikiNodeService.class);
085    
086                    templateVariableGroups.put(
087                            wikiServicesTemplateVariableGroup.getLabel(),
088                            wikiServicesTemplateVariableGroup);
089    
090                    return templateVariableGroups;
091            }
092    
093            @Override
094            protected String getTemplatesConfigPath() {
095                    return PropsValues.WIKI_DISPLAY_TEMPLATES_CONFIG;
096            }
097    
098    }