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