KickJava   Java API By Example, From Geeks To Geeks.

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


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
25
26 /**
27  * Represents a request for a Planet Roller url.
28  *
29  * currently ... /planet.do and /planetrss
30  */

31 public class PlanetRequest extends ParsedRequest {
32     
33     private static Log log = LogFactory.getLog(PlanetRequest.class);
34     
35     private String JavaDoc context = null;
36     private String JavaDoc type = null;
37     private String JavaDoc flavor = null;
38     private boolean excerpts = false;
39     private String JavaDoc language = null;
40     
41     
42     /**
43      * Construct the PlanetRequest by parsing the incoming url
44      */

45     public PlanetRequest(HttpServletRequest JavaDoc request) throws InvalidRequestException {
46         
47         super(request);
48         
49         // parse the request object and figure out what we've got
50
log.debug("parsing url "+request.getRequestURL());
51         
52         String JavaDoc servlet = request.getServletPath();
53         
54         // what servlet is our destination?
55
if(servlet != null) {
56             // strip off the leading slash
57
servlet = servlet.substring(1);
58             
59             if(servlet.equals("planet.do")) {
60                 this.context = "planet";
61                 this.type = "page";
62             } else if(servlet.equals("planetrss")) {
63                 this.context = "planet";
64                 this.type = "feed";
65                 this.flavor = "rss";
66             } else {
67                 // not a request to a feed servlet
68
throw new InvalidRequestException("not a planet request, "+request.getRequestURL());
69             }
70             
71         } else {
72             throw new InvalidRequestException("not a planet request, "+request.getRequestURL());
73         }
74         
75         
76         /*
77          * parse request parameters
78          *
79          * the only params we currently care about are:
80          * excerpts - specifies the feed should only include excerpts
81          *
82          */

83         if(request.getParameter("excerpts") != null) {
84             this.excerpts = Boolean.valueOf(request.getParameter("excerpts")).booleanValue();
85         }
86         
87         
88         // language is always from the browser
89
language = request.getLocale().getLanguage();
90     }
91     
92     
93     public String JavaDoc getContext() {
94         return context;
95     }
96     
97     public String JavaDoc getType() {
98         return type;
99     }
100     
101     public String JavaDoc getFlavor() {
102         return flavor;
103     }
104     
105     public boolean isExcerpts() {
106         return excerpts;
107     }
108
109     public String JavaDoc getLanguage() {
110         return language;
111     }
112
113     public void setLanguage(String JavaDoc language) {
114         this.language = language;
115     }
116     
117 }
118
Popular Tags