KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > velocity > deprecated > OldFeedRequest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.ui.rendering.velocity.deprecated;
20
21 import java.util.HashSet JavaDoc;
22 import java.util.Set JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.roller.RollerException;
28 import org.apache.roller.pojos.WeblogTemplate;
29
30
31 /**
32  * Represents a request for an *old* Roller weblog feed.
33  *
34  * any of /rss/*, /atom/*, /flavor/*
35  *
36  * While these urls are no longer used we do provide redirect support for them
37  * for users who have upgraded from earlier versions. We keep this class to
38  * help with parsing these urls since they are fairly complex.
39  */

40 public class OldFeedRequest {
41     
42     private static Log mLogger = LogFactory.getLog(OldFeedRequest.class);
43     
44     private static Set JavaDoc feedServlets = new HashSet JavaDoc();
45     
46     private String JavaDoc context = null;
47     private String JavaDoc flavor = null;
48     private String JavaDoc weblogHandle = null;
49     private String JavaDoc weblogCategory = null;
50     private boolean excerpts = false;
51     
52     
53     static {
54         // initialize our servlet list
55
feedServlets.add("rss");
56         feedServlets.add("flavor");
57         feedServlets.add("atom");
58     }
59     
60     
61     /**
62      * Construct the WeblogFeedRequest by parsing the incoming url
63      */

64     public OldFeedRequest(HttpServletRequest JavaDoc request) throws Exception JavaDoc {
65         
66         // parse the request object and figure out what we've got
67
mLogger.debug("parsing url "+request.getRequestURL());
68         
69         String JavaDoc servlet = request.getServletPath();
70         String JavaDoc pathInfo = request.getPathInfo();
71         
72         // what servlet is our destination?
73
if(servlet != null) {
74             // strip off the leading slash
75
servlet = servlet.substring(1);
76             
77             if(feedServlets.contains(servlet)) {
78                 this.context = "weblog";
79                 this.flavor = servlet;
80             } else {
81                 // not a request to a feed servlet
82
throw new Exception JavaDoc("not a weblog feed request, "+request.getRequestURL());
83             }
84         } else {
85             throw new Exception JavaDoc("not a weblog feed request, "+request.getRequestURL());
86         }
87         
88         // parse the path info
89
if(pathInfo != null && pathInfo.trim().length() > 1) {
90             // strip off the leading slash
91
pathInfo = pathInfo.substring(1);
92             String JavaDoc[] pathElements = pathInfo.split("/");
93             
94             if(pathElements[0].length() > 0) {
95                 this.weblogHandle = pathElements[0];
96             }
97             
98         } else {
99             
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(request.getParameter("excerpts")).booleanValue();
133         }
134         
135         // one small final adjustment.
136
// if our flavor is "flavor" then that means someone is just getting
137
// the default flavor, which is rss, so let's set that
138
if(this.flavor.equals("flavor")) {
139             this.flavor = "rss";
140         }
141         
142     }
143     
144
145     public String JavaDoc getContext() {
146         return context;
147     }
148
149     public String JavaDoc getFlavor() {
150         return flavor;
151     }
152
153     public String JavaDoc getWeblogHandle() {
154         return weblogHandle;
155     }
156
157     public String JavaDoc getWeblogCategory() {
158         return weblogCategory;
159     }
160
161     public boolean isExcerpts() {
162         return excerpts;
163     }
164
165 }
166
Popular Tags