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.util.HashMap;
19 import java.util.Map;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.jsp.JspException;
23 import javax.servlet.jsp.PageContext;
24 import javax.servlet.jsp.tagext.DynamicAttributes;
25 import javax.servlet.jsp.tagext.SimpleTagSupport;
26
27 /**
28 * DynamicAttributesをフィールドに持つタグの基底クラスです。
29 *
30 * @author agata
31 */
32 abstract public class DynamicAttributesTagSupport extends SimpleTagSupport
33 implements DynamicAttributes {
34
35 /**
36 * DynamicAttributes
37 */
38 private Map<String, Object> attrs = new HashMap<String, Object>();
39
40 /**
41 * DynamicAttributesをセットします。
42 * FIXME 現在はuriを無視しているので、必要であれば対応したほうがよいかも
43 */
44 public void setDynamicAttribute(final String uri, final String localName,
45 final Object value) throws JspException {
46 this.attrs.put(localName, value);
47 }
48
49 /**
50 * DynamicAttributesを取得します。
51 *
52 * @return DynamicAttributes
53 */
54 protected Map<String, Object> getDynamicAttribute() {
55 return this.attrs;
56 }
57
58 /**
59 * PageContextを取得します。
60 *
61 * @return PageContext
62 */
63 protected PageContext getPageContext() {
64 return (PageContext) getJspContext();
65 }
66
67 /**
68 * HttpServletRequestを取得します。
69 *
70 * @return HttpServletRequest
71 */
72 protected HttpServletRequest getRequest() {
73 return (HttpServletRequest) getPageContext().getRequest();
74 }
75
76 /**
77 * オブジェクトを文字列に変換します。 オブジェクトが<code>null</code>の場合、空文字を返します。
78 *
79 * @param object
80 * 対象のオブジェクト
81 * @return オブジェクトのtoString結果。
82 */
83 protected static String toString(Object object) {
84 return object == null ? "" : object.toString();
85 }
86
87 }