1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.tree.taglib;
20
21 import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
22 import org.apache.myfaces.custom.tree.HtmlTree;
23 import org.apache.myfaces.custom.tree.IconProvider;
24
25 import javax.faces.component.UIComponent;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28 import javax.faces.webapp.UIComponentTag;
29 import javax.servlet.jsp.JspException;
30 import javax.servlet.jsp.tagext.Tag;
31 import javax.servlet.jsp.tagext.TagSupport;
32
33
34
35
36
37
38
39
40
41
42
43 public class IconProviderTag
44 extends TagSupport
45 {
46 private static final long serialVersionUID = -8851450834386187922L;
47 private String type = null;
48
49
50 public IconProviderTag()
51 {
52 }
53
54
55
56
57
58 public void setType(String type)
59 {
60 this.type = type;
61 }
62
63
64 public int doStartTag() throws JspException
65 {
66 if (type == null)
67 {
68 throw new JspException("type attribute not set");
69 }
70
71
72 UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
73 if (componentTag == null)
74 {
75 throw new JspException("IconProviderTag has no UIComponentTag ancestor");
76 }
77
78 UIComponent component = componentTag.getComponentInstance();
79 if (component instanceof HtmlTree)
80 {
81 String className;
82 if (UIComponentTag.isValueReference(type))
83 {
84 FacesContext facesContext = FacesContext.getCurrentInstance();
85 ValueBinding vb = facesContext.getApplication().createValueBinding(type);
86 className = (String) vb.getValue(facesContext);
87 } else
88 {
89 className = type;
90 }
91 IconProvider provider = (IconProvider) ClassUtils.newInstance(className);
92 ((HtmlTree) component).setIconProvider(provider);
93 } else
94 {
95 throw new JspException("Component " + component.getId() + " is no HtmlTree");
96 }
97
98 return Tag.SKIP_BODY;
99 }
100 }