KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > taglibs > html > BoxTag


1 package org.jahia.taglibs.html;
2
3 import java.io.IOException JavaDoc;
4 import javax.servlet.jsp.*;
5 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7
8 /**
9  * <p>name: Tag that generates an HTML Box</p>
10  * <p>Description: this tag is for the moment not very generic but it is
11  * here to help template developers to include easily a box with a title.
12  * It's also possible to define a css class for the title and the content
13  * cell, and to fix the table width.</p>
14  * <p>Copyright: Copyright (c) 2003</p>
15  * <p>Company: Jahia Ltd</p>
16  * @author Philippe Vollenweider
17  * @version 1.0
18  */

19
20 public class BoxTag extends BodyTagSupport JavaDoc {
21
22     private static org.apache.log4j.Logger logger =
23         org.apache.log4j.Logger.getLogger(BoxTag.class);
24
25     private String JavaDoc name = null;
26     private String JavaDoc width= "100%";
27     private String JavaDoc titleClass = null;
28     private String JavaDoc bodyClass = null;
29
30     public BoxTag() {
31     }
32
33     public String JavaDoc getName() {
34         return name;
35     }
36     public void setName(String JavaDoc name) {
37         this.name = name;
38     }
39     public String JavaDoc getWidth() {
40         return width;
41     }
42     public void setWidth(String JavaDoc width) {
43         this.width = width;
44     }
45     public String JavaDoc getTitleClass() {
46         return titleClass;
47     }
48     public void setTitleClass(String JavaDoc titleClass) {
49         this.titleClass = titleClass;
50     }
51     public String JavaDoc getBodyClass() {
52         return bodyClass;
53     }
54     public void setBodyClass(String JavaDoc bodyClass) {
55         this.bodyClass = bodyClass;
56     }
57
58     public int doStartTag () {
59         String JavaDoc title = (String JavaDoc)pageContext.findAttribute(name);
60         if (title == null) {
61             logger.error("Couldn't find any title with name " + name);
62             return EVAL_BODY_BUFFERED;
63         }
64
65         JspWriter out = pageContext.getOut();
66         try {
67             out.println("<table width=\"" + width + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
68             out.println(" <tr>");
69             out.print (" <td");
70             if (titleClass != null){
71                 out.print(" class=\"" + titleClass + "\"");
72             }
73             out.println(">" + title + "</td>");
74             out.println(" </tr>");
75             out.println(" <tr>");
76             out.print(" <td");
77             if (bodyClass != null){
78                 out.print(" class=\"" + bodyClass + "\"");
79             }
80             out.println(">");
81         } catch (IOException JavaDoc ioe) {
82             logger.error("IO exception while trying to display box for object " + name, ioe);
83         }
84
85         return EVAL_BODY_BUFFERED;
86     }
87     // Body is evaluated one time, so just writes it on standard output
88
public int doAfterBody () {
89
90         JspWriter out = bodyContent.getEnclosingWriter();
91         try {
92             bodyContent.writeOut(out);
93         } catch (IOException JavaDoc ioe) {
94             logger.error("Error:", ioe);
95         }
96
97
98         Object JavaDoc contentObject = pageContext.findAttribute(name);
99         if (contentObject == null) {
100             logger.error("Couldn't find any object with name " + name);
101             return SKIP_BODY;
102         }
103
104         try {
105             out.println("</td>");
106             out.println(" </tr>");
107             if (! "100%".equals(width)){
108                 String JavaDoc contextPath = ((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath();
109                 out.println(" <tr>");
110                 out.print(" <td><img SRC=\"");
111                 out.print(contextPath);
112                 out.println("/jahia/jsp/jahia/engines/images/pix.gif\" width=\"" + width + "\" height=\"1\"/></td>");
113                 out.println(" </tr>");
114             }
115             out.println("</table>");
116         } catch (IOException JavaDoc ioe) {
117             logger.error("IO exception while trying to display box for object " + name, ioe);
118         }
119
120         return SKIP_BODY;
121     }
122
123     public int doEndTag ()
124         throws JspException {
125         // let's reinitialize the tag variables to allow tag object reuse in
126
// pooling.
127
super.doEndTag();
128         name = null;
129         width = null;
130         titleClass = null;
131         bodyClass = null;
132         return EVAL_PAGE;
133     }
134 }
Popular Tags