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.journal.template;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.template.TemplateVariableCodeHandler;
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.portlet.dynamicdatamapping.service.DDMStructureLocalService;
024    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureService;
025    import com.liferay.portlet.dynamicdatamapping.service.DDMTemplateLocalService;
026    import com.liferay.portlet.dynamicdatamapping.service.DDMTemplateService;
027    import com.liferay.portlet.dynamicdatamapping.template.BaseDDMTemplateHandler;
028    import com.liferay.portlet.dynamicdatamapping.template.DDMTemplateVariableCodeHandler;
029    import com.liferay.portlet.journal.model.JournalArticle;
030    import com.liferay.portlet.journal.service.JournalArticleLocalService;
031    import com.liferay.portlet.journal.service.JournalArticleService;
032    
033    import java.util.Locale;
034    import java.util.Map;
035    
036    /**
037     * @author Jorge Ferrer
038     */
039    public class JournalTemplateHandler extends BaseDDMTemplateHandler {
040    
041            @Override
042            public String getClassName() {
043                    return JournalArticle.class.getName();
044            }
045    
046            @Override
047            public String getName(Locale locale) {
048                    String portletTitle = PortalUtil.getPortletTitle(
049                            PortletKeys.JOURNAL, locale);
050    
051                    return portletTitle.concat(StringPool.SPACE).concat(
052                            LanguageUtil.get(locale, "template"));
053            }
054    
055            @Override
056            public String getResourceName() {
057                    return "com.liferay.portlet.journal.template";
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                    String[] restrictedVariables = getRestrictedVariables(language);
069    
070                    TemplateVariableGroup journalServicesTemplateVariableGroup =
071                            new TemplateVariableGroup(
072                                    "web-content-services", restrictedVariables);
073    
074                    journalServicesTemplateVariableGroup.setAutocompleteEnabled(false);
075    
076                    journalServicesTemplateVariableGroup.addServiceLocatorVariables(
077                            JournalArticleLocalService.class, JournalArticleService.class,
078                            DDMStructureLocalService.class, DDMStructureService.class,
079                            DDMTemplateLocalService.class, DDMTemplateService.class);
080    
081                    templateVariableGroups.put(
082                            journalServicesTemplateVariableGroup.getLabel(),
083                            journalServicesTemplateVariableGroup);
084    
085                    return templateVariableGroups;
086            }
087    
088            @Override
089            protected TemplateVariableCodeHandler getTemplateVariableCodeHandler() {
090                    return _templateVariableCodeHandler;
091            }
092    
093            @Override
094            protected TemplateVariableGroup getUtilTemplateVariableGroup() {
095                    TemplateVariableGroup utilTemplateVariableGroup =
096                            super.getUtilTemplateVariableGroup();
097    
098                    utilTemplateVariableGroup.addVariable(
099                            "xml-request", String.class, "xmlRequest");
100    
101                    return utilTemplateVariableGroup;
102            }
103    
104            private TemplateVariableCodeHandler _templateVariableCodeHandler =
105                    new DDMTemplateVariableCodeHandler(
106                            "com/liferay/portlet/journal/dependencies/template/");
107    
108    }