1 package org.jahia.taglibs.html; 2 3 import java.io.IOException ; 4 import javax.servlet.jsp.*; 5 import javax.servlet.jsp.tagext.BodyTagSupport ; 6 import javax.servlet.http.HttpServletRequest ; 7 8 19 20 public class BoxTag extends BodyTagSupport { 21 22 private static org.apache.log4j.Logger logger = 23 org.apache.log4j.Logger.getLogger(BoxTag.class); 24 25 private String name = null; 26 private String width= "100%"; 27 private String titleClass = null; 28 private String bodyClass = null; 29 30 public BoxTag() { 31 } 32 33 public String getName() { 34 return name; 35 } 36 public void setName(String name) { 37 this.name = name; 38 } 39 public String getWidth() { 40 return width; 41 } 42 public void setWidth(String width) { 43 this.width = width; 44 } 45 public String getTitleClass() { 46 return titleClass; 47 } 48 public void setTitleClass(String titleClass) { 49 this.titleClass = titleClass; 50 } 51 public String getBodyClass() { 52 return bodyClass; 53 } 54 public void setBodyClass(String bodyClass) { 55 this.bodyClass = bodyClass; 56 } 57 58 public int doStartTag () { 59 String title = (String )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 ioe) { 82 logger.error("IO exception while trying to display box for object " + name, ioe); 83 } 84 85 return EVAL_BODY_BUFFERED; 86 } 87 public int doAfterBody () { 89 90 JspWriter out = bodyContent.getEnclosingWriter(); 91 try { 92 bodyContent.writeOut(out); 93 } catch (IOException ioe) { 94 logger.error("Error:", ioe); 95 } 96 97 98 Object 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 contextPath = ((HttpServletRequest )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 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 super.doEndTag(); 128 name = null; 129 width = null; 130 titleClass = null; 131 bodyClass = null; 132 return EVAL_PAGE; 133 } 134 } | Popular Tags |