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 2005/12/12 19:59:42 UTC
svn commit: r356328 - in /incubator/roller/trunk/src/org/roller/presentation:
InvalidRequestException.java ParsedRequest.java PlanetRequest.java
WeblogFeedRequest.java WeblogPageRequest.java
Author: agilliland
Date: Mon Dec 12 10:59:30 2005
New Revision: 356328
URL: http://svn.apache.org/viewcvs?rev=356328&view=rev
Log:
some request processing improvements.
- A ParsedRequest now throws an InvalidRequestException when there is a problem parsing a request, rather than the more generic RollerException.
- Created a PlanetRequest object to handle all Planet requests.
- Removed logic about handling planet rss feed from WeblogFeedRequest.
Added:
incubator/roller/trunk/src/org/roller/presentation/InvalidRequestException.java
incubator/roller/trunk/src/org/roller/presentation/PlanetRequest.java
Modified:
incubator/roller/trunk/src/org/roller/presentation/ParsedRequest.java
incubator/roller/trunk/src/org/roller/presentation/WeblogFeedRequest.java
incubator/roller/trunk/src/org/roller/presentation/WeblogPageRequest.java
Added: incubator/roller/trunk/src/org/roller/presentation/InvalidRequestException.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/InvalidRequestException.java?rev=356328&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/InvalidRequestException.java (added)
+++ incubator/roller/trunk/src/org/roller/presentation/InvalidRequestException.java Mon Dec 12 10:59:30 2005
@@ -0,0 +1,25 @@
+/*
+ * InvalidRequestException.java
+ *
+ * Created on December 12, 2005, 9:49 AM
+ */
+
+package org.roller.presentation;
+
+/**
+ * An InvalidRequestException is thrown by the ParsedRequest class or any of
+ * its subclasses when the request being parsed is invalid in any way.
+ *
+ * @author Allen Gilliland
+ */
+public class InvalidRequestException extends Exception {
+
+ public InvalidRequestException(String msg) {
+ super(msg);
+ }
+
+ public InvalidRequestException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+}
Modified: incubator/roller/trunk/src/org/roller/presentation/ParsedRequest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/ParsedRequest.java?rev=356328&r1=356327&r2=356328&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/ParsedRequest.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/ParsedRequest.java Mon Dec 12 10:59:30 2005
@@ -40,7 +40,7 @@
* This abstract version of the constructor gathers info likely to be
* relevant to all requests to Roller.
*/
- public ParsedRequest(HttpServletRequest request) throws Exception {
+ public ParsedRequest(HttpServletRequest request) throws InvalidRequestException {
// keep a reference to the original request
this.request = request;
Added: incubator/roller/trunk/src/org/roller/presentation/PlanetRequest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/PlanetRequest.java?rev=356328&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/PlanetRequest.java (added)
+++ incubator/roller/trunk/src/org/roller/presentation/PlanetRequest.java Mon Dec 12 10:59:30 2005
@@ -0,0 +1,95 @@
+/*
+ * PlanetRequest.java
+ *
+ * Created on December 12, 2005, 9:47 AM
+ */
+
+package org.roller.presentation;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * Represents a request for a Planet Roller url.
+ *
+ * currently ... /planet.do and /planetrss
+ *
+ * @author Allen Gilliland
+ */
+public class PlanetRequest extends ParsedRequest {
+
+ private static Log mLogger = LogFactory.getLog(PlanetRequest.class);
+
+ private String context = null;
+ private String type = null;
+ private String flavor = null;
+ private boolean excerpts = false;
+
+
+ /**
+ * Construct the PlanetRequest by parsing the incoming url
+ */
+ public PlanetRequest(HttpServletRequest request) throws InvalidRequestException {
+
+ super(request);
+
+ // parse the request object and figure out what we've got
+ mLogger.debug("parsing url "+request.getRequestURL());
+
+ String servlet = request.getServletPath();
+
+ // what servlet is our destination?
+ if(servlet != null) {
+ // strip off the leading slash
+ servlet = servlet.substring(1);
+
+ if(servlet.equals("planet.do")) {
+ this.context = "planet";
+ this.type = "page";
+ } else if(servlet.equals("planetrss")) {
+ this.context = "planet";
+ this.type = "feed";
+ this.flavor = "rss";
+ } else {
+ // not a request to a feed servlet
+ throw new InvalidRequestException("not a planet request, "+request.getRequestURL());
+ }
+
+ } else {
+ throw new InvalidRequestException("not a planet request, "+request.getRequestURL());
+ }
+
+
+ /*
+ * parse request parameters
+ *
+ * the only params we currently care about are:
+ * excerpts - specifies the feed should only include excerpts
+ *
+ */
+ if(request.getParameter("excerpts") != null) {
+ this.excerpts = Boolean.valueOf(request.getParameter("excerpts")).booleanValue();
+ }
+
+ }
+
+
+ public String getContext() {
+ return context;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getFlavor() {
+ return flavor;
+ }
+
+ public boolean isExcerpts() {
+ return excerpts;
+ }
+
+}
Modified: incubator/roller/trunk/src/org/roller/presentation/WeblogFeedRequest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/WeblogFeedRequest.java?rev=356328&r1=356327&r2=356328&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/WeblogFeedRequest.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/WeblogFeedRequest.java Mon Dec 12 10:59:30 2005
@@ -19,7 +19,7 @@
/**
* Represents a request for a Roller weblog feed.
*
- * any of /rss/*, /atom/*, /flavor/*, or /planetrss
+ * any of /rss/*, /atom/*, /flavor/*
*
* We use this class as a helper to parse an incoming url and sort out the
* information embedded in the url for later use.
@@ -44,14 +44,13 @@
feedServlets.add("rss");
feedServlets.add("flavor");
feedServlets.add("atom");
- feedServlets.add("planetrss");
}
/**
* Construct the WeblogFeedRequest by parsing the incoming url
*/
- public WeblogFeedRequest(HttpServletRequest request) throws Exception {
+ public WeblogFeedRequest(HttpServletRequest request) throws InvalidRequestException {
super(request);
@@ -71,8 +70,10 @@
this.flavor = servlet;
} else {
// not a request to a feed servlet
- throw new RollerException("not a weblog feed request, "+request.getRequestURL());
+ throw new InvalidRequestException("not a weblog feed request, "+request.getRequestURL());
}
+ } else {
+ throw new InvalidRequestException("not a weblog feed request, "+request.getRequestURL());
}
// parse the path info
@@ -90,17 +91,10 @@
// no path info means this was a non-weblog request
// we handle a few exceptions for this which include
// /rss - main rss feed
- // /planetrss - main planet rss feed
// /atom - main atom feed
// /flavor - main flavor feed
- if(servlet.equals("rss") || servlet.equals("atom") ||
- servlet.equals("flavor")) {
-
- this.context = "main";
- } else if(servlet.equals("planetrss")) {
-
- this.context = "planet";
- }
+
+ this.context = "main";
}
/*
Modified: incubator/roller/trunk/src/org/roller/presentation/WeblogPageRequest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/WeblogPageRequest.java?rev=356328&r1=356327&r2=356328&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/WeblogPageRequest.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/WeblogPageRequest.java Mon Dec 12 10:59:30 2005
@@ -50,7 +50,7 @@
/**
* Construct the WeblogPageRequest by parsing the incoming url
*/
- public WeblogPageRequest(HttpServletRequest request) throws Exception {
+ public WeblogPageRequest(HttpServletRequest request) throws InvalidRequestException {
// let our parent take care of their business first
super(request);
@@ -70,10 +70,13 @@
this.context = "weblog";
} else {
// not a request to the page servlet
- throw new RollerException("not a weblog page request, "+request.getRequestURL());
+ throw new InvalidRequestException("not a weblog page request, "+request.getRequestURL());
}
+ } else {
+ throw new InvalidRequestException("not a weblog page request, "+request.getRequestURL());
}
+
/*
* parse path info
*
@@ -138,7 +141,7 @@
} else {
// invalid request ... path info is empty
- throw new RollerException("not a weblog page request, "+request.getRequestURL());
+ throw new InvalidRequestException("not a weblog page request, "+request.getRequestURL());
}