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            public String getClassName() {
041                    return WikiPage.class.getName();
042            }
043    
044            public String getName(Locale locale) {
045                    String portletTitle = PortalUtil.getPortletTitle(
046                            PortletKeys.WIKI, locale);
047    
048                    return portletTitle.concat(StringPool.SPACE).concat(
049                            LanguageUtil.get(locale, "template"));
050            }
051    
052            public String getResourceName() {
053                    return "com.liferay.portlet.wiki";
054            }
055    
056            @Override
057            public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
058                            long classPK, Locale locale)
059                    throws Exception {
060    
061                    Map<String, TemplateVariableGroup> templateVariableGroups =
062                            super.getTemplateVariableGroups(classPK, locale);
063    
064                    TemplateVariableGroup fieldsTemplateVariableGroup =
065                            templateVariableGroups.get("fields");
066    
067                    fieldsTemplateVariableGroup.empty();
068    
069                    fieldsTemplateVariableGroup.addVariable(
070                            "wiki-page", WikiPage.class, PortletDisplayTemplateConstants.ENTRY);
071                    fieldsTemplateVariableGroup.addVariable(
072                            "wiki-page-content", String.class, "formattedContent");
073    
074                    TemplateVariableGroup wikiServicesTemplateVariableGroup =
075                            new TemplateVariableGroup("wiki-services");
076    
077                    wikiServicesTemplateVariableGroup.setAutocompleteEnabled(false);
078    
079                    wikiServicesTemplateVariableGroup.addServiceLocatorVariables(
080                            WikiPageLocalService.class, WikiPageService.class,
081                            WikiNodeLocalService.class, WikiNodeService.class);
082    
083                    templateVariableGroups.put(
084                            wikiServicesTemplateVariableGroup.getLabel(),
085                            wikiServicesTemplateVariableGroup);
086    
087                    return templateVariableGroups;
088            }
089    
090            @Override
091            protected String getTemplatesConfigPath() {
092                    return PropsValues.WIKI_DISPLAY_TEMPLATES_CONFIG;
093            }
094    
095    }