1 16 17 package org.apache.taglibs.cache; 18 19 import javax.servlet.jsp.*; 20 import javax.servlet.jsp.tagext.*; 21 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 22 23 28 29 public class InvalidateTag extends TagSupport { 30 31 34 String nameExpr; String keyExpr; 37 int scope; String name, key; 40 43 public int doStartTag() throws JspException { 44 evaluateExpressions(); 45 if (keyExpr == null || key == null) { 46 CacheUtil.invalidateCache(scope, name, pageContext); 48 } else { 49 CacheUtil.invalidateCachedItem(scope, name, key, pageContext); 51 } 52 return SKIP_BODY; 53 } 54 55 58 public void setScope(String scope) { 59 if (scope.equalsIgnoreCase("page")) 60 this.scope = PageContext.PAGE_SCOPE; 61 else if (scope.equalsIgnoreCase("request")) 62 this.scope = PageContext.REQUEST_SCOPE; 63 else if (scope.equalsIgnoreCase("session")) 64 this.scope = PageContext.SESSION_SCOPE; 65 else if (scope.equalsIgnoreCase("application")) 66 this.scope = PageContext.APPLICATION_SCOPE; 67 else 68 throw new IllegalArgumentException ("invalid scope"); 69 } 70 71 public void setName(String nameExpr) { 72 this.nameExpr = nameExpr; 73 } 74 75 public void setKey(String keyExpr) { 76 this.keyExpr = keyExpr; 77 } 78 79 80 83 public InvalidateTag() { 84 super(); 85 init(); 86 } 87 88 private void init() { 89 scope = PageContext.APPLICATION_SCOPE; 90 name = nameExpr = null; 91 key = keyExpr = null; 92 } 93 94 95 98 private void evaluateExpressions() throws JspException { 99 if (nameExpr != null) 100 name = (String ) ExpressionEvaluatorManager.evaluate( 101 "name", 102 nameExpr, 103 String .class, 104 this, 105 pageContext); 106 if (keyExpr != null) 107 key = (String ) ExpressionEvaluatorManager.evaluate( 108 "key", 109 keyExpr, 110 String .class, 111 this, 112 pageContext); 113 } 114 115 } 116 | Popular Tags |