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.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 setAllowBrowseDocuments(boolean allowBrowseDocuments) {
033                    _allowBrowseDocuments = allowBrowseDocuments;
034            }
035    
036            public void setConfigParams(Map<String, String> configParams) {
037                    _configParams = configParams;
038            }
039    
040            public void setContents(String contents) {
041                    _contents = contents;
042            }
043    
044            public void setContentsLanguageId(String contentsLanguageId) {
045                    _contentsLanguageId = contentsLanguageId;
046            }
047    
048            public void setCssClass(String cssClass) {
049                    _cssClass = cssClass;
050            }
051    
052            public void setData(Map<String, Object> data) {
053                    _data = data;
054            }
055    
056            public void setEditorImpl(String editorImpl) {
057                    _editorImpl = editorImpl;
058            }
059    
060            public void setFileBrowserParams(Map<String, String> fileBrowserParams) {
061                    _fileBrowserParams = fileBrowserParams;
062            }
063    
064            public void setHeight(String height) {
065                    _height = height;
066            }
067    
068            /**
069             * @deprecated As of 7.0.0, replaced by {@link #setContents(String)}
070             */
071            @Deprecated
072            public void setInitMethod(String initMethod) {
073                    _initMethod = initMethod;
074            }
075    
076            public void setInlineEdit(boolean inlineEdit) {
077                    _inlineEdit = inlineEdit;
078            }
079    
080            public void setInlineEditSaveURL(String inlineEditSaveURL) {
081                    _inlineEditSaveURL = inlineEditSaveURL;
082            }
083    
084            public void setName(String name) {
085                    _name = name;
086            }
087    
088            public void setOnBlurMethod(String onBlurMethod) {
089                    _onBlurMethod = onBlurMethod;
090            }
091    
092            public void setOnChangeMethod(String onChangeMethod) {
093                    _onChangeMethod = onChangeMethod;
094            }
095    
096            public void setOnFocusMethod(String onFocusMethod) {
097                    _onFocusMethod = onFocusMethod;
098            }
099    
100            public void setOnInitMethod(String onInitMethod) {
101                    _onInitMethod = onInitMethod;
102            }
103    
104            public void setPlaceholder(String placeholder) {
105                    _placeholder = placeholder;
106            }
107    
108            public void setResizable(boolean resizable) {
109                    _resizable = resizable;
110            }
111    
112            public void setSkipEditorLoading(boolean skipEditorLoading) {
113                    _skipEditorLoading = skipEditorLoading;
114            }
115    
116            public void setToolbarSet(String toolbarSet) {
117                    _toolbarSet = toolbarSet;
118            }
119    
120            public void setWidth(String width) {
121                    _width = width;
122            }
123    
124            @Override
125            protected void cleanUp() {
126                    _allowBrowseDocuments = true;
127                    _configParams = null;
128                    _contents = null;
129                    _contentsLanguageId = null;
130                    _cssClass = null;
131                    _data = null;
132                    _editorImpl = null;
133                    _fileBrowserParams = null;
134                    _height = null;
135                    _initMethod = "initEditor";
136                    _inlineEdit = false;
137                    _inlineEditSaveURL = null;
138                    _name = "editor";
139                    _onChangeMethod = null;
140                    _onBlurMethod = null;
141                    _onFocusMethod = null;
142                    _onInitMethod = null;
143                    _page = null;
144                    _placeholder = null;
145                    _resizable = true;
146                    _skipEditorLoading = false;
147                    _toolbarSet = "liferay";
148                    _width = null;
149            }
150    
151            @Override
152            protected String getPage() {
153                    return _page;
154            }
155    
156            @Override
157            protected void setAttributes(HttpServletRequest request) {
158                    if (_contentsLanguageId == null) {
159                            ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
160                                    WebKeys.THEME_DISPLAY);
161    
162                            _contentsLanguageId = themeDisplay.getLanguageId();
163                    }
164    
165                    String cssClasses = "portlet ";
166    
167                    Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
168    
169                    if (portlet != null) {
170                            cssClasses += portlet.getCssClassWrapper();
171                    }
172    
173                    String editorImpl = EditorUtil.getEditorValue(request, _editorImpl);
174    
175                    _page = "/html/js/editor/" + editorImpl + ".jsp";
176    
177                    request.setAttribute(
178                            "liferay-ui:input-editor:allowBrowseDocuments",
179                            String.valueOf(_allowBrowseDocuments));
180                    request.setAttribute(
181                            "liferay-ui:input-editor:configParams", _configParams);
182                    request.setAttribute("liferay-ui:input-editor:contents", _contents);
183                    request.setAttribute(
184                            "liferay-ui:input-editor:contentsLanguageId", _contentsLanguageId);
185                    request.setAttribute("liferay-ui:input-editor:cssClass", _cssClass);
186                    request.setAttribute("liferay-ui:input-editor:cssClasses", cssClasses);
187                    request.setAttribute("liferay-ui:input-editor:data", _data);
188                    request.setAttribute("liferay-ui:input-editor:editorImpl", editorImpl);
189                    request.setAttribute(
190                            "liferay-ui:input-editor:fileBrowserParams", _fileBrowserParams);
191                    request.setAttribute("liferay-ui:input-editor:height", _height);
192                    request.setAttribute("liferay-ui:input-editor:initMethod", _initMethod);
193                    request.setAttribute(
194                            "liferay-ui:input-editor:inlineEdit", String.valueOf(_inlineEdit));
195                    request.setAttribute(
196                            "liferay-ui:input-editor:inlineEditSaveURL", _inlineEditSaveURL);
197                    request.setAttribute("liferay-ui:input-editor:name", _name);
198                    request.setAttribute(
199                            "liferay-ui:input-editor:onBlurMethod", _onBlurMethod);
200                    request.setAttribute(
201                            "liferay-ui:input-editor:onChangeMethod", _onChangeMethod);
202                    request.setAttribute(
203                            "liferay-ui:input-editor:onFocusMethod", _onFocusMethod);
204                    request.setAttribute(
205                            "liferay-ui:input-editor:onInitMethod", _onInitMethod);
206                    request.setAttribute(
207                            "liferay-ui:input-editor:placeholder", _placeholder);
208                    request.setAttribute(
209                            "liferay-ui:input-editor:resizable", String.valueOf(_resizable));
210                    request.setAttribute(
211                            "liferay-ui:input-editor:skipEditorLoading",
212                            String.valueOf(_skipEditorLoading));
213                    request.setAttribute("liferay-ui:input-editor:toolbarSet", _toolbarSet);
214                    request.setAttribute("liferay-ui:input-editor:width", _width);
215            }
216    
217            private boolean _allowBrowseDocuments = true;
218            private Map<String, String> _configParams;
219            private String _contents;
220            private String _contentsLanguageId;
221            private String _cssClass;
222            private Map<String, Object> _data = null;
223            private String _editorImpl;
224            private Map<String, String> _fileBrowserParams;
225            private String _height;
226            private String _initMethod = "initEditor";
227            private boolean _inlineEdit;
228            private String _inlineEditSaveURL;
229            private String _name = "editor";
230            private String _onBlurMethod;
231            private String _onChangeMethod;
232            private String _onFocusMethod;
233            private String _onInitMethod;
234            private String _page;
235            private String _placeholder;
236            private boolean _resizable = true;
237            private boolean _skipEditorLoading;
238            private String _toolbarSet = "liferay";
239            private String _width;
240    
241    }