KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > tree > taglib > IconProviderTag


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.tree.taglib;
17
18 import org.apache.myfaces.util.ClassUtils;
19 import org.apache.myfaces.custom.tree.HtmlTree;
20 import org.apache.myfaces.custom.tree.IconProvider;
21
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.faces.el.ValueBinding;
25 import javax.faces.webapp.UIComponentTag;
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.tagext.Tag JavaDoc;
28 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
29
30
31 /**
32  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
33  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:58 $
34  * $Log: IconProviderTag.java,v $
35  * Revision 1.3 2004/10/13 11:50:58 matze
36  * renamed packages to org.apache
37  *
38  * Revision 1.2 2004/07/01 21:53:06 mwessendorf
39  * ASF switch
40  *
41  * Revision 1.1 2004/05/04 12:19:14 o_rossmueller
42  * added icon provider
43  *
44  */

45 public class IconProviderTag
46     extends TagSupport JavaDoc
47 {
48
49     private String JavaDoc type = null;
50
51
52     public IconProviderTag()
53     {
54     }
55
56
57     public void setType(String JavaDoc type)
58     {
59         this.type = type;
60     }
61
62
63     public int doStartTag() throws JspException JavaDoc
64     {
65         if (type == null)
66         {
67             throw new JspException JavaDoc("type attribute not set");
68         }
69
70         //Find parent UIComponentTag
71
UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
72         if (componentTag == null)
73         {
74             throw new JspException JavaDoc("IconProviderTag has no UIComponentTag ancestor");
75         }
76
77         UIComponent component = componentTag.getComponentInstance();
78         if (component instanceof HtmlTree)
79         {
80             String JavaDoc className;
81             if (UIComponentTag.isValueReference(type))
82             {
83                 FacesContext facesContext = FacesContext.getCurrentInstance();
84                 ValueBinding vb = facesContext.getApplication().createValueBinding(type);
85                 className = (String JavaDoc) vb.getValue(facesContext);
86             } else
87             {
88                 className = type;
89             }
90             IconProvider provider = (IconProvider) ClassUtils.newInstance(className);
91             ((HtmlTree) component).setIconProvider(provider);
92         } else
93         {
94             throw new JspException JavaDoc("Component " + component.getId() + " is no HtmlTree");
95         }
96
97         return Tag.SKIP_BODY;
98     }
99 }
100
Popular Tags