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 scriptlet 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 setBodyContent(BodyContent bodyOut) { this.bodyOut = bodyOut;}; 38 public int doStartTag() throws JspException { return(EVAL_BODY_TAG);}; 39 public void release() { }; 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 engine = 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 engine.exec ("<JSP>", 1, 1, bodyOut.getString() ); 80 81 } catch( Exception e ) { 82 System.out.println( e.toString() ); 83 e.printStackTrace(); 84 } 86 return( EVAL_PAGE ); 87 }; 88 89 } 90 | Popular Tags |