1 16 17 package org.apache.taglibs.io; 18 19 import javax.servlet.ServletContext ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.JspWriter ; 22 import javax.servlet.jsp.tagext.Tag ; 23 24 30 public class GetTag extends AbstractTag { 31 32 33 private String name; 34 35 36 private String property; 37 38 39 public GetTag() { 40 } 41 42 public int doStartTag() throws JspException { 45 Tag parent = getParent(); 46 if ( parent instanceof PipeConsumer ) { 47 PipeConsumer consumer = (PipeConsumer) parent; 48 consumer.setReader( PipeHelper.getReader( getValue() ) ); 49 } 50 else if ( parent instanceof PipeProducer ) { 51 PipeProducer producer = (PipeProducer) parent; 52 producer.setWriter( PipeHelper.getWriter( getValue() ) ); 53 } 54 else { 55 throw new JspException ( "<io:get> tag must be included inside either a PipeConsumer or PipeProducer tag" ); 56 } 57 return SKIP_BODY; 58 } 59 60 public void release() { 61 super.release(); 62 name = null; 63 property = null; 64 } 65 66 67 68 public Object getValue() throws JspException { 71 Object bean = pageContext.findAttribute( name ); 72 if ( bean != null ) { 73 if ( property == null ) { 74 return bean; 75 } 76 else { 77 return BeanHelper.getProperty( bean, property ); 78 } 79 } 80 return null; 81 } 82 83 public void setName(String name) { 84 this.name = name; 85 } 86 87 public void setProperty(String property) { 88 this.property = property; 89 } 90 } 91 | Popular Tags |