Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ParamTag |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2008 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.cubby.tags; | |
17 | ||
18 | import java.io.IOException; | |
19 | import java.io.StringWriter; | |
20 | ||
21 | import javax.servlet.jsp.JspException; | |
22 | import javax.servlet.jsp.tagext.SimpleTagSupport; | |
23 | ||
24 | import org.seasar.framework.message.MessageFormatter; | |
25 | ||
26 | /** | |
27 | * パラメータを指定するためのカスタムタグです。 | |
28 | * | |
29 | * @author baba | |
30 | * @since 1.1.0 | |
31 | */ | |
32 | 12 | public class ParamTag extends SimpleTagSupport { |
33 | ||
34 | /** パラメータ名。 */ | |
35 | private String name; | |
36 | ||
37 | /** 値。 */ | |
38 | private String value; | |
39 | ||
40 | /** | |
41 | * パラメータ名を設定します。 | |
42 | * | |
43 | * @param name | |
44 | * パラメータ名 | |
45 | */ | |
46 | public void setName(final String name) { | |
47 | 12 | this.name = name; |
48 | 12 | } |
49 | ||
50 | /** | |
51 | * 値を設定します。 | |
52 | * | |
53 | * @param value | |
54 | * 値 | |
55 | */ | |
56 | public void setValue(final String value) { | |
57 | 11 | this.value = value; |
58 | 11 | } |
59 | ||
60 | /** | |
61 | * {@inheritDoc} | |
62 | */ | |
63 | @Override | |
64 | public void doTag() throws JspException, IOException { | |
65 | 12 | final ParamParent parent = (ParamParent) findAncestorWithClass(this, |
66 | ParamParent.class); | |
67 | 12 | if (parent == null) { |
68 | 2 | throw new JspException(MessageFormatter.getSimpleMessage( |
69 | "ECUB1004", null)); | |
70 | } | |
71 | final String value; | |
72 | 10 | if (this.value == null) { |
73 | 1 | StringWriter writer = new StringWriter(); |
74 | 1 | getJspBody().invoke(writer); |
75 | 1 | value = writer.toString().trim(); |
76 | 1 | } else { |
77 | 9 | value = this.value; |
78 | } | |
79 | 10 | parent.addParameter(name, value); |
80 | 10 | } |
81 | ||
82 | } |