1 23 24 package com.sun.appserv.web.taglibs.cache; 25 26 import java.util.ResourceBundle ; 27 import java.text.MessageFormat ; 28 29 import javax.servlet.jsp.PageContext ; 30 import javax.servlet.ServletContext ; 31 import javax.servlet.http.HttpServletRequest ; 32 33 import com.sun.appserv.util.cache.Cache; 34 import com.sun.enterprise.web.logging.pwc.LogDomains; 35 36 39 public class CacheUtil { 40 41 44 private static ResourceBundle _rb = 45 LogDomains.getLogger(LogDomains.PWC_LOGGER).getResourceBundle(); 46 47 private static final String PAGE_SCOPE = "page"; 48 private static final String REQUEST_SCOPE = "request"; 49 private static final String SESSION_SCOPE = "session"; 50 private static final String APPLICATION_SCOPE = "application"; 51 52 57 public static Cache getCache(PageContext pc, int scope) 58 { 59 return (Cache)pc.getAttribute(Constants.JSPTAG_CACHE_KEY, scope); 60 } 61 62 70 public static String generateKey(String key, PageContext pc) 71 { 72 HttpServletRequest req = (HttpServletRequest )pc.getRequest(); 73 74 String suffix = key; 76 if (suffix == null) { 77 String saved = (String )req.getAttribute(Constants.JSPTAG_COUNTER_KEY); 78 79 if (saved == null) 80 suffix = "1"; 81 else 82 suffix = Integer.toString(Integer.parseInt(saved) + 1); 83 84 req.setAttribute(Constants.JSPTAG_COUNTER_KEY, suffix); 85 } 86 87 return req.getServletPath() + '_' + suffix; 89 } 90 91 92 102 public static int convertScope(String scope) { 103 104 int ret; 105 106 if (REQUEST_SCOPE.equalsIgnoreCase(scope)) { 107 ret = PageContext.REQUEST_SCOPE; 108 } else if (SESSION_SCOPE.equalsIgnoreCase(scope)) { 109 ret = PageContext.SESSION_SCOPE; 110 } else if (APPLICATION_SCOPE.equalsIgnoreCase(scope)) { 111 ret = PageContext.APPLICATION_SCOPE; 112 } else { 113 String msg = _rb.getString("taglibs.cache.illegalScope"); 114 msg = MessageFormat.format(msg, new Object [] { scope }); 115 throw new IllegalArgumentException (msg); 116 } 117 118 return ret; 119 } 120 } 121 | Popular Tags |