001    /**
002     * Copyright (c) 2000-present 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.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.WebKeys;
018    import com.liferay.portal.theme.PortletDisplay;
019    import com.liferay.portal.theme.ThemeDisplay;
020    import com.liferay.taglib.util.IncludeTag;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Charles May
026     */
027    public class DiscussionTag extends IncludeTag {
028    
029            public void setAssetEntryVisible(boolean assetEntryVisible) {
030                    _assetEntryVisible = assetEntryVisible;
031            }
032    
033            public void setClassName(String className) {
034                    _className = className;
035            }
036    
037            public void setClassPK(long classPK) {
038                    _classPK = classPK;
039            }
040    
041            public void setFormAction(String formAction) {
042                    _formAction = formAction;
043            }
044    
045            public void setFormName(String formName) {
046                    _formName = formName;
047            }
048    
049            public void setHideControls(boolean hideControls) {
050                    _hideControls = hideControls;
051            }
052    
053            public void setRatingsEnabled(boolean ratingsEnabled) {
054                    _ratingsEnabled = ratingsEnabled;
055            }
056    
057            public void setRedirect(String redirect) {
058                    _redirect = redirect;
059            }
060    
061            /**
062             * @deprecated As of 6.2.0, with no direct replacement
063             */
064            @Deprecated
065            public void setSubject(String subject) {
066            }
067    
068            public void setUserId(long userId) {
069                    _userId = userId;
070            }
071    
072            @Override
073            protected void cleanUp() {
074                    _assetEntryVisible = true;
075                    _className = null;
076                    _classPK = 0;
077                    _formAction = null;
078                    _formName = "fm";
079                    _hideControls = false;
080                    _ratingsEnabled = true;
081                    _redirect = null;
082                    _userId = 0;
083            }
084    
085            protected String getFormAction(HttpServletRequest request) {
086                    if (_formAction != null) {
087                            return _formAction;
088                    }
089    
090                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
091                            WebKeys.THEME_DISPLAY);
092    
093                    return themeDisplay.getPathMain() + "/portal/comment/edit_discussion";
094            }
095    
096            @Override
097            protected String getPage() {
098                    return _PAGE;
099            }
100    
101            protected String getPaginationURL(HttpServletRequest request) {
102                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
103                            WebKeys.THEME_DISPLAY);
104    
105                    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
106    
107                    String portletId = portletDisplay.getId();
108    
109                    return themeDisplay.getPathMain() +
110                            "/portal/comment/get_comments?p_p_isolated=1&portletId=" +
111                                    portletId;
112            }
113    
114            @Override
115            protected void setAttributes(HttpServletRequest request) {
116                    request.setAttribute(
117                            "liferay-ui:discussion:assetEntryVisible",
118                            String.valueOf(_assetEntryVisible));
119                    request.setAttribute("liferay-ui:discussion:className", _className);
120                    request.setAttribute(
121                            "liferay-ui:discussion:classPK", String.valueOf(_classPK));
122                    request.setAttribute(
123                            "liferay-ui:discussion:formAction", getFormAction(request));
124                    request.setAttribute("liferay-ui:discussion:formName", _formName);
125                    request.setAttribute(
126                            "liferay-ui:discussion:hideControls",
127                            String.valueOf(_hideControls));
128                    request.setAttribute(
129                            "liferay-ui:discussion:paginationURL", getPaginationURL(request));
130                    request.setAttribute(
131                            "liferay-ui:discussion:ratingsEnabled",
132                            String.valueOf(_ratingsEnabled));
133                    request.setAttribute("liferay-ui:discussion:redirect", _redirect);
134                    request.setAttribute(
135                            "liferay-ui:discussion:userId", String.valueOf(_userId));
136            }
137    
138            private static final String _PAGE = "/html/taglib/ui/discussion/page.jsp";
139    
140            private boolean _assetEntryVisible = true;
141            private String _className;
142            private long _classPK;
143            private String _formAction;
144            private String _formName = "fm";
145            private boolean _hideControls;
146            private boolean _ratingsEnabled = true;
147            private String _redirect;
148            private long _userId;
149    
150    }