1 16 package org.apache.commons.jelly.impl; 17 18 import org.apache.commons.jelly.JellyContext; 19 import org.apache.commons.jelly.JellyTagException; 20 import org.apache.commons.jelly.Script; 21 import org.apache.commons.jelly.XMLOutput; 22 import org.apache.commons.jelly.expression.Expression; 23 24 import org.xml.sax.SAXException ; 25 26 32 public class ExpressionScript implements Script { 33 34 35 private Expression expression; 36 37 public ExpressionScript() { 38 } 39 40 public ExpressionScript(Expression expression) { 41 this.expression = expression; 42 } 43 44 public String toString() { 45 return super.toString() + "[expression=" + expression + "]"; 46 } 47 48 49 public Expression getExpression() { 50 return expression; 51 } 52 53 54 public void setExpression(Expression expression) { 55 this.expression = expression; 56 } 57 58 public Script compile() { 61 return this; 62 } 63 64 65 public void run(JellyContext context, XMLOutput output) throws JellyTagException { 66 Object result = expression.evaluate(context); 67 if ( result != null ) { 68 69 try { 70 output.objectData(result); 71 } catch (SAXException e) { 72 throw new JellyTagException("Could not write to XMLOutput",e); 73 } 74 75 } 76 } 77 } 78 | Popular Tags |