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 setName(String name) {
056                    _name = name;
057            }
058    
059            public void setOnChangeMethod(String onChangeMethod) {
060                    _onChangeMethod = onChangeMethod;
061            }
062    
063            public void setResizable(boolean resizable) {
064                    _resizable = resizable;
065            }
066    
067            public void setSkipEditorLoading(boolean skipEditorLoading) {
068                    _skipEditorLoading = skipEditorLoading;
069            }
070    
071            public void setToolbarSet(String toolbarSet) {
072                    _toolbarSet = toolbarSet;
073            }
074    
075            public void setWidth(String width) {
076                    _width = width;
077            }
078    
079            @Override
080            protected void cleanUp() {
081                    _configParams = null;
082                    _cssClass = null;
083                    _editorImpl = null;
084                    _fileBrowserParams = null;
085                    _height = null;
086                    _initMethod = "initEditor";
087                    _name = "editor";
088                    _onChangeMethod = null;
089                    _page = null;
090                    _resizable = true;
091                    _skipEditorLoading = false;
092                    _toolbarSet = "liferay";
093                    _width = null;
094            }
095    
096            @Override
097            protected String getPage() {
098                    return _page;
099            }
100    
101            @Override
102            protected void setAttributes(HttpServletRequest request) {
103                    String cssClasses = "portlet ";
104    
105                    Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET);
106    
107                    if (portlet != null) {
108                            cssClasses += portlet.getCssClassWrapper();
109                    }
110    
111                    String editorImpl = EditorUtil.getEditorValue(request, _editorImpl);
112    
113                    _page = "/html/js/editor/" + editorImpl + ".jsp";
114    
115                    request.setAttribute(
116                            "liferay-ui:input-editor:configParams", _configParams);
117                    request.setAttribute("liferay-ui:input-editor:cssClass", _cssClass);
118                    request.setAttribute("liferay-ui:input-editor:cssClasses", cssClasses);
119                    request.setAttribute("liferay-ui:input-editor:editorImpl", editorImpl);
120                    request.setAttribute(
121                            "liferay-ui:input-editor:fileBrowserParams", _fileBrowserParams);
122                    request.setAttribute("liferay-ui:input-editor:height", _height);
123                    request.setAttribute("liferay-ui:input-editor:initMethod", _initMethod);
124                    request.setAttribute("liferay-ui:input-editor:name", _name);
125                    request.setAttribute(
126                            "liferay-ui:input-editor:onChangeMethod", _onChangeMethod);
127                    request.setAttribute(
128                            "liferay-ui:input-editor:resizable", String.valueOf(_resizable));
129                    request.setAttribute(
130                            "liferay-ui:input-editor:skipEditorLoading",
131                            String.valueOf(_skipEditorLoading));
132                    request.setAttribute("liferay-ui:input-editor:toolbarSet", _toolbarSet);
133                    request.setAttribute("liferay-ui:input-editor:width", _width);
134            }
135    
136            private Map<String, String> _configParams;
137            private String _cssClass;
138            private String _editorImpl;
139            private Map<String, String> _fileBrowserParams;
140            private String _height;
141            private String _initMethod = "initEditor";
142            private String _name = "editor";
143            private String _onChangeMethod;
144            private String _page;
145            private boolean _resizable = true;
146            private boolean _skipEditorLoading;
147            private String _toolbarSet = "liferay";
148            private String _width;
149    
150    }