|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| UseCachedTag.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (c) 2002-2003 by OpenSymphony
|
|
| 3 |
* All rights reserved.
|
|
| 4 |
*/
|
|
| 5 |
package com.opensymphony.oscache.web.tag;
|
|
| 6 |
|
|
| 7 |
import javax.servlet.jsp.JspTagException;
|
|
| 8 |
import javax.servlet.jsp.tagext.TagSupport;
|
|
| 9 |
|
|
| 10 |
/**
|
|
| 11 |
* UseCachedTag is a tag that tells a <cache> tag to reuse the cached body.<p>
|
|
| 12 |
*
|
|
| 13 |
* Usage Example:
|
|
| 14 |
* <pre><code>
|
|
| 15 |
* <%@ taglib uri="oscache" prefix="cache" %>
|
|
| 16 |
* <cache:cache key="mycache" scope="application">
|
|
| 17 |
* if (reuse cached)
|
|
| 18 |
* <cache:usecached />
|
|
| 19 |
* else
|
|
| 20 |
* some other logic
|
|
| 21 |
* </cache:cache>
|
|
| 22 |
* </code></pre>
|
|
| 23 |
*
|
|
| 24 |
* Note this is very useful with try / catch blocks
|
|
| 25 |
* so that you can still produce old cached data if an
|
|
| 26 |
* exception occurs, eg your database goes down.<p>
|
|
| 27 |
*
|
|
| 28 |
* @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
|
|
| 29 |
* @version $Revision: 1.1 $
|
|
| 30 |
*/
|
|
| 31 |
public class UseCachedTag extends TagSupport { |
|
| 32 |
boolean use = true; |
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* Set the decision to use the body content of the ancestor <cache> or not.
|
|
| 36 |
*
|
|
| 37 |
* @param value Whether or not to use the body content. Default is true.
|
|
| 38 |
*/
|
|
| 39 | 0 |
public void setUse(boolean value) { |
| 40 | 0 |
this.use = value;
|
| 41 |
} |
|
| 42 |
|
|
| 43 |
/**
|
|
| 44 |
* The start tag.
|
|
| 45 |
*
|
|
| 46 |
* @throws JspTagException The standard tag exception thrown.
|
|
| 47 |
* @return The standard Tag return.
|
|
| 48 |
*/
|
|
| 49 | 0 |
public int doStartTag() throws JspTagException { |
| 50 | 0 |
CacheTag cacheTag = (CacheTag) TagSupport.findAncestorWithClass(this, CacheTag.class); |
| 51 |
|
|
| 52 | 0 |
if (cacheTag == null) { |
| 53 | 0 |
throw new JspTagException("A UseCached tag must be nested within a Cache tag"); |
| 54 |
} |
|
| 55 |
|
|
| 56 | 0 |
cacheTag.setUseBody(!use); |
| 57 |
|
|
| 58 | 0 |
return SKIP_BODY;
|
| 59 |
} |
|
| 60 |
} |
|
| 61 |
|
|
||||||||||