You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/07/14 01:36:17 UTC
svn commit: r421735 -
/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
Author: agilliland
Date: Thu Jul 13 16:36:17 2006
New Revision: 421735
URL: http://svn.apache.org/viewvc?rev=421735&view=rev
Log:
adding request validation to page servlet.
- if permalink is specified the entry must exist.
- if category is specified the category must exist.
Modified:
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java?rev=421735&r1=421734&r2=421735&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java Thu Jul 13 16:36:17 2006
@@ -129,10 +129,7 @@
try {
pageRequest = new WeblogPageRequest(request);
- // lookup weblog specified by feed request
- UserManager uMgr = RollerFactory.getRoller().getUserManager();
- weblog = uMgr.getWebsiteByHandle(pageRequest.getWeblogHandle());
-
+ weblog = pageRequest.getWeblog();
if(weblog == null) {
throw new RollerException("unable to lookup weblog: "+
pageRequest.getWeblogHandle());
@@ -145,55 +142,6 @@
}
- // figure out what we are going to render
- Template page = null;
-
- // If this is a popup request, then deal with it specially
- if (request.getParameter("popup") != null) {
- try {
- // Does user have a popupcomments page?
- page = weblog.getPageByName("_popupcomments");
- } catch(Exception e ) {
- // ignored ... considered page not found
- }
-
- // User doesn't have one so return the default
- if(page == null) {
- page = new WeblogTemplate("templates/weblog/popupcomments.vm", weblog,
- "Comments", "Comments", "dummy_link",
- "dummy_template", new Date());
- }
-
- // If request specified the page, then go with that
- } else if (pageRequest.getWeblogPageName() != null) {
- try {
- page = weblog.getPageByLink(pageRequest.getWeblogPageName());
- } catch(Exception e) {
- log.error("Error getting page: "+pageRequest.getWeblogPageName(), e);
- }
-
- // If page not available from request, then use weblog's default
- } else {
- try {
- page = weblog.getDefaultPage();
- } catch(Exception e) {
- log.error("Error getting weblogs default page", e);
- }
- }
-
- // Still no page? Then that is a 404
- if (page == null) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- // validation
- // 1. locale is valid
- // 2. permalink entry exists
- // 3. category exits
-
- log.debug("page found, dealing with it");
-
// 304 if-modified-since checking
long sinceDate = request.getDateHeader("If-Modified-Since");
log.debug("since date = "+sinceDate);
@@ -203,8 +151,9 @@
return;
}
+
// set the content type
- String pageLink = page.getLink();
+ String pageLink = pageRequest.getWeblogPageName();
String mimeType = RollerContext.getServletContext().getMimeType(pageLink);
if(mimeType != null) {
// we found a match ... set the content type
@@ -216,21 +165,17 @@
// set last-modified date
response.setDateHeader("Last-Modified", weblog.getLastModified().getTime());
+
// cached content checking
String cacheKey = this.CACHE_ID+":"+this.generateKey(pageRequest);
if((!this.excludeOwnerPages || !pageRequest.isLoggedIn()) &&
request.getAttribute("skipCache") == null) {
- // we need the last expiration time for the given weblog
- long lastExpiration = 0;
- Date lastExpirationDate =
- (Date) CacheManager.getLastExpiredDate(pageRequest.getWeblogHandle());
- if(lastExpirationDate != null)
- lastExpiration = lastExpirationDate.getTime();
LazyExpiringCacheEntry entry =
(LazyExpiringCacheEntry) this.contentCache.get(cacheKey);
if(entry != null) {
- CachedContent cachedContent = (CachedContent) entry.getValue(lastExpiration);
+ CachedContent cachedContent =
+ (CachedContent) entry.getValue(weblog.getLastModified().getTime());
if(cachedContent != null) {
log.debug("HIT "+cacheKey);
@@ -250,6 +195,78 @@
}
}
+
+ // figure out what we are going to render
+ Template page = null;
+
+ // If this is a popup request, then deal with it specially
+ if (request.getParameter("popup") != null) {
+ try {
+ // Does user have a popupcomments page?
+ page = weblog.getPageByName("_popupcomments");
+ } catch(Exception e ) {
+ // ignored ... considered page not found
+ }
+
+ // User doesn't have one so return the default
+ if(page == null) {
+ page = new WeblogTemplate("templates/weblog/popupcomments.vm", weblog,
+ "Comments", "Comments", "dummy_link",
+ "dummy_template", new Date());
+ }
+
+ // If request specified the page, then go with that
+ } else if (pageRequest.getWeblogPageName() != null) {
+ try {
+ page = weblog.getPageByLink(pageRequest.getWeblogPageName());
+ } catch(Exception e) {
+ log.error("Error getting page: "+pageRequest.getWeblogPageName(), e);
+ }
+
+ // If page not available from request, then use weblog's default
+ } else {
+ try {
+ page = weblog.getDefaultPage();
+ } catch(Exception e) {
+ log.error("Error getting weblogs default page", e);
+ }
+ }
+
+ // Still no page? Then that is a 404
+ if (page == null) {
+ if(!response.isCommitted()) response.reset();
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
+ log.debug("page found, dealing with it");
+
+ // validation
+ boolean invalid = false;
+ if(pageRequest.getWeblogAnchor() != null) {
+
+ // permalink specified. entry must exist and locale must match
+ if(pageRequest.getWeblogEntry() == null) {
+ invalid = true;
+ } else if (pageRequest.getLocale() != null &&
+ !pageRequest.getLocale().equals(pageRequest.getWeblogEntry().getLocale())) {
+ invalid = true;
+ }
+
+ } else if(pageRequest.getWeblogCategoryName() != null) {
+
+ // category specified. category must exist.
+ if(pageRequest.getWeblogCategory() == null) {
+ invalid = true;
+ }
+ }
+
+ if(invalid) {
+ if(!response.isCommitted()) response.reset();
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
// looks like we need to render content
HashMap model = new HashMap();