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