org.opensubsystems.core.www
Class PageElementCacheTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.opensubsystems.core.www.PageElementCacheTag
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag
Direct Known Subclasses:
BlockElementTag, WebModuleInitTag

public class PageElementCacheTag
extends javax.servlet.jsp.tagext.BodyTagSupport

Custom tag providing ability to cache elements of the page usually from custom tags and then display them at later point when requested. The main purpose is to allow other tags to specify elements, such as css includes or javascript includes at one spot, e.g. using initialization tag. These elements will then be place on a specific places at the page using this tag. It also allows derived tags to cache their content and then other tags to fetch them and display at other places.

Version:
$Id: PageElementCacheTag.java,v 1.10 2007/01/07 06:14:09 bastafidli Exp $
Author:
Miro Halas
See Also:
Serialized Form
Code reviewer:
Miro Halas
Code reviewed:
1.7 2006/04/13 00:21:23 jlegeny

Field Summary
static java.lang.String CACHE_INDICATOR
          Indicator to use in attributes to signal to retrieve content from the cache.
static java.lang.String CSS_ELEMENT
          CSS style sheets cache.
static java.lang.String JS_ELEMENT
          JavaScript js import cache.
protected  java.lang.String m_strCacheas
          If this id is specified then the content will not be printed into output but instead will be cached under id specified in this attribute.
protected  java.lang.String m_strId
          Id of the cached element to retrieve.
static java.lang.String PAGE_ELEMENTS_CACHE
          Messages collected during processing of current request.
static java.lang.String SCRIPT_ELEMENT
          JavaScript script cache.
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
PageElementCacheTag()
          Constructor for custom tag.
 
Method Summary
protected  void cache(java.lang.String strPageElementId, java.lang.String strItemToCache)
          Add item for specific page element to the cache.
 int doEndTag()
          
 int doStartTag()
          
 java.lang.String getCacheas()
           
protected  java.lang.String getCachedContent(java.lang.String strPageElementId)
          Get the cached content.
protected  java.lang.String getCachedContent(java.lang.String strPageElementId, boolean bRemove)
          Get the cached content.
protected  java.lang.String getCachedContent(java.lang.String strPageElementId, boolean bRemove, java.lang.String strSeparator)
          Get the cached content.
protected  java.util.List getCachedContentElements(java.lang.String strPageElementId, boolean bRemove)
          Get the elements of cached content elements.
 java.lang.String getId()
           
 void setCacheas(java.lang.String strCacheas)
           
 void setId(java.lang.String strId)
           
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doAfterBody, doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getParent, getValue, getValues, removeValue, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Field Detail

PAGE_ELEMENTS_CACHE

public static final java.lang.String PAGE_ELEMENTS_CACHE
Messages collected during processing of current request.

See Also:
Constant Field Values

CSS_ELEMENT

public static final java.lang.String CSS_ELEMENT
CSS style sheets cache.

See Also:
Constant Field Values

JS_ELEMENT

public static final java.lang.String JS_ELEMENT
JavaScript js import cache.

See Also:
Constant Field Values

SCRIPT_ELEMENT

public static final java.lang.String SCRIPT_ELEMENT
JavaScript script cache.

See Also:
Constant Field Values

CACHE_INDICATOR

public static final java.lang.String CACHE_INDICATOR
Indicator to use in attributes to signal to retrieve content from the cache.

See Also:
Constant Field Values

m_strId

protected java.lang.String m_strId
Id of the cached element to retrieve.


m_strCacheas

protected java.lang.String m_strCacheas
If this id is specified then the content will not be printed into output but instead will be cached under id specified in this attribute.

Constructor Detail

PageElementCacheTag

public PageElementCacheTag()
Constructor for custom tag.

Method Detail

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException

Specified by:
doEndTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

getId

public java.lang.String getId()
Overrides:
getId in class javax.servlet.jsp.tagext.TagSupport
Returns:
String - Id of the cached element to retrieve.

getCacheas

public java.lang.String getCacheas()
Returns:
String - New Id under which the output will be cached

setId

public void setId(java.lang.String strId)
Overrides:
setId in class javax.servlet.jsp.tagext.TagSupport
Parameters:
strId - - Id of the cached element to retrieve.

setCacheas

public void setCacheas(java.lang.String strCacheas)
Parameters:
strCacheas - - New Id under which the output will be cached

cache

protected void cache(java.lang.String strPageElementId,
                     java.lang.String strItemToCache)
Add item for specific page element to the cache.

Parameters:
strPageElementId - - constant representing HTML page element for which the item will be cached
strItemToCache - - element to cache

getCachedContent

protected java.lang.String getCachedContent(java.lang.String strPageElementId)
Get the cached content.

Parameters:
strPageElementId - - id of the cached element to get
Returns:
String - cached content or empty string if nothing is cached, but never null

getCachedContent

protected java.lang.String getCachedContent(java.lang.String strPageElementId,
                                            boolean bRemove,
                                            java.lang.String strSeparator)
Get the cached content.

Parameters:
strPageElementId - - id of the cached element to get
bRemove - - remove the element from the cache after it is retrieved
strSeparator - - separator for particular cached items
Returns:
String - cached content or empty string if nothing is cached, but never null

getCachedContent

protected java.lang.String getCachedContent(java.lang.String strPageElementId,
                                            boolean bRemove)
Get the cached content.

Parameters:
strPageElementId - - id of the cached element to get
bRemove - - remove the element from the cache after it is retrieved
Returns:
String - cached content or empty string if nothing is cached, but never null

getCachedContentElements

protected java.util.List getCachedContentElements(java.lang.String strPageElementId,
                                                  boolean bRemove)
Get the elements of cached content elements.

Parameters:
strPageElementId - - id of the cached element to get
bRemove - - remove the element from the cache after it is retrieved
Returns:
Lists - cached content or empty List if nothing is cached, but never null


Copyright © 2003 - 2006 OpenSubsystems s.r.o.