1 34 35 36 package com.micronova.jsp.tag; 37 38 import com.micronova.util.*; 39 import com.micronova.util.codec.CodecJSP; 40 import java.util.regex.*; 41 import java.util.*; 42 43 44 45 public class EvalTag extends YuzuTag implements ObjectSource 46 { 47 protected Object _pattern; 48 protected boolean _recursive; 49 protected boolean _allowGroup; 50 protected String _evalCodec; 51 protected Object _environment; 52 53 protected void init() 54 { 55 super.init(); 56 57 _export = DEFAULT; 58 59 _pattern = EL.DEFAULTPATTERNEVAL; 60 _recursive = false; 61 _allowGroup = false; 62 _evalCodec = null; 63 _environment = null; 64 } 65 66 protected Object evaluate(Object tagValue, Pattern pattern) throws Exception 67 { 68 return Template.render(tagValue.toString(), pattern, 1, this, this, _recursive, _allowGroup); 69 } 70 71 public Object processValue(Object tagValue) throws Exception 72 { 73 if (tagValue instanceof String ) 74 { 75 Pattern pattern = EL.getPattern(_pattern); 76 77 Object environment = _environment; 78 79 Object valueVarSaved = null; 80 81 if (environment != null) 82 { 83 valueVarSaved = pageContext.getAttribute(YuzuTag.VALUEVAR); 84 setPageAttribute(VALUEVAR, environment); 85 } 86 87 tagValue = evaluate(tagValue, pattern); 88 89 if (environment != null) 90 { 91 EL.setPageAttribute(pageContext, YuzuTag.VALUEVAR, valueVarSaved); 92 } 93 } 94 else 95 { 96 tagValue =CodecJSP.eval(pageContext, tagValue, EL.getPattern(_pattern), _environment, _evalCodec, _recursive, _allowGroup); 97 } 98 99 return tagValue; 100 } 101 102 public Object getObject(Object client, Object key) 103 { 104 try 105 { 106 return applyCodec(_evalCodec, evaluateExpression("eval", "${" + key.toString() + "}", Object .class)); 107 } 108 catch (Exception e) 109 { 110 throw new RuntimeException (e); 111 } 112 } 113 114 public void setPattern(Object expression) throws Exception 115 { 116 _pattern = evaluateAttribute("pattern", expression, Object .class); 117 } 118 119 public void setRecursive(Object expression) throws Exception 120 { 121 _recursive = ((Boolean )evaluateAttribute("recursive", expression, Boolean .class)).booleanValue(); 122 } 123 124 public void setAllowGroup(Object expression) throws Exception 125 { 126 _allowGroup = ((Boolean )evaluateAttribute("allowGroup", expression, Boolean .class)).booleanValue(); 127 } 128 129 public void setEvalCodec(Object expression) throws Exception 130 { 131 _evalCodec = (String )evaluateAttribute("evalCodec", expression, EL.class); 132 } 133 134 public void setEnvironment(Object expression) throws Exception 135 { 136 _environment = evaluateAttribute("environment", expression, Object .class); 137 } 138 } 139 | Popular Tags |