001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.rendering.velocity.deprecated;
020:
021: import java.util.HashSet;
022: import java.util.Set;
023: import javax.servlet.http.HttpServletRequest;
024: import org.apache.commons.lang.StringUtils;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.roller.RollerException;
028: import org.apache.roller.pojos.WeblogTemplate;
029:
030: /**
031: * Represents a request for an *old* Roller weblog feed.
032: *
033: * any of /rss/*, /atom/*, /flavor/*
034: *
035: * While these urls are no longer used we do provide redirect support for them
036: * for users who have upgraded from earlier versions. We keep this class to
037: * help with parsing these urls since they are fairly complex.
038: */
039: public class OldFeedRequest {
040:
041: private static Log mLogger = LogFactory
042: .getLog(OldFeedRequest.class);
043:
044: private static Set feedServlets = new HashSet();
045:
046: private String context = null;
047: private String flavor = null;
048: private String weblogHandle = null;
049: private String weblogCategory = null;
050: private boolean excerpts = false;
051:
052: static {
053: // initialize our servlet list
054: feedServlets.add("rss");
055: feedServlets.add("flavor");
056: feedServlets.add("atom");
057: }
058:
059: /**
060: * Construct the WeblogFeedRequest by parsing the incoming url
061: */
062: public OldFeedRequest(HttpServletRequest request) throws Exception {
063:
064: // parse the request object and figure out what we've got
065: mLogger.debug("parsing url " + request.getRequestURL());
066:
067: String servlet = request.getServletPath();
068: String pathInfo = request.getPathInfo();
069:
070: // what servlet is our destination?
071: if (servlet != null) {
072: // strip off the leading slash
073: servlet = servlet.substring(1);
074:
075: if (feedServlets.contains(servlet)) {
076: this .context = "weblog";
077: this .flavor = servlet;
078: } else {
079: // not a request to a feed servlet
080: throw new Exception("not a weblog feed request, "
081: + request.getRequestURL());
082: }
083: } else {
084: throw new Exception("not a weblog feed request, "
085: + request.getRequestURL());
086: }
087:
088: // parse the path info
089: if (pathInfo != null && pathInfo.trim().length() > 1) {
090: // strip off the leading slash
091: pathInfo = pathInfo.substring(1);
092: String[] pathElements = pathInfo.split("/");
093:
094: if (pathElements[0].length() > 0) {
095: this .weblogHandle = pathElements[0];
096: }
097:
098: } else {
099:
100: // no path info means this was a non-weblog request
101: // we handle a few exceptions for this which include
102: // /rss - main rss feed
103: // /atom - main atom feed
104: // /flavor - main flavor feed
105:
106: this .context = "main";
107: }
108:
109: /*
110: * parse request parameters
111: *
112: * the only params we currently care about are:
113: * flavor - defines the feed type
114: * catname - specifies a weblog category
115: * path - specifies a weblog category
116: * excerpts - specifies the feed should only include excerpts
117: *
118: */
119: if (request.getParameter("flavor") != null) {
120: this .flavor = request.getParameter("flavor");
121: }
122:
123: if (request.getParameter("path") != null) {
124: this .weblogCategory = request.getParameter("path");
125: }
126:
127: if (request.getParameter("catname") != null) {
128: this .weblogCategory = request.getParameter("catname");
129: }
130:
131: if (request.getParameter("excerpts") != null) {
132: this .excerpts = Boolean.valueOf(
133: request.getParameter("excerpts")).booleanValue();
134: }
135:
136: // one small final adjustment.
137: // if our flavor is "flavor" then that means someone is just getting
138: // the default flavor, which is rss, so let's set that
139: if (this .flavor.equals("flavor")) {
140: this .flavor = "rss";
141: }
142:
143: }
144:
145: public String getContext() {
146: return context;
147: }
148:
149: public String getFlavor() {
150: return flavor;
151: }
152:
153: public String getWeblogHandle() {
154: return weblogHandle;
155: }
156:
157: public String getWeblogCategory() {
158: return weblogCategory;
159: }
160:
161: public boolean isExcerpts() {
162: return excerpts;
163: }
164:
165: }
|