FileDocCategorySizeDatePackage
CacheUtil.javaAPI DocGlassfish v2 API5147Fri May 04 22:35:28 BST 2007com.sun.appserv.web.taglibs.cache

CacheUtil

public class CacheUtil extends Object
CacheUtil has utility methods used by the cache tag library.

Fields Summary
private static ResourceBundle
_rb
The resource bundle containing the localized message strings.
private static final String
PAGE_SCOPE
private static final String
REQUEST_SCOPE
private static final String
SESSION_SCOPE
private static final String
APPLICATION_SCOPE
Constructors Summary
Methods Summary
public static intconvertScope(java.lang.String scope)


        int ret;

        if (REQUEST_SCOPE.equalsIgnoreCase(scope)) {
            ret = PageContext.REQUEST_SCOPE;
	} else if (SESSION_SCOPE.equalsIgnoreCase(scope)) {
            ret = PageContext.SESSION_SCOPE;
        } else if (APPLICATION_SCOPE.equalsIgnoreCase(scope)) {
            ret = PageContext.APPLICATION_SCOPE;
        } else {
            String msg = _rb.getString("taglibs.cache.illegalScope");
            msg = MessageFormat.format(msg, new Object[] { scope });
            throw new IllegalArgumentException(msg);
        }

        return ret;
    
public static java.lang.StringgenerateKey(java.lang.String key, javax.servlet.jsp.PageContext pc)
This function generates the key to the cache. It creates the key by suffixing the servlet path with either the user-specified key or by keeping a counter in the request attribute which it will increment each time so that multiple cache tags in a page each get a unique key.

return
the generated key

        HttpServletRequest req = (HttpServletRequest)pc.getRequest();

        // use the key as the suffix by default
        String suffix = key;
        if (suffix == null) {
            String saved = (String)req.getAttribute(Constants.JSPTAG_COUNTER_KEY);

            if (saved == null)
                suffix = "1";
            else
                suffix = Integer.toString(Integer.parseInt(saved) + 1);

            req.setAttribute(Constants.JSPTAG_COUNTER_KEY, suffix);
        }
        
        // concatenate the servlet path and the suffix to generate key
        return req.getServletPath() + '_" + suffix;
    
public static com.sun.appserv.util.cache.CachegetCache(javax.servlet.jsp.PageContext pc, int scope)
This is used to get the cache itself. The cache is stored as an attribute in the specified scope.

return
the cache object


                                
          
    
        return (Cache)pc.getAttribute(Constants.JSPTAG_CACHE_KEY, scope);