1 16 17 package org.apache.taglibs.bsf ; 18 19 import javax.servlet.jsp.* ; 20 import javax.servlet.jsp.tagext.* ; 21 import java.io.IOException ; 22 23 import org.apache.bsf.* ; 24 25 public class expression implements BodyTag 26 { 27 protected Tag parent ; 28 protected BodyContent bodyOut ; 29 protected PageContext pageContext ; 30 protected String language ; 31 32 public void setLanguage(String value) { language = value ; }; 33 public void setParent(Tag parent) { this.parent = parent ; }; 34 public Tag getParent() { return( this.parent ); }; 35 public void doInitBody() throws JspException { }; 36 public int doAfterBody() throws JspException { return 0; }; 37 public void release() { }; 38 public void setBodyContent(BodyContent bodyOut) { this.bodyOut = bodyOut;}; 39 public int doStartTag() throws JspException { return(EVAL_BODY_TAG);}; 40 41 public void setPageContext(PageContext pageContext) { 42 this.pageContext = pageContext ; 43 }; 44 45 private void register( BSFManager mgr, String name, Object bean ) 46 throws Exception { 47 if ( bean == null ) return ; 48 try { 49 mgr.declareBean( name, bean, bean.getClass() ); 50 } 51 catch( Exception e ) { 52 throw e ; 53 } 54 }; 55 56 public int doEndTag() throws JspException { 57 try { 58 JspWriter out = pageContext.getOut(); 59 if ( bodyOut == null ) return( EVAL_PAGE ); 60 61 BSFManager mgr = new BSFManager (); 62 BSFEngine BSFengine = mgr.loadScriptingEngine (language); 63 64 try { 65 register( mgr, "request" , pageContext.getRequest() ); 66 register( mgr, "response" , pageContext.getResponse() ); 67 register( mgr, "pageContext", pageContext ); 68 register( mgr, "application", pageContext.getServletContext() ); 69 register( mgr, "out" , out ); 70 register( mgr, "config" , pageContext.getServletConfig() ); 71 register( mgr, "page" , pageContext.getPage() ); 72 register( mgr, "exception" , pageContext.getException() ); 73 register( mgr, "session" , pageContext.getSession() ); 74 } catch( Exception e ) { 75 out.println( e.toString() ); 76 e.printStackTrace(); 77 } 78 79 Object result ; 80 result = BSFengine.eval ("<unknown>", 0, 0, bodyOut.getString() ); 81 if ( result != null ) 82 out.println( result.toString() ); 83 } catch( Exception e ) { 84 System.out.println( e.toString() ); 85 e.printStackTrace(); 86 } 88 return( EVAL_PAGE ); 89 }; 90 } 91 | Popular Tags |