KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > layer > LayerItemTag


1 package fr.improve.struts.taglib.layout.layer;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.LayoutTagSupport;
6 import fr.improve.struts.taglib.layout.collection.CollectionTag;
7 import fr.improve.struts.taglib.layout.el.Expression;
8 import fr.improve.struts.taglib.layout.util.LayoutUtils;
9 import fr.improve.struts.taglib.layout.util.ParentFinder;
10
11 /**
12  * This tag allow you to apply in a layer differents properties from a bean
13  * inside ou outside a collection
14  *
15  * @author: Damien Viel, Jean-Noel Ribette
16  **/

17 public class LayerItemTag extends LayoutTagSupport {
18     
19     private String JavaDoc name;
20     private String JavaDoc property;
21     private String JavaDoc key;
22     private String JavaDoc value;
23     private String JavaDoc JSPValue;
24     
25     /* (non-Javadoc)
26      * @see fr.improve.struts.taglib.layout.LayoutTagSupport#initDynamicValues()
27      */

28     protected void initDynamicValues() {
29         JSPValue = value;
30         value = Expression.evaluate(value,pageContext);
31         super.initDynamicValues();
32     }
33     
34     /* (non-Javadoc)
35      * @see fr.improve.struts.taglib.layout.LayoutTagSupport#reset()
36      */

37     protected void reset() {
38         value = JSPValue;
39         JSPValue = null;
40     }
41     
42     /**
43      * @return Returns the key.
44      */

45     public String JavaDoc getKey() {
46         return key;
47     }
48     /**
49      * @param key The key to set.
50      */

51     public void setKey(String JavaDoc key) {
52         this.key = key;
53     }
54     /**
55      * @return Returns the name.
56      */

57     public String JavaDoc getName() {
58         return name;
59     }
60     /**
61      * @param name The name to set.
62      */

63     public void setName(String JavaDoc name) {
64         this.name = name;
65     }
66     /**
67      * @return Returns the property.
68      */

69     public String JavaDoc getProperty() {
70         return property;
71     }
72     /**
73      * @param property The property to set.
74      */

75     public void setProperty(String JavaDoc property) {
76         this.property = property;
77     }
78     /**
79      * @return Returns the value.
80      */

81     public String JavaDoc getValue() {
82         return value;
83     }
84     /**
85      * @param value The value to set.
86      */

87     public void setValue(String JavaDoc value) {
88         this.value = value;
89     }
90     protected Object JavaDoc buildContent() throws JspException JavaDoc {
91         Object JavaDoc lc_cell = null;
92         if (value!=null) {
93             return value;
94         }
95         if (name == null) {
96             // The item to add is a property of a bean in the current collection.
97
CollectionTag collectionTag = (CollectionTag) ParentFinder.findLayoutTag(this, CollectionTag.class);
98             lc_cell = collectionTag.getBean();
99         } else {
100             // The item to add is a property of a bean in the context.
101
lc_cell = pageContext.findAttribute(name);
102         }
103         if (lc_cell != null && property != null) {
104             // Get the property of the bean.
105
lc_cell = getPropertyValue(lc_cell, property);
106         }
107         return lc_cell;
108     }
109     
110     /**
111      * This method simply uses BeanUtils (indirectly) to return the value of the property 'in_property'
112      * of in_bean. This method is intended to be overrided if needed.
113      */

114     protected Object JavaDoc getPropertyValue(Object JavaDoc in_bean, String JavaDoc in_property) throws JspException JavaDoc {
115         return LayoutUtils.getProperty(in_bean, in_property);
116     }
117     
118     
119     /* (non-Javadoc)
120      * @see fr.improve.struts.taglib.layout.LayoutTagSupport#doEndLayoutTag()
121      */

122     public int doEndLayoutTag() throws JspException JavaDoc {
123         
124         return super.doEndLayoutTag();
125     }
126     /* (non-Javadoc)
127      * @see fr.improve.struts.taglib.layout.LayoutTagSupport#doStartLayoutTag()
128      */

129     public int doStartLayoutTag() throws JspException JavaDoc {
130         StringBuffer JavaDoc results = new StringBuffer JavaDoc("");
131         String JavaDoc lc_key = LayoutUtils.getLabel(pageContext,getKey(),null);
132         Object JavaDoc lc_contentObject = buildContent();
133         String JavaDoc lc_content = lc_contentObject==null ? null : lc_contentObject.toString();
134         
135         if (lc_key!=null){
136             results.append(lc_key);
137         }
138         if (lc_content!=null && lc_content.length()>0){
139             results.append(lc_content);
140         }
141         LayerTag lc_layerTag = (LayerTag) ParentFinder.findLayoutTag(this, LayerTag.class);
142         lc_layerTag.addContent(results.toString());
143         return (EVAL_BODY_INCLUDE);
144     }
145     
146 }
Popular Tags