roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r417633 - in /incubator/roller/branches/roller_3.0: metadata/xdoclet/ src/org/apache/roller/ui/rendering/ src/org/apache/roller/ui/rendering/servlets/ src/org/apache/roller/ui/rendering/util/
Date Wed, 28 Jun 2006 01:58:12 GMT
Author: agilliland
Date: Tue Jun 27 18:58:11 2006
New Revision: 417633

URL: http://svn.apache.org/viewvc?rev=417633&view=rev
Log:
moving first batch of servlets to new urls and enabling request mapping to support new url
structure.

- updated servlet endpoints for most content rendering servlets

- updated various parsed weblog request objects to make better use of object hierarchy and
to keep up with urls supported by new url structure

- some minor tweaks to weblog request mapper

- updated filter mappings to enable request mapping filter

NOTE: this commit will break a lot of urls for existing weblog pages because we still need
to go in and update the way urls are constructed so that they are formed using the new url
structure, that will happen soon.



Modified:
    incubator/roller/branches/roller_3.0/metadata/xdoclet/filter-mappings.xml
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PreviewServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogFeedRequest.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogPageRequest.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogRequest.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogSearchRequest.java

Modified: incubator/roller/branches/roller_3.0/metadata/xdoclet/filter-mappings.xml
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/metadata/xdoclet/filter-mappings.xml?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/metadata/xdoclet/filter-mappings.xml (original)
+++ incubator/roller/branches/roller_3.0/metadata/xdoclet/filter-mappings.xml Tue Jun 27 18:58:11
2006
@@ -10,13 +10,6 @@
      commented out for Servlet API 2.3 containers, like Tomcat 4.x and Resin 2.x.
 -->
 
-<!--
-<filter-mapping>
-    <filter-name>UrlRewriteFilter</filter-name>
-    <url-pattern>/*</url-pattern>
-</filter-mapping>
--->
-
 <!-- Ensures character encoding set to UTF-8 and JSTL and Struts locales are in sync.
 Note: Any filters preceding this one MUST not cause request parsing. -->
 <filter-mapping>
@@ -49,10 +42,14 @@
     <dispatcher>FORWARD</dispatcher>
 </filter-mapping>
 
+<filter-mapping>
+    <filter-name>RequestMappingFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+</filter-mapping>
 
 <filter-mapping>
     <filter-name>RefererFilter</filter-name>
-    <url-pattern>/page/*</url-pattern>
+    <url-pattern>/roller-ui/rendering/page/*</url-pattern>
 </filter-mapping>
 
 <filter-mapping>
@@ -61,50 +58,18 @@
 </filter-mapping>
 
 
-<filter-mapping>
-    <filter-name>IfPlanetModifiedFilter</filter-name>
-    <url-pattern>/planetrss/*</url-pattern>
-</filter-mapping>
-
-
-<!-- Compression Filters -->
-<filter-mapping>
-    <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/page/*</url-pattern>
-</filter-mapping>
-<filter-mapping>
-    <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/planet.do</url-pattern>
-</filter-mapping>
-<filter-mapping>
-    <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/main.do</url-pattern>
-</filter-mapping>
-
+<!-- Compression Filter -->
 <filter-mapping>
     <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/atom/*</url-pattern>
+    <url-pattern>/roller-ui/rendering/page/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
     <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/rss/*</url-pattern>
+    <url-pattern>/roller-ui/rendering/feed/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
     <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/flavor/*</url-pattern>
-</filter-mapping>
-<filter-mapping>
-    <filter-name>CompressionFilter</filter-name>
-    <url-pattern>/foaf/*</url-pattern>
-</filter-mapping>
-
-
-<!-- Main Page Caching -->
-<filter-mapping>
-	<filter-name>MainPageCacheFilter</filter-name>
-	<url-pattern>/main.do</url-pattern>
-	<dispatcher>REQUEST</dispatcher>
-	<dispatcher>FORWARD</dispatcher>
+    <url-pattern>/planet.do</url-pattern>
 </filter-mapping>
 
 
@@ -114,6 +79,10 @@
 	<url-pattern>/planet.do</url-pattern>
 	<dispatcher>REQUEST</dispatcher>
 	<dispatcher>FORWARD</dispatcher>
+</filter-mapping>
+<filter-mapping>
+    <filter-name>IfPlanetModifiedFilter</filter-name>
+    <url-pattern>/planetrss/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
     <filter-name>PlanetCacheFilter</filter-name>

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java
Tue Jun 27 18:58:11 2006
@@ -44,10 +44,11 @@
     
     private static Log log = LogFactory.getLog(WeblogRequestMapper.class);
     
-    private static final String PAGE_SERVLET = "/page";
-    private static final String FEED_SERVLET = "/flavor";
-    private static final String RESOURCE_SERVLET = "/resource";
-    private static final String SEARCH_SERVLET = "/search";
+    private static final String PAGE_SERVLET = "/roller-ui/rendering/page";
+    private static final String FEED_SERVLET = "/roller-ui/rendering/feed";
+    private static final String RESOURCE_SERVLET = "/roller-ui/rendering/resources";
+    private static final String SEARCH_SERVLET = "/roller-ui/rendering/search";
+    private static final String RSD_SERVLET = "/roller-ui/rendering/rsd";
     
     // url patterns that are not allowed to be considered weblog handles
     Set restricted = null;
@@ -103,7 +104,7 @@
         
         // check if it's a valid weblog handle
         if(restricted.contains(weblogHandle) || !this.isWeblog(weblogHandle)) {
-            log.debug("DENIED "+weblogHandle);
+            log.debug("SKIPPED "+weblogHandle);
             return false;
         }
         
@@ -111,8 +112,9 @@
         
         // parse the rest of the url and build forward url
         if(pathInfo != null) {
+            
             // parse the next portion of the url
-            // we expect [locale]/<context>/<extra>/<info>
+            // we expect [locale/]<context>/<extra>/<info>
             String[] urlPath = pathInfo.split("/", 3);
             
             // if we have a locale, deal with it
@@ -241,6 +243,17 @@
             forwardUrl.append(SEARCH_SERVLET);
             forwardUrl.append("/");
             forwardUrl.append(handle);
+            
+        // requests handled by RSDServlet
+        } else if(context.equals("rsd")) {
+            
+            forwardUrl.append(RSD_SERVLET);
+            forwardUrl.append("/");
+            forwardUrl.append(handle);
+            
+        // unsupported url
+        } else {
+            return null;
         }
         
         log.debug("FORWARD_URL "+forwardUrl.toString());

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
Tue Jun 27 18:58:11 2006
@@ -61,7 +61,7 @@
  * Responsible for rendering weblog feeds.
  *
  * @web.servlet name="FeedServlet" load-on-startup="5"
- * @web.servlet-mapping url-pattern="/feeds/*"
+ * @web.servlet-mapping url-pattern="/roller-ui/rendering/feed/*"
  */ 
 public class FeedServlet extends HttpServlet implements CacheHandler {
     
@@ -131,8 +131,8 @@
                         feedRequest.getWeblogHandle());
             }
         } catch(Exception e) {
-            // some kind of error parsing the request
-            log.error("error creating weblog feed request", e);
+            // invalid feed request format or weblog doesn't exist
+            log.debug("error creating weblog feed request", e);
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
             return;
         }

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=417633&r1=417632&r2=417633&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
Tue Jun 27 18:58:11 2006
@@ -63,7 +63,7 @@
  * Responsible for rendering weblog pages.
  *
  * @web.servlet name="PageServlet" load-on-startup="5"
- * @web.servlet-mapping url-pattern="/page/*"
+ * @web.servlet-mapping url-pattern="/roller-ui/rendering/page/*"
  */
 public class PageServlet extends HttpServlet implements CacheHandler {
     
@@ -141,8 +141,8 @@
                         pageRequest.getWeblogHandle());
             }
         } catch (Exception e) {
-            // some kind of error parsing the request
-            log.error("error creating page request", e);
+            // some kind of error parsing the request or looking up weblog
+            log.debug("error creating page request", e);
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
             return;
         }
@@ -359,10 +359,9 @@
     private String generateKey(WeblogPageRequest pageRequest) {
         
         StringBuffer key = new StringBuffer();
-        key.append("weblog/");
+        key.append("weblog/page/");
         key.append(pageRequest.getWeblogHandle().toLowerCase());
-        key.append("/page/");
-        key.append(pageRequest.getPageType());
+        key.append("/").append(pageRequest.getContext());
         
         if(pageRequest.getWeblogAnchor() != null) {
             // convert to base64 because there can be spaces in anchors :/

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PreviewServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PreviewServlet.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PreviewServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PreviewServlet.java
Tue Jun 27 18:58:11 2006
@@ -50,7 +50,7 @@
  * Responsible for rendering weblog page previews.
  *
  * @web.servlet name="PreviewServlet" load-on-startup="7"
- * @web.servlet-mapping url-pattern="/preview/*"
+ * @web.servlet-mapping url-pattern="/roller-ui/rendering/preview/*"
  */
 public class PreviewServlet extends HttpServlet {
     
@@ -147,14 +147,7 @@
         log.debug("preview page found, dealing with it");
         
         // set the content type
-        String pageLink = page.getLink();
-        String mimeType = RollerContext.getServletContext().getMimeType(pageLink);
-        if(mimeType != null) {
-            // we found a match ... set the content type
-            response.setContentType(mimeType+"; charset=utf-8");
-        } else {
-            response.setContentType("text/html; charset=utf-8");
-        }
+        response.setContentType("text/html; charset=utf-8");
         
         // looks like we need to render content
         Map model = new HashMap();

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/RSDServlet.java
Tue Jun 27 18:58:11 2006
@@ -46,7 +46,7 @@
  * level of content caching.
  *
  * @web.servlet name="RSDServlet" load-on-startup="7"
- * @web.servlet-mapping url-pattern="/rsd/*"
+ * @web.servlet-mapping url-pattern="/roller-ui/rendering/rsd/*"
  */
 public class RSDServlet extends HttpServlet {
     
@@ -84,17 +84,10 @@
             UserManager userMgr = RollerFactory.getRoller().getUserManager();
             weblog = userMgr.getWebsiteByHandle(weblogRequest.getWeblogHandle(), Boolean.TRUE);
             
-        } catch(InvalidRequestException ire) {
-            // An error initializing the request is considered to be a 404
+        } catch(Exception e) {
+            // invalid rsd request format or weblog doesn't exist
+            log.debug("error creating weblog request", e);
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
-            log.error("Bad Request: "+ire.getMessage());
-            return;
-            
-        } catch(RollerException re) {
-            // error looking up the weblog, we assume it doesn't exist
-            response.sendError(HttpServletResponse.SC_NOT_FOUND);
-            log.warn("Unable to lookup weblog ["+
-                    weblogRequest.getWeblogHandle()+"] "+re.getMessage());
             return;
         }
         

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
Tue Jun 27 18:58:11 2006
@@ -45,7 +45,7 @@
  * @author Allen Gilliland
  *
  * @web.servlet name="ResourcesServlet"
- * @web.servlet-mapping url-pattern="/resources/*"
+ * @web.servlet-mapping url-pattern="/roller-ui/rendering/resources/*"
  */
 public class ResourceServlet extends HttpServlet {
     

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
Tue Jun 27 18:58:11 2006
@@ -50,7 +50,7 @@
  * Handles search queries for weblogs.
  *
  * @web.servlet name="SearchServlet" load-on-startup="5"
- * @web.servlet-mapping url-pattern="/search/*"
+ * @web.servlet-mapping url-pattern="/roller-ui/rendering/search/*"
  */
 public class SearchServlet extends HttpServlet {
     
@@ -87,17 +87,10 @@
             UserManager userMgr = RollerFactory.getRoller().getUserManager();
             weblog = userMgr.getWebsiteByHandle(searchRequest.getWeblogHandle(), Boolean.TRUE);
             
-        } catch(InvalidRequestException ire) {
-            // An error initializing the request is considered to be a 404
+        } catch(Exception e) {
+            // invalid search request format or weblog doesn't exist
+            log.debug("error creating weblog search request", e);
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
-            log.error("Bad Request: "+ire.getMessage());
-            return;
-            
-        } catch(RollerException re) {
-            // error looking up the weblog, we assume it doesn't exist
-            response.sendError(HttpServletResponse.SC_NOT_FOUND);
-            log.warn("Unable to lookup weblog ["+
-                    searchRequest.getWeblogHandle()+"] "+re.getMessage());
             return;
         }
         

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogFeedRequest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogFeedRequest.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogFeedRequest.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogFeedRequest.java
Tue Jun 27 18:58:11 2006
@@ -33,58 +33,67 @@
  * We use this class as a helper to parse an incoming url and sort out the
  * information embedded in the url for later use.
  */
-public class WeblogFeedRequest extends ParsedRequest {
+public class WeblogFeedRequest extends WeblogRequest {
     
-    private static Log mLogger = LogFactory.getLog(WeblogFeedRequest.class);
+    private static Log log = LogFactory.getLog(WeblogFeedRequest.class);
     
-    private static final String FEED_SERVLET = "/feeds";
+    private static final String FEED_SERVLET = "/roller-ui/rendering/feed";
     
     private String type = null;
     private String format = null;
-    private String weblogHandle = null;
     private String weblogCategory = null;
     private boolean excerpts = false;
     
     
+    public WeblogFeedRequest() {}
+    
+    
     /**
      * Construct the WeblogFeedRequest by parsing the incoming url
      */
-    public WeblogFeedRequest(HttpServletRequest request) throws InvalidRequestException {
+    public WeblogFeedRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
         
+        // let our parent take care of their business first
+        // parent determines weblog handle and locale if specified
         super(request);
         
-        // parse the request object and figure out what we've got
-        mLogger.debug("parsing url "+request.getRequestURL());
-        
         String servlet = request.getServletPath();
-        String pathInfo = request.getPathInfo();
+        
+        // we only want the path info left over from after our parents parsing
+        String pathInfo = this.getPathInfo();
+        
+        // parse the request object and figure out what we've got
+        log.debug("parsing path "+pathInfo);
         
         // was this request bound for the feed servlet?
         if(servlet == null || !FEED_SERVLET.equals(servlet)) {
-            throw new InvalidRequestException("not a weblog feed request, "+request.getRequestURL());
+            throw new InvalidRequestException("not a weblog feed request, "+
+                    request.getRequestURL());
         }
         
+        
         /* 
-         * parse the path info.  must conform to the format below.
-         *
-         * /<weblog>/<type>/<format>
+         * parse the path info.
+         * 
+         * must look like this ...
          *
+         * /<type>/<format>
          */
         if(pathInfo != null && pathInfo.trim().length() > 1) {
-            // strip off the leading slash
-            pathInfo = pathInfo.substring(1);
-            String[] pathElements = pathInfo.split("/");
             
-            if(pathElements.length == 3) {
-                this.weblogHandle = pathElements[0];
-                this.type = pathElements[1];
-                this.format = pathElements[2];
+            String[] pathElements = pathInfo.split("/");
+            if(pathElements.length == 2) {
+                this.type = pathElements[0];
+                this.format = pathElements[1];
             } else {
-                throw new InvalidRequestException("invalid feed path info, "+request.getRequestURL());
+                throw new InvalidRequestException("invalid feed path info, "+
+                        request.getRequestURL());
             }
             
         } else {
-            throw new InvalidRequestException("invalid feed path info, "+request.getRequestURL());
+            throw new InvalidRequestException("invalid feed path info, "+
+                    request.getRequestURL());
         }
         
         
@@ -98,7 +107,8 @@
          */
         if(request.getParameter("cat") != null) {
             try {
-                this.weblogCategory = URLDecoder.decode(request.getParameter("cat"), "UTF-8");
+                this.weblogCategory = 
+                        URLDecoder.decode(request.getParameter("cat"), "UTF-8");
             } catch (UnsupportedEncodingException ex) {
                 // should never happen, utf-8 is always supported by java
             }
@@ -108,27 +118,44 @@
             this.excerpts = Boolean.valueOf(request.getParameter("excerpts")).booleanValue();
         }
         
+        if(log.isDebugEnabled()) {
+            log.debug("type = "+this.type);
+            log.debug("format = "+this.format);
+            log.debug("weblogCategory = "+this.weblogCategory);
+            log.debug("excerpts = "+this.excerpts);
+        }
     }
-    
 
     public String getType() {
         return type;
     }
 
+    public void setType(String type) {
+        this.type = type;
+    }
+
     public String getFormat() {
         return format;
     }
 
-    public String getWeblogHandle() {
-        return weblogHandle;
+    public void setFormat(String format) {
+        this.format = format;
     }
 
     public String getWeblogCategory() {
         return weblogCategory;
     }
 
+    public void setWeblogCategory(String weblogCategory) {
+        this.weblogCategory = weblogCategory;
+    }
+
     public boolean isExcerpts() {
         return excerpts;
     }
 
+    public void setExcerpts(boolean excerpts) {
+        this.excerpts = excerpts;
+    }
+    
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogPageRequest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogPageRequest.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogPageRequest.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogPageRequest.java
Tue Jun 27 18:58:11 2006
@@ -18,38 +18,34 @@
 
 package org.apache.roller.ui.rendering.util;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.pojos.WeblogTemplate;
-import org.apache.roller.ui.rendering.util.InvalidRequestException;
 
 
 /**
  * Represents a request for a Roller weblog page.
  *
- * any url from ... /page/*
+ * any url from ... /roller-ui/rendering/page/*
  *
  * We use this class as a helper to parse an incoming url and sort out the
  * information embedded in the url for later use.
  */
-public class WeblogPageRequest extends ParsedRequest {
+public class WeblogPageRequest extends WeblogRequest {
     
-    private static Log mLogger = LogFactory.getLog(WeblogPageRequest.class);
+    private static Log log = LogFactory.getLog(WeblogPageRequest.class);
     
-    // various page types
-    public static final String MAIN = "main";
-    public static final String PERMALINK = "permalink";
-    public static final String ARCHIVE = "archive";
+    private static final String PAGE_SERVLET = "/roller-ui/rendering/page";
     
     private String context = null;
-    private String pageType = null;
-    private String weblogHandle = null;
     private String weblogAnchor = null;
     private String weblogPage = null;
     private String weblogCategory = null;
     private String weblogDate = null;
+    private int pageNum = 0;
     
     
     public WeblogPageRequest() {}
@@ -58,187 +54,196 @@
     /**
      * Construct the WeblogPageRequest by parsing the incoming url
      */
-    public WeblogPageRequest(HttpServletRequest request) throws InvalidRequestException {
+    public WeblogPageRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
         
         // let our parent take care of their business first
+        // parent determines weblog handle and locale if specified
         super(request);
         
-        // parse the request object and figure out what we've got
-        mLogger.debug("parsing url "+request.getRequestURL());
-        
         String servlet = request.getServletPath();
-        String pathInfo = request.getPathInfo();
         
-        // make sure this request was destined for the page servlet
-        if(servlet != null) {
-            // strip off the leading slash
-            servlet = servlet.substring(1);
-            
-            if("page".equals(servlet)) {
-                this.context = "weblog";
-            } else {
-                // not a request to the page servlet
-                throw new InvalidRequestException("not a weblog page request, "+request.getRequestURL());
-            }
-        } else {
-            throw new InvalidRequestException("not a weblog page request, "+request.getRequestURL());
+        // we only want the path info left over from after our parents parsing
+        String pathInfo = this.getPathInfo();
+        
+        // parse the request object and figure out what we've got
+        log.debug("parsing path "+pathInfo);
+        
+        // was this request bound for the page servlet?
+        if(servlet == null || !PAGE_SERVLET.equals(servlet)) {
+            throw new InvalidRequestException("not a weblog page request, "+
+                    request.getRequestURL());
         }
         
         
         /*
          * parse path info
          *
-         * we expect one of the following forms of urls ...
+         * we expect one of the following forms of url ...
+         *
+         * /entry/<anchor> - permalink
+         * /date/<YYYYMMDD> - date collection view
+         * /category/<category> - category collection view
+         * /page/<pagelink> - custom page
          *
-         * [handle] - get default page for user for today's date
-         * [handle]/[date] - get default page for user for specified date
-         * [handle]/[pagelink] - get specified page for today's date
-         * [handle]/[pagelink]/[date] - get specified page for specified date
-         * [handle]/[pagelink]/[anchor] - get specified page & entry (by anchor)
-         * [handle]/[pagelink]/[date]/[anchor] - get specified page & entry (by anchor)
+         * path info may be null, which indicates the weblog homepage
          */
-        if(pathInfo != null && pathInfo.trim().length() > 1) {
-            // strip off the leading slash
-            pathInfo = pathInfo.substring(1);
-            String[] pathElements = pathInfo.split("/");
+        if(pathInfo != null && pathInfo.trim().length() > 0) {
             
-            if ( pathElements.length == 1 ) {
-                
-                // /handle
-                this.weblogHandle = pathElements[0];
-                this.weblogPage = WeblogTemplate.DEFAULT_PAGE;
-                this.pageType = MAIN;
-                
-            } else if ( pathElements.length == 2 ) {
-                
-                // /handle/date or /handle/page
-                this.weblogHandle = pathElements[0];
-                this.weblogPage = WeblogTemplate.DEFAULT_PAGE;
+            // we should only ever get 2 path elements
+            String[] pathElements = pathInfo.split("/");
+            if(pathElements.length == 2) {
                 
-                if(this.isValidDateString(pathElements[1])) {
-                    this.weblogDate = pathElements[1];
-                    this.pageType = ARCHIVE;
-                } else {
+                this.context = pathElements[0];
+                if("entry".equals(this.context)) {
+                    try {
+                        this.weblogAnchor = 
+                                URLDecoder.decode(pathElements[1], "UTF-8");
+                    } catch (UnsupportedEncodingException ex) {
+                        // should never happen
+                        log.error(ex);
+                    }
+                    
+                } else if("date".equals(this.context)) {
+                    if(this.isValidDateString(pathElements[1])) {
+                        this.weblogDate = pathElements[1];
+                    } else {
+                        throw new InvalidRequestException("invalid date, "+
+                            request.getRequestURL());
+                    }
+                    
+                } else if("category".equals(this.context)) {
+                    try {
+                        this.weblogCategory =
+                                URLDecoder.decode(pathElements[1], "UTF-8");
+                    } catch (UnsupportedEncodingException ex) {
+                        // should never happen
+                        log.error(ex);
+                    }
+                    
+                } else if("page".equals(this.context)) {
                     this.weblogPage = pathElements[1];
-                    this.pageType = MAIN;
-                }
-                
-            } else if ( pathElements.length == 3 ) {
-                
-                // /handle/page/date or /handle/page/anchor
-                this.weblogHandle = pathElements[0];
-                this.weblogPage = pathElements[1];
-                
-                if(this.isValidDateString(pathElements[2])) {
-                    this.weblogDate = pathElements[2];
-                    this.pageType = ARCHIVE;
+                    
                 } else {
-                    this.weblogAnchor = pathElements[2];
-                    this.pageType = PERMALINK;
+                    throw new InvalidRequestException("context "+this.context+
+                            "not supported, "+request.getRequestURL());
                 }
                 
-            } else if ( pathElements.length == 4 ) {
-                
-                // /handle/page/date/anchor
-                this.weblogHandle = pathElements[0];
-                this.weblogPage = pathElements[1];
-                this.weblogDate = pathElements[2];
-                this.weblogAnchor = pathElements[3];
-                this.pageType = PERMALINK;
+            } else {
+                throw new InvalidRequestException("bad path info, "+
+                        request.getRequestURL());
             }
             
         } else {
-            // invalid request ... path info is empty
-            throw new InvalidRequestException("not a weblog page request, "+request.getRequestURL());
+            // default view, weblog homepage
         }
         
         
         /*
          * parse request parameters
          *
-         * the only params we currently care about are:
-         *   anchor - specifies a weblog entry
-         *   entry - specifies a weblog entry
-         *   catname - specifies a weblog category
+         * the only params we currently allow are:
+         *   date - specifies a weblog date string
+         *   cat - specifies a weblog category
+         *
+         * we only allow request params if the path info is null.  this way
+         * we prevent mixing of path based and query param style urls.
          */
-        if(request.getParameter("anchor") != null) {
-            this.weblogAnchor = request.getParameter("anchor");
-            this.pageType = PERMALINK;
+        if(pathInfo == null) {
+            if(request.getParameter("date") != null) {
+                String date = request.getParameter("date");
+                if(this.isValidDateString(date)) {
+                    this.weblogDate = date;
+                } else {
+                    throw new InvalidRequestException("invalid date, "+
+                            request.getRequestURL());
+                }
+            }
+            
+            if(request.getParameter("cat") != null) {
+                try {
+                    this.weblogCategory = 
+                            URLDecoder.decode(request.getParameter("cat"), "UTF-8");
+                } catch (UnsupportedEncodingException ex) {
+                    // should never happen
+                    log.error(ex);
+                }
+            }
         }
         
-        if(request.getParameter("entry") != null) {
-            this.weblogAnchor = request.getParameter("entry");
-            this.pageType = PERMALINK;
+        // page request param is supported in all views
+        if(request.getParameter("page") != null) {
+            String pageInt = request.getParameter("page");
+            try {
+                this.pageNum = Integer.parseInt(pageInt);
+            } catch(NumberFormatException e) {
+                // ignored, bad input
+            }
         }
         
-        if(request.getParameter("catname") != null) {
-            String cat = request.getParameter("catname");
-            
-            this.weblogCategory = cat;
-            this.pageType = ARCHIVE;
+        if(log.isDebugEnabled()) {
+            log.debug("context = "+this.context);
+            log.debug("weblogAnchor = "+this.weblogAnchor);
+            log.debug("weblogDate = "+this.weblogDate);
+            log.debug("weblogCategory = "+this.weblogCategory);
+            log.debug("weblogPage = "+this.weblogPage);
+            log.debug("pageNum = "+this.pageNum);
         }
-        
     }
     
     
     private boolean isValidDateString(String dateString) {
-        return (dateString != null && dateString.length() > 3 && StringUtils.isNumeric(dateString));
+        // string must be all numeric and 6 or 8 characters
+        return (dateString != null && StringUtils.isNumeric(dateString) &&
+                (dateString.length() == 6 || dateString.length() == 8));
     }
-    
+
     public String getContext() {
         return context;
     }
-    
-    public String getWeblogHandle() {
-        return weblogHandle;
-    }
-    
-    public String getWeblogAnchor() {
-        return weblogAnchor;
-    }
-    
-    public String getWeblogPage() {
-        return weblogPage;
-    }
-    
-    public String getWeblogCategory() {
-        return weblogCategory;
-    }
-    
-    public String getWeblogDate() {
-        return weblogDate;
-    }
-    
-    public String getPageType() {
-        return pageType;
-    }
 
     public void setContext(String context) {
         this.context = context;
     }
 
-    public void setPageType(String pageType) {
-        this.pageType = pageType;
-    }
-
-    public void setWeblogHandle(String weblogHandle) {
-        this.weblogHandle = weblogHandle;
+    public String getWeblogAnchor() {
+        return weblogAnchor;
     }
 
     public void setWeblogAnchor(String weblogAnchor) {
         this.weblogAnchor = weblogAnchor;
     }
 
+    public String getWeblogPage() {
+        return weblogPage;
+    }
+
     public void setWeblogPage(String weblogPage) {
         this.weblogPage = weblogPage;
     }
 
+    public String getWeblogCategory() {
+        return weblogCategory;
+    }
+
     public void setWeblogCategory(String weblogCategory) {
         this.weblogCategory = weblogCategory;
     }
 
+    public String getWeblogDate() {
+        return weblogDate;
+    }
+
     public void setWeblogDate(String weblogDate) {
         this.weblogDate = weblogDate;
+    }
+
+    public int getPageNum() {
+        return pageNum;
+    }
+
+    public void setPageNum(int pageNum) {
+        this.pageNum = pageNum;
     }
     
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogRequest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogRequest.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogRequest.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogRequest.java
Tue Jun 27 18:58:11 2006
@@ -19,48 +19,124 @@
 package org.apache.roller.ui.rendering.util;
 
 import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 
 /**
- * Represents a request to single weblog.
- *
+ * Represents a request to a weblog.
+ * 
  * This is a fairly generic parsed request which is only trying to figure out
- * the weblog handle that this request is destined for.
+ * the elements of a weblog request which apply to all weblogs.  We try to 
+ * determine the weblog weblogHandle, if a locale was specified, and then what extra 
+ * path info remains.  The basic format is like this ...
+ * 
+ * /<weblogHandle>[/locale][/extra/path/info]
+ * 
+ * All weblog urls require a weblogHandle, so we ensure that part of the url is
+ * properly specified.  locale is always optional, so we do our best to see
+ * if a locale is specified.  and path info is always optional.
  */
 public class WeblogRequest extends ParsedRequest {
     
+    private static Log log = LogFactory.getLog(WeblogRequest.class);
+    
     private String weblogHandle = null;
+    private String locale = null;
+    private String pathInfo = null;
     
     
     public WeblogRequest() {}
     
     
-    public WeblogRequest(HttpServletRequest request) throws InvalidRequestException {
+    public WeblogRequest(HttpServletRequest request) 
+            throws InvalidRequestException {
         
         // let our parent take care of their business first
         super(request);
         
-        String pathInfo = request.getPathInfo();
+        String path = request.getPathInfo();
+        
+        log.debug("parsing path "+path);
         
-        // we expect a path info of /<handle>/*
-        if(pathInfo != null && pathInfo.trim().length() > 1) {
+        // first, cleanup extra slashes and extract the weblog weblogHandle
+        if(path != null && path.trim().length() > 1) {
+            
             // strip off the leading slash
-            pathInfo = pathInfo.substring(1);
-            String[] pathElements = pathInfo.split("/");
+            path = path.substring(1);
+            
+            // strip off trailing slash if needed
+            if(path.endsWith("/")) {
+                path = path.substring(0, path.length() - 1);
+            }
             
-            if(pathElements[0] != null && pathElements[0].trim().length() > 1)
{
+            String[] pathElements = path.split("/", 2);
+            if(pathElements[0].trim().length() > 0) {
                 this.weblogHandle = pathElements[0];
             } else {
-                // no handle in path info
-                throw new InvalidRequestException("not a weblog request, "+request.getRequestURL());
+                // no weblogHandle in path info
+                throw new InvalidRequestException("not a weblog request, "+
+                        request.getRequestURL());
+            }
+            
+            // if there is more left of the path info then hold onto it
+            if(pathElements.length == 2) {
+                path = pathElements[1];
+            } else {
+                path = null;
             }
+        }
+        
+        // second, check if we have a locale, everything else is extra path info
+        if(path != null && path.trim().length() > 0) {
             
-        } else {
-            // invalid request ... path info is empty
-            throw new InvalidRequestException("not a weblog request, "+request.getRequestURL());
+            String[] pathElements = path.split("/", 2);
+            if(this.isLocale(pathElements[0])) {
+                this.locale = pathElements[0];
+                
+                // everything else is path info
+                if(pathElements.length == 2) {
+                    this.pathInfo = pathElements[1];
+                }
+            } else {
+                // no locale, just extra path info
+                this.pathInfo = path;
+            }
+        }
+        
+        if(log.isDebugEnabled()) {
+            log.debug("handle = "+this.weblogHandle);
+            log.debug("locale = "+this.locale);
+            log.debug("pathInfo = "+this.pathInfo);
         }
     }
     
+
+    /**
+     * Convenience method which determines if the given string is a valid
+     * locale string.
+     */
+    private boolean isLocale(String potentialLocale) {
+        
+        boolean isLocale = false;
+        
+        // we only support 5 character locale strings, so check that first
+        if(potentialLocale != null && potentialLocale.length() == 5) {
+            
+            // now make sure that the format is proper ... e.g. "en_US"
+            // we are not going to be picky about capitalization
+            String[] langCountry = potentialLocale.split("_");
+            if(langCountry.length == 2 && 
+                    langCountry[0] != null && langCountry[0].length() == 2 &&

+                    langCountry[1] != null && langCountry[1].length() == 2) {
+                
+                isLocale = true;
+            }
+        }
+        
+        return isLocale;
+    }
+    
     
     public String getWeblogHandle() {
         return weblogHandle;
@@ -68,6 +144,22 @@
 
     public void setWeblogHandle(String weblogHandle) {
         this.weblogHandle = weblogHandle;
+    }
+    
+    public String getLocale() {
+        return locale;
+    }
+
+    public void setLocale(String locale) {
+        this.locale = locale;
+    }
+
+    public String getPathInfo() {
+        return pathInfo;
+    }
+
+    public void setPathInfo(String pathInfo) {
+        this.pathInfo = pathInfo;
     }
     
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogSearchRequest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogSearchRequest.java?rev=417633&r1=417632&r2=417633&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogSearchRequest.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogSearchRequest.java
Tue Jun 27 18:58:11 2006
@@ -26,17 +26,40 @@
  */
 public class WeblogSearchRequest extends WeblogRequest {
     
+    private static final String SEARCH_SERVLET = "/roller-ui/rendering/search";
+    
     private String query = null;
     private int pageNum = 0;
     private String weblogCategory = null;
     
     
+    public WeblogSearchRequest() {}
+    
+    
     public WeblogSearchRequest(HttpServletRequest request) 
             throws InvalidRequestException {
         
-        // our parent will determine the weblog handle for us
+        // let our parent take care of their business first
+        // parent determines weblog handle and locale if specified
         super(request);
         
+        String servlet = request.getServletPath();
+        
+        // we only want the path info left over from after our parents parsing
+        String pathInfo = this.getPathInfo();
+        
+        // was this request bound for the search servlet?
+        if(servlet == null || !SEARCH_SERVLET.equals(servlet)) {
+            throw new InvalidRequestException("not a weblog search request, "+
+                    request.getRequestURL());
+        }
+        
+        if(pathInfo != null) {
+            throw new InvalidRequestException("invalid path info, "+
+                    request.getRequestURL());
+        }
+        
+        
         /*
          * parse request parameters
          *
@@ -63,17 +86,28 @@
         }
     }
 
-    
     public String getQuery() {
         return query;
     }
 
+    public void setQuery(String query) {
+        this.query = query;
+    }
+
     public int getPageNum() {
         return pageNum;
     }
 
+    public void setPageNum(int pageNum) {
+        this.pageNum = pageNum;
+    }
+
     public String getWeblogCategory() {
         return weblogCategory;
+    }
+
+    public void setWeblogCategory(String weblogCategory) {
+        this.weblogCategory = weblogCategory;
     }
     
 }



Mime
View raw message