Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ConfigTag |
|
| 3.0;3 |
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.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 3594 2009-06-01 18:50:07Z mosipov $ | |
38 | */ | |
39 | 0 | public class ConfigTag extends TagSupport implements DynamicAttributes { |
40 | ||
41 | 0 | 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 | 0 | Tag ancestor = findAncestorWithClass(this, EditorTag.class); |
49 | 0 | if (ancestor == null) |
50 | 0 | throw new JspException( |
51 | "the config tag can only be nested within an editor tag"); | |
52 | 0 | EditorTag editorTag = (EditorTag) ancestor; |
53 | ||
54 | 0 | for (Map.Entry<String, String> option : params.entrySet()) |
55 | 0 | editorTag.setConfig(option.getKey(), option.getValue()); |
56 | ||
57 | 0 | 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 | 0 | if (value != null) |
66 | 0 | params.put(name, value.toString()); |
67 | 0 | } |
68 | ||
69 | } |