logo       

roller/src/org/roller/presentation/filters IfModifiedFilter.java,1.6,1.7: msg#00070

java.roller.cvs

Subject: roller/src/org/roller/presentation/filters IfModifiedFilter.java,1.6,1.7

Update of /cvsroot/roller/roller/src/org/roller/presentation/filters
In directory sc8-pr-cvs1:/tmp/cvs-serv25669/src/org/roller/presentation/filters

Modified Files:
IfModifiedFilter.java
Log Message:
formatting

Index: IfModifiedFilter.java
===================================================================
RCS file:
/cvsroot/roller/roller/src/org/roller/presentation/filters/IfModifiedFilter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** IfModifiedFilter.java 16 Aug 2003 15:54:27 -0000 1.6
--- IfModifiedFilter.java 16 Sep 2003 01:49:31 -0000 1.7
***************
*** 31,35 ****
import javax.servlet.http.HttpServletResponse;

-
/**
* Handles If-Modified-Since header using per-user and per-category
--- 31,34 ----
***************
*** 41,48 ****
public class IfModifiedFilter implements Filter
{
! private static Log mLogger =
LogFactory.getFactory().getInstance(IfModifiedFilter.class);

! private Cache cache;
/**
*
--- 40,47 ----
public class IfModifiedFilter implements Filter
{
! private static Log mLogger =
LogFactory.getFactory().getInstance(IfModifiedFilter.class);

! private Cache cache;
/**
*
***************
*** 58,75 ****
public void init(FilterConfig arg0) throws ServletException
{
! // This method is not multithreaded, so we dont need to sync
!
! String cacheName = "UpdateTimeCache";
! if(CacheSingleton.hasCache(cacheName))
! {
! cache = CacheSingleton.getCache(cacheName);
! }
! else
! {
! cache = new SimpleCache( new MemoryStash( 5000 ),
! new LRUEvictionPolicy(), null, new
GroupMapImpl() );
! CacheSingleton.putCache( cacheName, cache );
! }
!
}

--- 57,78 ----
public void init(FilterConfig arg0) throws ServletException
{
! // This method is not multithreaded, so we dont need to sync
!
! String cacheName = "UpdateTimeCache";
! if (CacheSingleton.hasCache(cacheName))
! {
! cache = CacheSingleton.getCache(cacheName);
! }
! else
! {
! cache =
! new SimpleCache(
! new MemoryStash(5000),
! new LRUEvictionPolicy(),
! null,
! new GroupMapImpl());
! CacheSingleton.putCache(cacheName, cache);
! }
!
}

***************
*** 86,168 ****
throws IOException, ServletException
{
! HttpServletRequest request = (HttpServletRequest)req;
! HttpServletResponse response = (HttpServletResponse)res;
!
! Date updateTime = null;
! try {
! updateTime = getLastPublishedDate(request);
!
! // Check the incoming if-modified-since header
! Date sinceDate = new
Date(request.getDateHeader("If-Modified-Since"));
!
! // Check to see if we should return NOT MODIFIED
! mLogger.debug("Got If-Modified-Since: "+sinceDate);
! if ( updateTime.compareTo(sinceDate) <= 0 )
! {
! mLogger.debug("Returning 304 NOT MODIFIED");
! ((HttpServletResponse)response).setStatus(
! HttpServletResponse.SC_NOT_MODIFIED);

! return;
! }

- } catch (RollerException e) {
- // Thrown by getLastPublishedDate if there is a db-type error
- mLogger.debug("Returning BAD REQUEST");
- response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

- return;
- } catch (IllegalArgumentException e) {
- // Thrown by getDateHeader if not in valid format
- // This can be safely ignored, the only consequence is that the
NOT MODIFIED
- // response is not set.
- }
-
-
-
chain.doFilter(request, response);
!
// Set outgoing last modified header
! ((HttpServletResponse)response).setDateHeader(
! "Last-Modified", updateTime.getTime());
}

! private Date getLastPublishedDate(HttpServletRequest request)
! throws RollerException {
! // Get user name without using heavy RollerRequest URL parser
! String userName = null;
! String pathInfo = request.getPathInfo();
! pathInfo = pathInfo!=null ? pathInfo : "";
! String[] pathInfoArray = StringUtils.split(pathInfo,"/");
! if ( pathInfoArray.length > 0 ) userName = pathInfoArray[0];

! // Get last pub time for specific weblog category requested
! String catname =
!
request.getParameter(RollerRequest.WEBLOGCATEGORYNAME_KEY);
! Date updateTime = new Date();

! Roller roller = RollerContext.getRoller(request);
! WeblogManager wmgr= roller.getWeblogManager();

! // update times are cached to reduce database queries per
request
! String key = userName+"|"+catname;

! updateTime = (Date)cache.retrieve(key);
! if ( updateTime == null )
! {
! updateTime =
wmgr.getWeblogLastPublishTime(userName,catname);
!
! // cache update times for 15 minutes
! cache.store(key,updateTime,
! new Long(System.currentTimeMillis() +
15*60*60),null);
! mLogger.debug("Storing updateTime in cache for key:
"+key);
! }
! else
! {
! mLogger.debug("Retreived updateTime from cache for key:
"+key);
! }

! mLogger.debug("Last update time for "+userName
! +"/"+catname+" is: "+updateTime);
! return updateTime;
! }

/**
--- 89,186 ----
throws IOException, ServletException
{
! HttpServletRequest request = (HttpServletRequest) req;
! HttpServletResponse response = (HttpServletResponse) res;
!
! Date updateTime = null;
! try
! {
! updateTime = getLastPublishedDate(request);
!
! // Check the incoming if-modified-since header
! Date sinceDate =
! new Date(request.getDateHeader("If-Modified-Since"));
!
! // Check to see if we should return NOT MODIFIED
! mLogger.debug("Got If-Modified-Since: " + sinceDate);
! if (updateTime.compareTo(sinceDate) <= 0)
! {
! mLogger.debug("Returning 304 NOT MODIFIED");
! ((HttpServletResponse) response).setStatus(
! HttpServletResponse.SC_NOT_MODIFIED);
! return;
! }
!
! }
! catch (RollerException e)
! {
! // Thrown by getLastPublishedDate if there is a db-type error
! mLogger.debug("Returning BAD REQUEST");
! response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
! return;
! }
! catch (IllegalArgumentException e)
! {
! // Thrown by getDateHeader if not in valid format
! // This can be safely ignored, the only consequence is that the
NOT MODIFIED
! // response is not set.
! }

chain.doFilter(request, response);
!
// Set outgoing last modified header
! ((HttpServletResponse) response).setDateHeader(
! "Last-Modified",
! updateTime.getTime());
}

! private Date getLastPublishedDate(HttpServletRequest request)
! throws RollerException
! {
! // Get user name without using heavy RollerRequest URL parser
! String userName = null;
! String pathInfo = request.getPathInfo();
! pathInfo = pathInfo != null ? pathInfo : "";
! String[] pathInfoArray = StringUtils.split(pathInfo, "/");
! if (pathInfoArray.length > 0)
! userName = pathInfoArray[0];

! // Get last pub time for specific weblog category requested
! String catname =
! request.getParameter(RollerRequest.WEBLOGCATEGORYNAME_KEY);
! Date updateTime = new Date();

! Roller roller = RollerContext.getRoller(request);
! WeblogManager wmgr = roller.getWeblogManager();

! // update times are cached to reduce database queries per request
! String key = userName + "|" + catname;

! updateTime = (Date) cache.retrieve(key);
! if (updateTime == null)
! {
! updateTime = wmgr.getWeblogLastPublishTime(userName, catname);

! // cache update times for 15 minutes
! cache.store(
! key,
! updateTime,
! new Long(System.currentTimeMillis() + 15 * 60 * 60),
! null);
! mLogger.debug("Storing updateTime in cache for key: " + key);
! }
! else
! {
! mLogger.debug("Retreived updateTime from cache for key: " + key);
! }
!
! mLogger.debug(
! "Last update time for "
! + userName
! + "/"
! + catname
! + " is: "
! + updateTime);
! return updateTime;
! }

/**
***************
*** 171,176 ****
public void destroy()
{
! cache.clear();
}
!
}
--- 189,194 ----
public void destroy()
{
! cache.clear();
}
!
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise