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.taglib.ui;
016    
017    import com.liferay.portal.kernel.editor.EditorUtil;
018    import com.liferay.portal.kernel.util.WebKeys;
019    import com.liferay.portal.model.Portlet;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.taglib.util.IncludeTag;
022    
023    import java.util.Map;
024    
025    import javax.servlet.http.HttpServletRequest;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class InputEditorTag extends IncludeTag {
031    
032            public void setConfigParams(Map<String, String> configParams) {
033                    _configParams = configParams;
034            }
035    
036            public void setContentsLanguageId(String contentsLanguageId) {
037                    _contentsLanguageId = contentsLanguageId;
038            }
039    
040            public void setCssClass(String cssClass) {
041                    _cssClass = cssClass;
042            }
043    
044            public void setEditorImpl(String editorImpl) {
045                    _editorImpl = editorImpl;
046            }
047    
048            public void setFileBrowserParams(Map<String, String> fileBrowserParams) {
049                    _fileBrowserParams = fileBrowserParams;
050            }
051    
052            public void setHeight(String height) {
053                    _height = height;
054            }
055    
056            public void setInitMethod(String initMethod) {
057                    _initMethod = initMethod;
058            }
059    
060            public void setInlineEdit(boolean inlineEdit) {
061                    _inlineEdit = inlineEdit;
062            }
063    
064            public void setInlineEditSaveURL(String inlineEditSaveURL) {
065                    _inlineEditSaveURL = inlineEditSaveURL;
066            }
067    
068            public void setName(String name) {
069                    _name = name;
070            }
071    
072            public void setOnBlurMethod(String onBlurMethod) {
073                    _onBlurMethod = onBlurMethod;
074            }
075    
076            public void setOnChangeMethod(String onChangeMethod) {
077                    _onChangeMethod = onChangeMethod;
078            }
079    
080            public void setOnFocusMethod(String onFocusMethod) {
081                    _onFocusMethod = onFocusMethod;
082            }
083    
084            public void setResizable(boolean resizable) {
085                    _resizable = resizable;
086            }
087    
088            public void setSkipEditorLoading(boolean skipEditorLoading) {
089                    _skipEditorLoading = skipEditorLoading;
090            }
091    
092            public void setToolbarSet(String toolbarSet) {
093                    _toolbarSet = toolbarSet;
094            }
095    
096            public void setWidth(String width) {
097                    _width = width;
098            }
099    
100            @Override
101            protected void cleanUp() {
102                    _configParams = null;
103                    _contentsLanguageId = null;
104                    _cssClass = null;
105                    _editorImpl = null;
106                    _fileBrowserParams = null;
107                    _height = null;
108                    _initMethod = "initEditor";
109                    _inlineEdit = false;
110                    _inlineEditSaveURL = null;
111                    _name = "editor";
112                    _onChangeMethod = null;
113                    _onBlurMethod = null;
114                    _onFocusMethod = null;
115                    _page = null;
116                    _resizable = true;
117                    _skipEditorLoading = false;
118                    _toolbarSet = "liferay";
119                    _width = null;
120            }
121    
122            @Override
123            protected String getPage() {
124                    return _page;
125            }
126    
127            @Override
128            protected void setAttributes(HttpServletRequest request) {
129                    if (_contentsLanguageId == null) {
130                            ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
131                                    WebKeys.THEME_DISPLAY);
132    
133                            _contentsLanguageId = themeDisplay.getLanguageId();
134                    }
135    
136                    String cssClasses = "portlet ";
137    
138                    Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
139    
140                    if (portlet != null) {
141                            cssClasses += portlet.getCssClassWrapper();
142                    }
143    
144                    String editorImpl = EditorUtil.getEditorValue(request, _editorImpl);
145    
146                    _page = "/html/js/editor/" + editorImpl + ".jsp";
147    
148                    request.setAttribute(
149                            "liferay-ui:input-editor:configParams", _configParams);
150                    request.setAttribute(
151                            "liferay-ui:input-editor:contentsLanguageId", _contentsLanguageId);
152                    request.setAttribute("liferay-ui:input-editor:cssClass", _cssClass);
153                    request.setAttribute("liferay-ui:input-editor:cssClasses", cssClasses);
154                    request.setAttribute("liferay-ui:input-editor:editorImpl", editorImpl);
155                    request.setAttribute(
156                            "liferay-ui:input-editor:fileBrowserParams", _fileBrowserParams);
157    
158                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
159                            WebKeys.THEME_DISPLAY);
160    
161                    long groupId = themeDisplay.getDoAsGroupId();
162    
163                    if (groupId == 0) {
164                            groupId = themeDisplay.getScopeGroupId();
165                    }
166    
167                    request.setAttribute("liferay-ui:input-editor:groupId", groupId);
168                    request.setAttribute("liferay-ui:input-editor:height", _height);
169                    request.setAttribute("liferay-ui:input-editor:initMethod", _initMethod);
170                    request.setAttribute(
171                            "liferay-ui:input-editor:inlineEdit", String.valueOf(_inlineEdit));
172                    request.setAttribute(
173                            "liferay-ui:input-editor:inlineEditSaveURL", _inlineEditSaveURL);
174                    request.setAttribute("liferay-ui:input-editor:name", _name);
175                    request.setAttribute(
176                            "liferay-ui:input-editor:onBlurMethod", _onBlurMethod);
177                    request.setAttribute(
178                            "liferay-ui:input-editor:onChangeMethod", _onChangeMethod);
179                    request.setAttribute(
180                            "liferay-ui:input-editor:onFocusMethod", _onFocusMethod);
181                    request.setAttribute(
182                            "liferay-ui:input-editor:resizable", String.valueOf(_resizable));
183                    request.setAttribute(
184                            "liferay-ui:input-editor:skipEditorLoading",
185                            String.valueOf(_skipEditorLoading));
186                    request.setAttribute("liferay-ui:input-editor:toolbarSet", _toolbarSet);
187                    request.setAttribute("liferay-ui:input-editor:width", _width);
188            }
189    
190            private Map<String, String> _configParams;
191            private String _contentsLanguageId;
192            private String _cssClass;
193            private String _editorImpl;
194            private Map<String, String> _fileBrowserParams;
195            private String _height;
196            private String _initMethod = "initEditor";
197            private boolean _inlineEdit;
198            private String _inlineEditSaveURL;
199            private String _name = "editor";
200            private String _onBlurMethod;
201            private String _onChangeMethod;
202            private String _onFocusMethod;
203            private String _page;
204            private boolean _resizable = true;
205            private boolean _skipEditorLoading;
206            private String _toolbarSet = "liferay";
207            private String _width;
208    
209    }