KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > MessageTag


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.event.EndLayoutEvent;
6 import fr.improve.struts.taglib.layout.event.StartLayoutEvent;
7 import fr.improve.struts.taglib.layout.util.LayoutUtils;
8 import fr.improve.struts.taglib.layout.util.TagUtils;
9
10 /**
11  * Custom tag that retrieves an internationalized messages string (with
12  * optional parametric replacement) from the <code>ActionResources</code>
13  * object stored as a context attribute by our associated
14  * <code>ActionServlet</code> implementation.
15  * <br>
16  * <br>
17  * Modify to display the key if the label is not present<br>
18  * The tag can be nested in panel and line tags if the styleClass attribute is set.
19  *
20  * @author Craig R. McClanahan
21  * @author Jean-NoŽl Ribette
22  */

23
24 public class MessageTag extends LabelledTag {
25     protected boolean layout = true;
26     /**
27      * Process the start tag.
28      *
29      * @exception JspException if a JSP exception has occurred
30      */

31     public int doStartLayoutTag() throws JspException JavaDoc {
32         doStartLayout();
33         String JavaDoc key = this.key;
34         if (key == null) {
35             // Look up the requested property value
36
Object JavaDoc value =
37                 TagUtils.lookup(pageContext, name, property, null);
38             if (value != null && !(value instanceof String JavaDoc)) {
39                 JspException JavaDoc e = new JspException JavaDoc
40                     (messages.getMessage("message.property", key));
41                 TagUtils.saveException(pageContext, e);
42                 throw e;
43             }
44             key = (String JavaDoc)value;
45         }
46         String JavaDoc lc_message = getLabel();
47         TagUtils.write(pageContext, lc_message);
48
49         doEndLayout();
50         // Continue processing this page
51
return (SKIP_BODY);
52     }
53     /**
54      * Release any acquired resources.
55      */

56     public void release() {
57         super.release();
58         layout = true;
59     }
60     /**
61      * Print the required HTML code so that the tag can be nested in panel and line tags.<br>
62      * This won't do anything if styleClass is null.
63      */

64     private void doStartLayout() throws JspException JavaDoc {
65         if (layout) {
66             StringBuffer JavaDoc lc_buffer = new StringBuffer JavaDoc("<th");
67             if (styleClass!=null) {
68                 lc_buffer.append(" class=\"");
69                 lc_buffer.append(styleClass);
70                 lc_buffer.append("\"");
71             }
72             lc_buffer.append(" colspan=\"");
73             lc_buffer.append(LayoutUtils.getSkin(pageContext.getSession()).getFieldInterface().getColumnNumber());
74             lc_buffer.append("\">");
75             new StartLayoutEvent(this, lc_buffer.toString()).send();
76         }
77     }
78     
79     /**
80      * Print the required HTML code so that the tag can be nested in panel and line tags.<br>
81      * This won't do anything if styleClass is null.
82      */

83     private void doEndLayout() throws JspException JavaDoc {
84         if (layout) {
85             new EndLayoutEvent(this,"</th>").send();
86         }
87     }
88
89     /**
90      * Sets the layout.
91      * @param layout The layout to set
92      */

93     public void setLayout(boolean layout) {
94         this.layout = layout;
95     }
96
97 }
98
Popular Tags