1 23 package org.infoglue.deliver.taglib; 24 25 import java.io.IOException ; 26 import java.util.Collection ; 27 import java.util.List ; 28 29 import javax.servlet.jsp.JspException ; 30 import javax.servlet.jsp.JspTagException ; 31 import javax.servlet.jsp.tagext.TagSupport ; 32 33 import org.apache.taglibs.standard.tag.el.core.ExpressionUtil; 34 35 38 public abstract class AbstractTag extends TagSupport 39 { 40 45 private String id; 46 47 50 protected AbstractTag() 51 { 52 super(); 53 } 54 55 62 public void setId(String id) 63 { 64 this.id = id; 65 } 66 67 73 protected void setResultAttribute(Object value) 74 { 75 if(value == null) 76 { 77 pageContext.removeAttribute(id); 78 } 79 else 80 { 81 pageContext.setAttribute(id, value); 82 } 83 } 84 85 94 protected void produceResult(Object value) throws JspTagException 95 { 96 if(id == null) 97 { 98 write((value == null) ? "" : value.toString()); 99 } 100 else 101 { 102 setResultAttribute(value); 103 } 104 } 105 106 112 protected void write(final String text) throws JspTagException 113 { 114 try 115 { 116 pageContext.getOut().write(text); 117 } 118 catch(IOException e) 119 { 120 e.printStackTrace(); 121 throw new JspTagException ("IO error: " + e.getMessage()); 122 } 123 } 124 125 135 protected Object evaluate(String tagName, String attributeName, String expression, Class expectedType) throws JspException 136 { 137 return ExpressionUtil.evalNotNull(tagName, attributeName, expression, expectedType, this, pageContext); 138 } 139 140 149 protected Integer evaluateInteger(String tagName, String attributeName, String expression) throws JspException 150 { 151 return (Integer ) evaluate(tagName, attributeName, expression, Integer .class); 152 } 153 154 163 protected String evaluateString(String tagName, String attributeName, String expression) throws JspException 164 { 165 return (String ) evaluate(tagName, attributeName, expression, String .class); 166 } 167 168 177 protected Collection evaluateCollection(String tagName, String attributeName, String expression) throws JspException 178 { 179 return (Collection ) evaluate(tagName, attributeName, expression, Collection .class); 180 } 181 182 191 protected List evaluateList(String tagName, String attributeName, String expression) throws JspException 192 { 193 return (List ) evaluate(tagName, attributeName, expression, List .class); 194 } 195 } 196 | Popular Tags |