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