package nl.siegmann.ehcachetag.cachetagmodifier;

import javax.servlet.ServletContext;
import javax.servlet.jsp.JspContext;

import nl.siegmann.ehcachetag.CacheTag;

/**
 * Is called after the attributes are set and before the Cache lookup.
 * 
 * Useful for for instance adding additional data to the cache key.
 * 
 * Thread-safety: This class can and will be used by several concurrent threads.
 * Init and destroy will be called only once by the application server, but make sure doPreProcess is thread-safe.
 * 
 * @author paul
 *
 */
public interface CacheTagModifier {

	/**
	 * CacheTagInterceptor that does not do anything.
	 * 
	 */
	CacheTagModifier NULL_CACHETAG_MODIFIER = new CacheTagModifier() {
		
		@Override
		public void init(ServletContext servletContext) {
		}
		
		@Override
		public void beforeLookup(CacheTag cacheTag, JspContext jspContext) {
		}
		
		@Override
		public String afterRetrieval(CacheTag cacheTag, JspContext jspContext,
				String content) {
			return content;
		}
		
		@Override
		public void destroy() {
		}

		@Override
		public String beforeUpdate(CacheTag cacheTag, JspContext jspContext,
				String content) {
			return content;
		}

	};
	
	/**
	 * Called once on Application startup.
	 * 
	 * @param properties
	 */
	void init(ServletContext servletContext);
	
	/**
	 * Called before Cache lookup.
	 * 
	 * Will be called by different threads concurrently.
	 */
	void beforeLookup(CacheTag cacheTag, JspContext jspContext);
	
	/**
	 * Called before updating the cache with the given content.
	 * 
	 * @param cacheTag
	 * @param jspContext
	 * @param content the content that will be stored in the cache
	 * @return
	 */
	String beforeUpdate(CacheTag cacheTag, JspContext jspContext, String content);
	
	
	/**
	 * Called after retrieving content from the cache but before it's written to the output.
	 * 
	 * @param cacheTag
	 * @param jspContext
	 * @param content the content that will be sent back to the response
	 * @return
	 */
	String afterRetrieval(CacheTag cacheTag, JspContext jspContext, String content);

	/**
	 * Called on Application shutdown.
	 */
	void destroy();
}
@@ -170,151 +170,333 @@
 %0A * 
-Is called after the attributes are set and before the Cache lookup.%0A * %0A * Useful for for instance adding additional data to the cache key
+This class is called before a lookup in the cache is done, after content is retreived from the cache and before%0A * content is written to the outputstream.%0A * %0A * It gives the ability to modify the cache key, the cache to use, the content to store, the content to display and other%0A * aspects of the caching lifecycle
 .%0A * 
+%3Cp/%3E
 %0A * 
@@ -572,16 +572,21 @@
 threads.
+%3Cbr/%3E
 %0A * Init
@@ -668,20 +668,47 @@
 ure 
-doPreProcess
+any implementation%0A * of this interface
  is 
@@ -1860,32 +1860,67 @@
 ache%0A%09 * @return
+ the content to store in the cache.
 %0A%09 */%0A%09String be
@@ -2200,16 +2200,14 @@
 the 
-response
+client
 %0A%09 *
@@ -2214,16 +2214,55 @@
  @return
+ The content to send back to the client
 %0A%09 */%0A%09S
@@ -2406,8 +2406,9 @@
 roy();%0A%7D
+%0A

improve javadoc