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.portletdisplaytemplate.ddm;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
019    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
020    import com.liferay.portal.kernel.template.TemplateHandler;
021    import com.liferay.portal.kernel.template.TemplateHandlerRegistryUtil;
022    import com.liferay.portal.kernel.util.ParamUtil;
023    import com.liferay.portal.kernel.util.SetUtil;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portal.kernel.util.Validator;
026    import com.liferay.portal.security.permission.ActionKeys;
027    import com.liferay.portal.theme.ThemeDisplay;
028    import com.liferay.portal.util.PortalUtil;
029    import com.liferay.portal.util.PortletKeys;
030    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
031    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
032    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants;
033    import com.liferay.portlet.dynamicdatamapping.util.BaseDDMDisplay;
034    import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateUtil;
035    
036    import java.util.Locale;
037    import java.util.Set;
038    
039    /**
040     * @author Eduardo Garcia
041     */
042    public class PortletDisplayTemplateDDMDisplay extends BaseDDMDisplay {
043    
044            @Override
045            public String getAddTemplateActionId() {
046                    return ActionKeys.ADD_PORTLET_DISPLAY_TEMPLATE;
047            }
048    
049            @Override
050            public String getEditTemplateBackURL(
051                            LiferayPortletRequest liferayPortletRequest,
052                            LiferayPortletResponse liferayPortletResponse, long classNameId,
053                            long classPK, String portletResource)
054                    throws Exception {
055    
056                    String redirect = ParamUtil.getString(
057                            liferayPortletRequest, "redirect");
058    
059                    if (Validator.isNull(redirect)) {
060                            return getViewTemplatesURL(
061                                    liferayPortletRequest, liferayPortletResponse, classNameId,
062                                    classPK);
063                    }
064    
065                    return redirect;
066            }
067    
068            @Override
069            public String getPortletId() {
070                    return PortletKeys.PORTLET_DISPLAY_TEMPLATES;
071            }
072    
073            @Override
074            public String getResourceName() {
075                    return StringPool.BLANK;
076            }
077    
078            @Override
079            public long[] getTemplateClassPKs(
080                            long companyId, long classNameId, long classPK)
081                    throws Exception {
082    
083                    return null;
084            }
085    
086            @Override
087            public long[] getTemplateGroupIds(
088                            ThemeDisplay themeDisplay, boolean showGlobalScope)
089                    throws Exception {
090    
091                    if (showGlobalScope) {
092                            return PortalUtil.getSiteAndCompanyGroupIds(themeDisplay);
093                    }
094    
095                    return new long[] {
096                            PortletDisplayTemplateUtil.getDDMTemplateGroupId(
097                                    themeDisplay.getScopeGroupId())
098                            };
099            }
100    
101            @Override
102            public String getTemplateType() {
103                    return DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY;
104            }
105    
106            @Override
107            public String getTemplateType(DDMTemplate template, Locale locale) {
108                    TemplateHandler templateHandler =
109                            TemplateHandlerRegistryUtil.getTemplateHandler(
110                                    template.getClassNameId());
111    
112                    return templateHandler.getName(locale);
113            }
114    
115            @Override
116            public String getViewTemplatesBackURL(
117                            LiferayPortletRequest liferayPortletRequest,
118                            LiferayPortletResponse liferayPortletResponse, long classPK)
119                    throws Exception {
120    
121                    return StringPool.BLANK;
122            }
123    
124            @Override
125            public Set<String> getViewTemplatesExcludedColumnNames() {
126                    return _viewTemplateExcludedColumnNames;
127            }
128    
129            @Override
130            public String getViewTemplatesTitle(
131                    DDMStructure structure, boolean controlPanel, Locale locale) {
132    
133                    if (controlPanel) {
134                            return StringPool.BLANK;
135                    }
136    
137                    return super.getViewTemplatesTitle(structure, controlPanel, locale);
138            }
139    
140            @Override
141            protected String getDefaultEditTemplateTitle(Locale locale) {
142                    return LanguageUtil.get(locale, "new-application-display-template");
143            }
144    
145            @Override
146            protected String getDefaultViewTemplateTitle(Locale locale) {
147                    return LanguageUtil.get(locale, "application-display-templates");
148            }
149    
150            private static Set<String> _viewTemplateExcludedColumnNames =
151                    SetUtil.fromArray(new String[] {"language", "mode", "structure"});
152    
153    }