File Source: PlanetRequest.java

     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.weblogger.ui.rendering.util;
    20  
    21  import javax.servlet.http.HttpServletRequest;
    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      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.util.PlanetRequest__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    33      private static Log log = LogFactory.getLog(PlanetRequest.class);
    34      
    35      private String context = null;
    36      private String type = null;
    37      private String flavor = null;
    38      private boolean excerpts = false;
    39      private String language = null;
    40      private String group = null;
    41      
    42      
    43      /**
    44       * Construct the PlanetRequest by parsing the incoming url
    45       */
    46      public PlanetRequest(HttpServletRequest request) throws InvalidRequestException {
    47          
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.ui.rendering.util.PlanetRequest(HttpServletRequest)
                  * 
                  *  Preconditions:
                  *    log != null
                  *    request != null
                  * 
                  *  Presumptions:
                  *    java.lang.Boolean:valueOf(...)@85 != null
                  *    java.lang.String:equals(...)@63 == 1
                  *    javax.servlet.http.HttpServletRequest:getLocale(...)@94 != null
                  *    javax.servlet.http.HttpServletRequest:getServletPath(...)@53 != null
                  * 
                  *  Postconditions:
                  *    init'ed(this.authenticUser)
                  *    this.context == &"planet"
                  *    init'ed(this.excerpts)
                  *    this.flavor in Addr_Set{null,&"rss"}
                  *    init'ed(this.group)
                  *    init'ed(this.language)
                  *    this.request == request
                  *    this.request != null
                  *    this.type in Addr_Set{&"feed",&"page"}
                  *    this.user == null
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@60: {0}, {1}
                  *    javax.servlet.http.HttpServletRequest:getParameter(...)@84: Addr_Set{null}, Inverse{null}
                  *    javax.servlet.http.HttpServletRequest:getParameter(...)@88: Addr_Set{null}, Inverse{null}
                  */
    48          super(request);
    49          
    50          // parse the request object and figure out what we've got
    51          log.debug("parsing url "+request.getRequestURL());
    52          
    53          String servlet = request.getServletPath();
    54          
    55          // what servlet is our destination?
    56          if(servlet != null) {
    57              // strip off the leading slash
    58              servlet = servlet.substring(1);
    59              
    60              if(servlet.equals("planet.do")) {
    61                  this.context = "planet";
    62                  this.type = "page";
    63              } else if(servlet.equals("planetrss")) {
    64                  this.context = "planet";
    65                  this.type = "feed";
    66                  this.flavor = "rss";
    67              } else {
    68                  // not a request to a feed servlet
    69                  throw new InvalidRequestException("not a planet request, "+request.getRequestURL());
    70              }
    71              
    72          } else {
    73              throw new InvalidRequestException("not a planet request, "+request.getRequestURL());
    74          }
    75          
    76          
    77          /*
    78           * parse request parameters
    79           *
    80           * the only params we currently care about are:
    81           *   excerpts - specifies the feed should only include excerpts
    82           *   group - specifies the aggregation group to include
    83           */
    84          if (request.getParameter("excerpts") != null) {
    85              this.excerpts = Boolean.valueOf(request.getParameter("excerpts")).booleanValue();
    86          }
    87          
    88          if (request.getParameter("group") != null) {
    89              this.group = request.getParameter("group");
    90          }
    91          
    92          
    93          // language is always from the browser
    94          language = request.getLocale().getLanguage();
    95      }
    96      
    97      
    98      public String getContext() {
                 /* 
    P/P           *  Method: String getContext()
                  * 
                  *  Preconditions:
                  *    init'ed(this.context)
                  * 
                  *  Postconditions:
                  *    return_value == this.context
                  *    init'ed(return_value)
                  */
    99          return context;
   100      }
   101      
   102      public String getType() {
                 /* 
    P/P           *  Method: String getType()
                  * 
                  *  Preconditions:
                  *    init'ed(this.type)
                  * 
                  *  Postconditions:
                  *    return_value == this.type
                  *    init'ed(return_value)
                  */
   103          return type;
   104      }
   105      
   106      public String getFlavor() {
                 /* 
    P/P           *  Method: String getFlavor()
                  * 
                  *  Preconditions:
                  *    init'ed(this.flavor)
                  * 
                  *  Postconditions:
                  *    return_value == this.flavor
                  *    init'ed(return_value)
                  */
   107          return flavor;
   108      }
   109      
   110      public boolean isExcerpts() {
                 /* 
    P/P           *  Method: bool isExcerpts()
                  * 
                  *  Preconditions:
                  *    init'ed(this.excerpts)
                  * 
                  *  Postconditions:
                  *    return_value == this.excerpts
                  *    init'ed(return_value)
                  */
   111          return excerpts;
   112      }
   113  
   114      public String getLanguage() {
                 /* 
    P/P           *  Method: String getLanguage()
                  * 
                  *  Preconditions:
                  *    init'ed(this.language)
                  * 
                  *  Postconditions:
                  *    return_value == this.language
                  *    init'ed(return_value)
                  */
   115          return language;
   116      }
   117  
   118      public void setLanguage(String language) {
                 /* 
    P/P           *  Method: void setLanguage(String)
                  * 
                  *  Postconditions:
                  *    this.language == language
                  *    init'ed(this.language)
                  */
   119          this.language = language;
   120      }
   121      
   122      public String getGroup() {
                 /* 
    P/P           *  Method: String getGroup()
                  * 
                  *  Preconditions:
                  *    init'ed(this.group)
                  * 
                  *  Postconditions:
                  *    return_value == this.group
                  *    init'ed(return_value)
                  */
   123          return group;
   124      }    
   125  }








SofCheck Inspector Build Version : 2.18479
PlanetRequest.java 2009-Jan-02 14:24:48
PlanetRequest.class 2009-Sep-04 03:12:45