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.util.HashMap;
24  import java.util.Map;
25  
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.tagext.DynamicAttributes;
28  import javax.servlet.jsp.tagext.Tag;
29  import javax.servlet.jsp.tagext.TagSupport;
30  
31  import net.fckeditor.FCKeditorConfig;
32  
33  /**
34   * Sets {@link FCKeditorConfig configuration options} in the surrounding editor
35   * tag only.
36   * 
37   * @version $Id: ConfigTag.java 4785 2009-12-21 20:10:28Z mosipov $
38   */
39  public class ConfigTag extends TagSupport implements DynamicAttributes {
40  
41  	private Map<String, String> params = new HashMap<String, String>();
42  
43  	private static final long serialVersionUID = -5282810094404700422L;
44  
45  	@Override
46  	public int doStartTag() throws JspException {
47  
48  		Tag ancestor = findAncestorWithClass(this, EditorTag.class);
49  		if (ancestor == null)
50  			throw new JspException(
51  					"the config tag can only be nested within an editor tag");
52  		EditorTag editorTag = (EditorTag) ancestor;
53  
54  		for (Map.Entry<String, String> option : params.entrySet())
55  			editorTag.setConfig(option.getKey(), option.getValue());
56  
57  		return SKIP_BODY;
58  	}
59  
60  	/**
61  	 * Sets a configuration option.
62  	 */
63  	public void setDynamicAttribute(String arg0, String name, Object value)
64  			throws JspException {
65  		if (value != null)
66  			params.put(name, value.toString());
67  	}
68  
69  }