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