1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import javax.servlet.jsp.JspException ; 68 import javax.servlet.jsp.JspTagException ; 69 import javax.servlet.jsp.JspWriter ; 70 import javax.servlet.jsp.tagext.TagSupport ; 71 72 73 92 public class ContentTag 93 extends TagSupport { 94 private String content = null; 95 96 public ContentTag() { 97 super(); 98 } 99 100 public int doStartTag() throws javax.servlet.jsp.JspException { 101 content = null; 102 return EVAL_BODY_INCLUDE; 103 } 104 105 106 111 public int doEndTag() 112 throws javax.servlet.jsp.JspTagException { 113 try { 114 115 OutputTag ancestorOutput = (OutputTag) getAncestor("com.jcorporate.expresso.ext.taglib.OutputTag"); 117 118 if (ancestorOutput == null) { 119 throw new JspTagException ("A ContentTag must be nested within a valid OutputTag."); 120 } 121 122 content = ancestorOutput.getContent(); 123 124 JspWriter writer = pageContext.getOut(); 125 writer.print(content); 126 } catch (Exception e) { 127 throw new JspTagException ("ContentTag Error: " + e.getMessage()); 128 } 129 130 return EVAL_PAGE; 131 } 132 133 134 private TagSupport getAncestor(String className) 137 throws JspException { 138 Class klass = null; 140 try { 141 klass = Class.forName(className); 142 } catch (ClassNotFoundException ex) { 143 throw new JspException (ex.getMessage()); 144 } 145 146 return (TagSupport ) findAncestorWithClass(this, klass); 147 } 148 } | Popular Tags |