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.ddm;
016    
017    import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.kernel.portlet.LiferayWindowState;
020    import com.liferay.portal.kernel.template.TemplateConstants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.kernel.util.SetUtil;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.kernel.util.Validator;
025    import com.liferay.portal.util.PortalUtil;
026    import com.liferay.portal.util.PortletKeys;
027    import com.liferay.portal.util.PropsValues;
028    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
029    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
030    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants;
031    import com.liferay.portlet.dynamicdatamapping.util.BaseDDMDisplay;
032    import com.liferay.portlet.journal.model.JournalArticle;
033    import com.liferay.portlet.journal.service.permission.JournalPermission;
034    
035    import java.util.Set;
036    
037    import javax.portlet.PortletRequest;
038    import javax.portlet.PortletURL;
039    
040    /**
041     * @author Eduardo Garcia
042     */
043    public class JournalDDMDisplay extends BaseDDMDisplay {
044    
045            @Override
046            public String getAvailableFields() {
047                    return "Liferay.FormBuilder.AVAILABLE_FIELDS.WCM_STRUCTURE";
048            }
049    
050            @Override
051            public String getEditStructureDefaultValuesURL(
052                            LiferayPortletRequest liferayPortletRequest,
053                            LiferayPortletResponse liferayPortletResponse,
054                            DDMStructure structure, String redirectURL, String backURL)
055                    throws Exception {
056    
057                    PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
058                            getControlPanelPlid(liferayPortletRequest), PortletKeys.JOURNAL,
059                            PortletRequest.RENDER_PHASE);
060    
061                    portletURL.setParameter("struts_action", "/journal/edit_article");
062                    portletURL.setParameter("redirect", redirectURL);
063                    portletURL.setParameter("backURL", backURL);
064                    portletURL.setParameter(
065                            "groupId", String.valueOf(structure.getGroupId()));
066                    portletURL.setParameter(
067                            "classNameId",
068                            String.valueOf(PortalUtil.getClassNameId(DDMStructure.class)));
069                    portletURL.setParameter(
070                            "classPK", String.valueOf(structure.getStructureId()));
071                    portletURL.setParameter("structureId", structure.getStructureKey());
072                    portletURL.setWindowState(LiferayWindowState.POP_UP);
073    
074                    return portletURL.toString();
075            }
076    
077            @Override
078            public String getEditTemplateBackURL(
079                            LiferayPortletRequest liferayPortletRequest,
080                            LiferayPortletResponse liferayPortletResponse, long classNameId,
081                            long classPK, String portletResource)
082                    throws Exception {
083    
084                    String redirect = ParamUtil.getString(
085                            liferayPortletRequest, "redirect");
086    
087                    if (Validator.isNull(redirect)) {
088                            return getViewTemplatesURL(
089                                    liferayPortletRequest, liferayPortletResponse, classNameId,
090                                    classPK);
091                    }
092    
093                    return redirect;
094            }
095    
096            @Override
097            public String getPortletId() {
098                    return PortletKeys.JOURNAL;
099            }
100    
101            @Override
102            public String getResourceName() {
103                    return JournalPermission.RESOURCE_NAME;
104            }
105    
106            @Override
107            public String getStorageType() {
108                    return PropsValues.JOURNAL_ARTICLE_STORAGE_TYPE;
109            }
110    
111            @Override
112            public String getStructureType() {
113                    return JournalArticle.class.getName();
114            }
115    
116            @Override
117            public long getTemplateHandlerClassNameId(
118                    DDMTemplate template, long classNameId) {
119    
120                    return PortalUtil.getClassNameId(JournalArticle.class);
121            }
122    
123            @Override
124            public Set<String> getTemplateLanguageTypes() {
125                    return _templateLanguageTypes;
126            }
127    
128            @Override
129            public String getTemplateType() {
130                    return DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY;
131            }
132    
133            @Override
134            public String getViewTemplatesBackURL(
135                            LiferayPortletRequest liferayPortletRequest,
136                            LiferayPortletResponse liferayPortletResponse, long classPK)
137                    throws Exception {
138    
139                    if (classPK <= 0) {
140                            return StringPool.BLANK;
141                    }
142    
143                    return super.getViewTemplatesBackURL(
144                            liferayPortletRequest, liferayPortletResponse, classPK);
145            }
146    
147            @Override
148            public Set<String> getViewTemplatesExcludedColumnNames() {
149                    return _viewTemplateExcludedColumnNames;
150            }
151    
152            @Override
153            public boolean isShowStructureSelector() {
154                    return true;
155            }
156    
157            private static Set<String> _templateLanguageTypes =
158                    SetUtil.fromArray(
159                            new String[] {
160                                    TemplateConstants.LANG_TYPE_FTL, TemplateConstants.LANG_TYPE_VM,
161                                    TemplateConstants.LANG_TYPE_XSL
162                            });
163            private static Set<String> _viewTemplateExcludedColumnNames =
164                    SetUtil.fromArray(new String[] {"mode"});
165    
166    }