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