KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.improve.struts.taglib.layout.layer;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import org.apache.struts.taglib.html.Constants;
6 import org.apache.struts.util.MessageResources;
7
8 import fr.improve.struts.taglib.layout.LayoutTag;
9 import fr.improve.struts.taglib.layout.LayoutTagSupport;
10 import fr.improve.struts.taglib.layout.el.Expression;
11 import fr.improve.struts.taglib.layout.event.EndLayoutEvent;
12 import fr.improve.struts.taglib.layout.event.StartLayoutEvent;
13 import fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent;
14 import fr.improve.struts.taglib.layout.formatter.FormatException;
15 import fr.improve.struts.taglib.layout.util.FormUtilsInterface;
16 import fr.improve.struts.taglib.layout.util.LayoutUtils;
17 import fr.improve.struts.taglib.layout.util.TagUtils;
18
19 public class LayerTag extends LayoutTagSupport implements LayoutTag {
20
21     /**
22      * The message resources for this package.
23      */

24     protected static MessageResources messages = MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
25
26     /**
27      * The JSP bean name for query parameters.
28      */

29     protected String JavaDoc name = null;
30     protected String JavaDoc jspName = null;
31     protected String JavaDoc styleClass = null;
32     protected String JavaDoc jspStyleclass = null;
33     protected String JavaDoc type;
34     
35     protected StringBuffer JavaDoc results;
36     
37     
38     /**
39      * @return Returns the styleClass.
40      */

41     public String JavaDoc getStyleClass() {
42         return styleClass;
43     }
44     /**
45      * @param styleClass The styleClass to set.
46      */

47     public void setStyleClass(String JavaDoc styleClass) {
48         this.styleClass = styleClass;
49     }
50     
51     
52     public String JavaDoc getName() {
53         return (this.name);
54     }
55
56     public void setName(String JavaDoc name) {
57         this.name = name;
58     }
59
60     /**
61      * The JSP bean property name for query parameters.
62      */

63     protected String JavaDoc property = null;
64
65     public String JavaDoc getProperty() {
66         return (this.property);
67     }
68
69     public void setProperty(String JavaDoc property) {
70         this.property = property;
71     }
72
73     
74     /* (non-Javadoc)
75      * @see fr.improve.struts.taglib.layout.LayoutTagSupport#initDynamicValues()
76      */

77     protected void initDynamicValues() {
78         jspStyleclass = styleClass;
79         if (styleClass==null){
80             styleClass = LayoutUtils.getSkin(pageContext.getSession()).getProperty("styleclass.layer",null);
81         }
82         jspName = name;
83         name = Expression.evaluate(name,pageContext);
84         super.initDynamicValues();
85     }
86     
87     /**
88      * Render the beginning of the hyperlink. Indexed property since 1.1
89      *
90      * @exception JspException
91      * if a JSP exception has occurred
92      */

93     public int doStartLayoutTag() throws JspException JavaDoc {
94         Integer JavaDoc i = (Integer JavaDoc)pageContext.getRequest().getAttribute("layerId");
95         if (i==null){
96             i = new Integer JavaDoc(100);
97         }
98         i = new Integer JavaDoc(i.intValue()+1);
99         pageContext.getRequest().setAttribute("layerId",i);
100         
101         results = new StringBuffer JavaDoc("<DIV id='layer" + String.valueOf(i)+ "' style='position:absolute;top:0;left:0;visibility:hidden'>");
102         results.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ");
103         if (getStyleClass()!=null && getStyleClass().length()>0){
104             results.append(" class=\""+ getStyleClass() +"\"");
105         }
106         results.append(">");
107         results.append("<tr>");
108         results.append("<td valign=top");
109         if (getStyleClass()!=null && getStyleClass().length()>0){
110             results.append(" class=\""+ getStyleClass() +"\"");
111         }
112         results.append(">");
113         //ResponseUtils.write(pageContext, results.toString());
114
return (EVAL_BODY_INCLUDE);
115     }
116
117     /**
118      * Render the end of the hyperlink.
119      *
120      * @exception JspException
121      * if a JSP exception has occurred
122      */

123     public int doEndLayoutTag() throws JspException JavaDoc {
124         Integer JavaDoc i = (Integer JavaDoc)pageContext.getRequest().getAttribute("layerId");
125          
126         results.append("</td>");
127         results.append("</tr>");
128         results.append("</table></DIV>");
129         TagUtils.write(pageContext, new StaticCodeIncludeLayoutEvent(this, results.toString()).send().toString());
130         
131         TagUtils.write(pageContext, "<a HREF=\"#\"");
132         TagUtils.write(pageContext, " onmouseover=\"showLayoutLayer('layer" + String.valueOf(i)+ "',event);\"");
133         TagUtils.write(pageContext, " onmouseout=\"hideLayoutLayer('layer" + String.valueOf(i)+ "');\">");
134         
135         Object JavaDoc lc_value = LayoutUtils.getBeanFromPageContext(pageContext, name,property);
136         if (type!=null) try {
137             lc_value = LayoutUtils.getSkin(pageContext.getSession()).getFormatter().format(lc_value, type, pageContext);
138         } catch (FormatException e) {
139             throw new JspException JavaDoc("Format " + type + " failed: " + e.getMessage());
140         }
141         TagUtils.write(pageContext, lc_value==null ? "" : lc_value.toString());
142         TagUtils.write(pageContext, "</a>");
143         return (EVAL_PAGE);
144
145     }
146     
147     public void addContent(String JavaDoc in_content) {
148         results.append(in_content);
149     }
150
151     protected void reset() {
152         showLink = true;
153         name = jspName;
154         jspName = null;
155         styleClass = jspStyleclass;
156         jspStyleclass = null;
157     }
158
159     /**
160      * Prepare to display the link.
161      */

162     protected void beginLinkLayout(StringBuffer JavaDoc in_buffer) throws JspException JavaDoc {
163         in_buffer.append("<td>&nbsp;</td><td");
164         // if (valign!=null) {
165
// in_buffer.append(" valign=\"");
166
// in_buffer.append(valign);
167
// in_buffer.append("\"");
168
// }
169
in_buffer.append(">");
170     }
171
172     /**
173      * End the display of the action.
174      */

175     protected void endLinkLayout(StringBuffer JavaDoc in_buffer) {
176         in_buffer.append("</td>");
177     }
178
179     /**
180      * Release any acquired resources.
181      */

182     public void release() {
183
184         super.release();
185         name = null;
186         property = null;
187         policy = null;
188         display = true;
189         type = null;
190     }
191
192     protected boolean display = true;
193
194     protected boolean showLink = true;
195
196     protected String JavaDoc policy = null;
197
198     /**
199      * Set in wich form modes the action should be displayed or not. The format
200      * form in_mode is X,Y,Z where allowed values are D (Displayed) and N (not
201      * displayed) in the same order as the input field tags.
202      */

203     public void setMode(String JavaDoc in_mode) {
204         if (in_mode == null || in_mode.length() != 5) {
205             throw new IllegalArgumentException JavaDoc("The specified mode" + in_mode
206                     + " is invalid");
207         }
208         int lc_formMode = LayoutUtils.getSkin(pageContext.getSession())
209                 .getFormUtils().getFormDisplayMode(pageContext);
210         char lc_displayMode;
211         switch (lc_formMode) {
212         case FormUtilsInterface.CREATE_MODE:
213             lc_displayMode = in_mode.charAt(0);
214             break;
215         case FormUtilsInterface.EDIT_MODE:
216             lc_displayMode = in_mode.charAt(2);
217             break;
218         case FormUtilsInterface.INSPECT_MODE:
219             lc_displayMode = in_mode.charAt(4);
220             break;
221         default:
222             lc_displayMode = 'D';
223         }
224         display = lc_displayMode == 'D' || lc_displayMode == 'd';
225     }
226
227     /**
228      * @return Returns the policy.
229      */

230     public String JavaDoc getPolicy() {
231         return policy;
232     }
233
234     /**
235      * @param policy
236      * The policy to set.
237      */

238     public void setPolicy(String JavaDoc policy) {
239         this.policy = policy;
240     }
241
242     public Object JavaDoc processEndLayoutEvent(EndLayoutEvent in_event)
243             throws JspException JavaDoc {
244         return Boolean.FALSE;
245     }
246
247     public Object JavaDoc processStartLayoutEvent(StartLayoutEvent in_event)
248             throws JspException JavaDoc {
249         return Boolean.FALSE;
250     }
251
252     public String JavaDoc getType() {
253         return type;
254     }
255     public void setType(String JavaDoc type) {
256         this.type = type;
257     }
258 }
Popular Tags