View Javadoc

1   /*
2    * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3    * Copyright (C) 2004-2010 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  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.JspWriter;
28  import javax.servlet.jsp.tagext.TagSupport;
29  
30  import net.fckeditor.FCKeditor;
31  import net.fckeditor.tool.Utils;
32  
33  /**
34   * Tag creates and configures a {@link FCKeditor} instance. The setter methods
35   * are the same as in the FCKeditor class itself.
36   * 
37   * @version $Id: EditorTag.java 4785 2009-12-21 20:10:28Z mosipov $
38   */
39  public class EditorTag extends TagSupport {
40  
41  	private static final long serialVersionUID = -173091731589866140L;
42  
43  	private String instanceName;
44  	private String inputName;
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#setInputName(String) 
63  	 */
64  	public void setInputName(String inputName) {
65  		this.inputName = inputName;
66  	}
67  
68  	/**
69  	 * @see FCKeditor#setWidth(String)
70  	 */
71  	public void setWidth(String width) {
72  		this.width = width;
73  	}
74  
75  	/**
76  	 * @see FCKeditor#setHeight(String)
77  	 */
78  	public void setHeight(String height) {
79  		this.height = height;
80  	}
81  
82  	/**
83  	 * @see FCKeditor#setToolbarSet(String)
84  	 */
85  	public void setToolbarSet(String toolbarSet) {
86  		this.toolbarSet = toolbarSet;
87  	}
88  
89  	/**
90  	 * @see FCKeditor#setValue(String)
91  	 */
92  	public void setValue(String value) {
93  		this.value = value;
94  	}
95  
96  	/**
97  	 * @see FCKeditor#setBasePath(String)
98  	 */
99  	public void setBasePath(String basePath) {
100 		this.basePath = basePath;
101 	}
102 
103 	/**
104 	 * @see FCKeditor#setConfig(String, String)
105 	 */
106 	void setConfig(String name, String value) {
107 		fckEditor.setConfig(name, value);
108 	}
109 
110 	@Override
111 	public int doStartTag() throws JspException {
112 
113 		try {
114 			fckEditor = new FCKeditor((HttpServletRequest) pageContext
115 					.getRequest(), instanceName, inputName);
116 
117 			if (Utils.isNotEmpty(width))
118 				fckEditor.setWidth(width);
119 			if (Utils.isNotEmpty(height))
120 				fckEditor.setHeight(height);
121 			if (Utils.isNotEmpty(toolbarSet))
122 				fckEditor.setToolbarSet(toolbarSet);
123 			if (Utils.isNotEmpty(value))
124 				fckEditor.setValue(value);
125 			if (Utils.isNotEmpty(basePath))
126 				fckEditor.setBasePath(basePath);
127 
128 		} catch (Exception e) {
129 			throw new JspException(e);
130 		}
131 
132 		return EVAL_BODY_INCLUDE;
133 	}
134 
135 	@Override
136 	public int doEndTag() throws JspException {
137 
138 		JspWriter out = pageContext.getOut();
139 
140 		try {
141 			out.println(fckEditor);
142 		} catch (IOException e) {
143 			throw new JspException(
144 					"Tag response could not be written to the user!", e);
145 		}
146 
147 		return EVAL_PAGE;
148 	}
149 
150 }