KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > util > WeblogFeedRequest


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.util;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.roller.RollerException;
25 import org.apache.roller.model.RollerFactory;
26 import org.apache.roller.model.WeblogManager;
27 import org.apache.roller.pojos.WeblogCategoryData;
28 import org.apache.roller.util.URLUtilities;
29
30
31 /**
32  * Represents a request for a Roller weblog feed.
33  *
34  * /roller-ui/rendering/feeds/*
35  *
36  * We use this class as a helper to parse an incoming url and sort out the
37  * information embedded in the url for later use.
38  */

39 public class WeblogFeedRequest extends WeblogRequest {
40     
41     private static Log log = LogFactory.getLog(WeblogFeedRequest.class);
42     
43     private static final String JavaDoc FEED_SERVLET = "/roller-ui/rendering/feed";
44     
45     // lightweight attributes
46
private String JavaDoc type = null;
47     private String JavaDoc format = null;
48     private String JavaDoc weblogCategoryName = null;
49     private boolean excerpts = false;
50     
51     // heavyweight attributes
52
private WeblogCategoryData weblogCategory = null;
53     
54     
55     public WeblogFeedRequest() {}
56     
57     
58     /**
59      * Construct the WeblogFeedRequest by parsing the incoming url
60      */

61     public WeblogFeedRequest(HttpServletRequest JavaDoc request)
62             throws InvalidRequestException {
63         
64         // let our parent take care of their business first
65
// parent determines weblog handle and locale if specified
66
super(request);
67         
68         String JavaDoc servlet = request.getServletPath();
69         
70         // we only want the path info left over from after our parents parsing
71
String JavaDoc pathInfo = this.getPathInfo();
72         
73         // parse the request object and figure out what we've got
74
log.debug("parsing path "+pathInfo);
75         
76         // was this request bound for the feed servlet?
77
if(servlet == null || !FEED_SERVLET.equals(servlet)) {
78             throw new InvalidRequestException("not a weblog feed request, "+
79                     request.getRequestURL());
80         }
81         
82         
83         /*
84          * parse the path info.
85          *
86          * must look like this ...
87          *
88          * /<type>/<format>
89          */

90         if(pathInfo != null && pathInfo.trim().length() > 1) {
91             
92             String JavaDoc[] pathElements = pathInfo.split("/");
93             if(pathElements.length == 2) {
94                 this.type = pathElements[0];
95                 this.format = pathElements[1];
96             } else {
97                 throw new InvalidRequestException("invalid feed path info, "+
98                         request.getRequestURL());
99             }
100             
101         } else {
102             throw new InvalidRequestException("invalid feed path info, "+
103                     request.getRequestURL());
104         }
105         
106         
107         /*
108          * parse request parameters
109          *
110          * the only params we currently care about are:
111          * cat - specifies a weblog category
112          * excerpts - specifies the feed should only include excerpts
113          *
114          */

115         if(request.getParameter("cat") != null) {
116             this.weblogCategoryName =
117                     URLUtilities.decode(request.getParameter("cat"));
118             
119             // all categories must start with a /
120
if(!this.weblogCategoryName.startsWith("/")) {
121                 this.weblogCategoryName = "/"+this.weblogCategoryName;
122             }
123         }
124         
125         if(request.getParameter("excerpts") != null) {
126             this.excerpts = Boolean.valueOf(request.getParameter("excerpts")).booleanValue();
127         }
128         
129         if(log.isDebugEnabled()) {
130             log.debug("type = "+this.type);
131             log.debug("format = "+this.format);
132             log.debug("weblogCategory = "+this.weblogCategoryName);
133             log.debug("excerpts = "+this.excerpts);
134         }
135     }
136
137     public String JavaDoc getType() {
138         return type;
139     }
140
141     public void setType(String JavaDoc type) {
142         this.type = type;
143     }
144
145     public String JavaDoc getFormat() {
146         return format;
147     }
148
149     public void setFormat(String JavaDoc format) {
150         this.format = format;
151     }
152
153     public String JavaDoc getWeblogCategoryName() {
154         return weblogCategoryName;
155     }
156
157     public void setWeblogCategoryName(String JavaDoc weblogCategory) {
158         this.weblogCategoryName = weblogCategory;
159     }
160
161     public boolean isExcerpts() {
162         return excerpts;
163     }
164
165     public void setExcerpts(boolean excerpts) {
166         this.excerpts = excerpts;
167     }
168
169     public WeblogCategoryData getWeblogCategory() {
170         
171         if(weblogCategory == null && weblogCategoryName != null) {
172             try {
173                 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
174                 weblogCategory = wmgr.getWeblogCategoryByPath(getWeblog(), weblogCategoryName);
175             } catch (RollerException ex) {
176                 log.error("Error getting weblog category "+weblogCategoryName, ex);
177             }
178         }
179         
180         return weblogCategory;
181     }
182
183     public void setWeblogCategory(WeblogCategoryData weblogCategory) {
184         this.weblogCategory = weblogCategory;
185     }
186     
187 }
188
Popular Tags