1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import org.apache.struts.taglib.bean.DefineTag; 68 69 import javax.servlet.jsp.JspException ; 70 import javax.servlet.jsp.JspTagException ; 71 import javax.servlet.jsp.PageContext ; 72 import javax.servlet.jsp.tagext.TagSupport ; 73 74 75 81 public class ExOutputVarTag extends DefineTag { 82 89 public int doStartTag() 90 throws JspException { 91 92 return (SKIP_BODY); 93 } 94 95 protected TagSupport getAncestor(String className) 96 throws JspException { 97 Class klass = null; 98 99 try { 100 klass = Class.forName(className); 101 } catch (ClassNotFoundException ex) { 102 throw new JspException (ex.getMessage()); 103 } 104 105 return (TagSupport ) findAncestorWithClass(this, klass); 106 } 107 108 113 public int doEndTag() throws JspException { 114 115 116 Object value = this.value; 118 119 if ((value == null) && (body != null)) { 120 value = body; 122 } 123 if (value == null) { 124 125 OutputTag ancestorOutput = (OutputTag) getAncestor("com.jcorporate.expresso.ext.taglib.OutputTag"); 127 128 if (ancestorOutput == null) { 129 throw new JspTagException ("A ExOutputVar tag must be nested within a valid OutputTag."); 130 } 131 132 value = ancestorOutput.getContent(); 133 } 134 if (value == null) { 135 throw new JspException ("Unable to retireve content from parent Output tag"); 136 } 137 138 int inScope = PageContext.PAGE_SCOPE; 140 141 if ("request".equals(toScope)) { 142 inScope = PageContext.REQUEST_SCOPE; 143 } else if ("session".equals(toScope)) { 144 inScope = PageContext.SESSION_SCOPE; 145 } else if ("application".equals(toScope)) { 146 inScope = PageContext.APPLICATION_SCOPE; 147 } 148 149 pageContext.setAttribute(id, value, inScope); 150 151 return (EVAL_PAGE); 153 154 } 155 156 } 157 | Popular Tags |