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.util;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: /**
026: * Represents a request for a Planet Roller url.
027: *
028: * currently ... /planet.do and /planetrss
029: */
030: public class PlanetRequest extends ParsedRequest {
031:
032: private static Log log = LogFactory.getLog(PlanetRequest.class);
033:
034: private String context = null;
035: private String type = null;
036: private String flavor = null;
037: private boolean excerpts = false;
038: private String language = null;
039:
040: /**
041: * Construct the PlanetRequest by parsing the incoming url
042: */
043: public PlanetRequest(HttpServletRequest request)
044: throws InvalidRequestException {
045:
046: super (request);
047:
048: // parse the request object and figure out what we've got
049: log.debug("parsing url " + request.getRequestURL());
050:
051: String servlet = request.getServletPath();
052:
053: // what servlet is our destination?
054: if (servlet != null) {
055: // strip off the leading slash
056: servlet = servlet.substring(1);
057:
058: if (servlet.equals("planet.do")) {
059: this .context = "planet";
060: this .type = "page";
061: } else if (servlet.equals("planetrss")) {
062: this .context = "planet";
063: this .type = "feed";
064: this .flavor = "rss";
065: } else {
066: // not a request to a feed servlet
067: throw new InvalidRequestException(
068: "not a planet request, "
069: + request.getRequestURL());
070: }
071:
072: } else {
073: throw new InvalidRequestException("not a planet request, "
074: + request.getRequestURL());
075: }
076:
077: /*
078: * parse request parameters
079: *
080: * the only params we currently care about are:
081: * excerpts - specifies the feed should only include excerpts
082: *
083: */
084: if (request.getParameter("excerpts") != null) {
085: this .excerpts = Boolean.valueOf(
086: request.getParameter("excerpts")).booleanValue();
087: }
088:
089: // language is always from the browser
090: language = request.getLocale().getLanguage();
091: }
092:
093: public String getContext() {
094: return context;
095: }
096:
097: public String getType() {
098: return type;
099: }
100:
101: public String getFlavor() {
102: return flavor;
103: }
104:
105: public boolean isExcerpts() {
106: return excerpts;
107: }
108:
109: public String getLanguage() {
110: return language;
111: }
112:
113: public void setLanguage(String language) {
114: this.language = language;
115: }
116:
117: }
|