001    /**
002     * Copyright (c) 2000-2012 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 setCssClass(String cssClass) {
036                    _cssClass = cssClass;
037            }
038    
039            public void setEditorImpl(String editorImpl) {
040                    _editorImpl = editorImpl;
041            }
042    
043            public void setFileBrowserParams(Map<String, String> fileBrowserParams) {
044                    _fileBrowserParams = fileBrowserParams;
045            }
046    
047            public void setHeight(String height) {
048                    _height = height;
049            }
050    
051            public void setInitMethod(String initMethod) {
052                    _initMethod = initMethod;
053            }
054    
055            public void setInlineEdit(boolean inlineEdit) {
056                    _inlineEdit = inlineEdit;
057            }
058    
059            public void setInlineEditSaveURL(String inlineEditSaveURL) {
060                    _inlineEditSaveURL = inlineEditSaveURL;
061            }
062    
063            public void setName(String name) {
064                    _name = name;
065            }
066    
067            public void setOnChangeMethod(String onChangeMethod) {
068                    _onChangeMethod = onChangeMethod;
069            }
070    
071            public void setResizable(boolean resizable) {
072                    _resizable = resizable;
073            }
074    
075            public void setSkipEditorLoading(boolean skipEditorLoading) {
076                    _skipEditorLoading = skipEditorLoading;
077            }
078    
079            public void setToolbarSet(String toolbarSet) {
080                    _toolbarSet = toolbarSet;
081            }
082    
083            public void setWidth(String width) {
084                    _width = width;
085            }
086    
087            @Override
088            protected void cleanUp() {
089                    _configParams = null;
090                    _cssClass = null;
091                    _editorImpl = null;
092                    _fileBrowserParams = null;
093                    _height = null;
094                    _initMethod = "initEditor";
095                    _inlineEdit = false;
096                    _inlineEditSaveURL = null;
097                    _name = "editor";
098                    _onChangeMethod = null;
099                    _page = null;
100                    _resizable = true;
101                    _skipEditorLoading = false;
102                    _toolbarSet = "liferay";
103                    _width = null;
104            }
105    
106            @Override
107            protected String getPage() {
108                    return _page;
109            }
110    
111            @Override
112            protected void setAttributes(HttpServletRequest request) {
113                    String cssClasses = "portlet ";
114    
115                    Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
116    
117                    if (portlet != null) {
118                            cssClasses += portlet.getCssClassWrapper();
119                    }
120    
121                    String editorImpl = EditorUtil.getEditorValue(request, _editorImpl);
122    
123                    _page = "/html/js/editor/" + editorImpl + ".jsp";
124    
125                    request.setAttribute(
126                            "liferay-ui:input-editor:configParams", _configParams);
127                    request.setAttribute("liferay-ui:input-editor:cssClass", _cssClass);
128                    request.setAttribute("liferay-ui:input-editor:cssClasses", cssClasses);
129                    request.setAttribute("liferay-ui:input-editor:editorImpl", editorImpl);
130                    request.setAttribute(
131                            "liferay-ui:input-editor:fileBrowserParams", _fileBrowserParams);
132                    request.setAttribute("liferay-ui:input-editor:height", _height);
133                    request.setAttribute("liferay-ui:input-editor:initMethod", _initMethod);
134                    request.setAttribute(
135                            "liferay-ui:input-editor:inlineEdit", String.valueOf(_inlineEdit));
136                    request.setAttribute(
137                            "liferay-ui:input-editor:inlineEditSaveURL", _inlineEditSaveURL);
138                    request.setAttribute("liferay-ui:input-editor:name", _name);
139                    request.setAttribute(
140                            "liferay-ui:input-editor:onChangeMethod", _onChangeMethod);
141                    request.setAttribute(
142                            "liferay-ui:input-editor:resizable", String.valueOf(_resizable));
143                    request.setAttribute(
144                            "liferay-ui:input-editor:skipEditorLoading",
145                            String.valueOf(_skipEditorLoading));
146                    request.setAttribute("liferay-ui:input-editor:toolbarSet", _toolbarSet);
147                    request.setAttribute("liferay-ui:input-editor:width", _width);
148            }
149    
150            private Map<String, String> _configParams;
151            private String _cssClass;
152            private String _editorImpl;
153            private Map<String, String> _fileBrowserParams;
154            private String _height;
155            private String _initMethod = "initEditor";
156            private boolean _inlineEdit;
157            private String _inlineEditSaveURL;
158            private String _name = "editor";
159            private String _onChangeMethod;
160            private String _page;
161            private boolean _resizable = true;
162            private boolean _skipEditorLoading;
163            private String _toolbarSet = "liferay";
164            private String _width;
165    
166    }