View Javadoc

1   /*
2    * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3    * Copyright (C) 2004-2009 Frederico Caldeira Knabben
4    * 
5    * == BEGIN LICENSE ==
6    * 
7    * Licensed under the terms of any of the following licenses at your
8    * choice:
9    * 
10   *  - GNU General Public License Version 2 or later (the "GPL")
11   *    http://www.gnu.org/licenses/gpl.html
12   * 
13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14   *    http://www.gnu.org/licenses/lgpl.html
15   * 
16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
17   *    http://www.mozilla.org/MPL/MPL-1.1.html
18   * 
19   * == END LICENSE ==
20   */
21  package net.fckeditor.tags;
22  
23  import java.io.IOException;
24  import java.util.Map;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.JspWriter;
29  import javax.servlet.jsp.tagext.TagSupport;
30  
31  import net.fckeditor.FCKeditor;
32  import net.fckeditor.tool.Utils;
33  
34  /**
35   * Tag creates and configures a {@link FCKeditor} instance. The setter methods
36   * are the same as in the FCKeditor class itself.
37   * 
38   * @version $Id: EditorTag.java 3695 2009-06-18 20:18:38Z mosipov $
39   */
40  public class EditorTag extends TagSupport {
41  
42  	private static final long serialVersionUID = -173091731589866140L;
43  
44  	private String instanceName;
45  	private String width;
46  	private String height;
47  	private String toolbarSet;
48  	private String value;
49  	private String basePath;
50  
51  	/** The underlying FCKeditor instance */
52  	private transient FCKeditor fckEditor;
53  
54  	/**
55  	 * @see FCKeditor#setInstanceName(String)
56  	 */
57  	public void setInstanceName(String instanceName) {
58  		this.instanceName = instanceName;
59  	}
60  
61  	/**
62  	 * @see FCKeditor#setWidth(String)
63  	 */
64  	public void setWidth(String width) {
65  		this.width = width;
66  	}
67  
68  	/**
69  	 * @see FCKeditor#setHeight(String)
70  	 */
71  	public void setHeight(String height) {
72  		this.height = height;
73  	}
74  
75  	/**
76  	 * @see FCKeditor#setToolbarSet(String)
77  	 */
78  	public void setToolbarSet(String toolbarSet) {
79  		this.toolbarSet = toolbarSet;
80  	}
81  
82  	/**
83  	 * @see FCKeditor#setValue(String)
84  	 */
85  	public void setValue(String value) {
86  		this.value = value;
87  	}
88  
89  	/**
90  	 * @see FCKeditor#setBasePath(String)
91  	 */
92  	public void setBasePath(String basePath) {
93  		this.basePath = basePath;
94  	}
95  
96  	/**
97  	 * @see FCKeditor#setConfig(String, String)
98  	 * @deprecated method will be removed in FCKeditor.Java 2.6, use
99  	 *             {@link #setConfig(String, String)}
100 	 */
101 	@Deprecated
102 	void setConfigParamAll(Map<String, String> map) {
103 		fckEditor.getConfig().putAll(map);
104 	}
105 
106 	/**
107 	 * @see FCKeditor#setConfig(String, String)
108 	 */
109 	void setConfig(String name, String value) {
110 		fckEditor.setConfig(name, value);
111 	}
112 
113 	@Override
114 	public int doStartTag() throws JspException {
115 
116 		try {
117 			fckEditor = new FCKeditor((HttpServletRequest) pageContext
118 					.getRequest(), instanceName);
119 
120 			if (Utils.isNotEmpty(width))
121 				fckEditor.setWidth(width);
122 			if (Utils.isNotEmpty(height))
123 				fckEditor.setHeight(height);
124 			if (Utils.isNotEmpty(toolbarSet))
125 				fckEditor.setToolbarSet(toolbarSet);
126 			if (Utils.isNotEmpty(value))
127 				fckEditor.setValue(value);
128 			if (Utils.isNotEmpty(basePath))
129 				fckEditor.setBasePath(basePath);
130 
131 		} catch (Exception e) {
132 			throw new JspException(e);
133 		}
134 
135 		return EVAL_BODY_INCLUDE;
136 	}
137 
138 	@Override
139 	public int doEndTag() throws JspException {
140 
141 		JspWriter out = pageContext.getOut();
142 
143 		try {
144 			out.println(fckEditor);
145 		} catch (IOException e) {
146 			throw new JspException(
147 					"Tag response could not be written to the user!", e);
148 		}
149 
150 		return EVAL_PAGE;
151 	}
152 
153 }