File Source: OldFeedRequest.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.velocity.deprecated;
    20  
    21  import java.util.HashSet;
    22  import java.util.Set;
    23  import javax.servlet.http.HttpServletRequest;
    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.weblogger.WebloggerException;
    28  import org.apache.roller.weblogger.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      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.velocity.deprecated.OldFeedRequest__static_init
              * 
              *  Postconditions:
              *    feedServlets == &new HashSet(OldFeedRequest__static_init#1)
              *    init'ed(mLogger)
              *    new HashSet(OldFeedRequest__static_init#1) num objects == 1
              */
    42      private static Log mLogger = LogFactory.getLog(OldFeedRequest.class);
    43      
    44      private static Set feedServlets = new HashSet();
    45      
    46      private String context = null;
    47      private String flavor = null;
    48      private String weblogHandle = null;
    49      private String 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       */
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.ui.rendering.velocity.deprecated.OldFeedRequest(HttpServletRequest)
              * 
              *  Preconditions:
              *    feedServlets != null
              *    mLogger != null
              *    request != null
              * 
              *  Presumptions:
              *    java.lang.Boolean:valueOf(...)@132 != null
              *    java.util.Set:contains(...)@77 == 1
              *    javax.servlet.http.HttpServletRequest:getParameter(...)@120 != null
              *    javax.servlet.http.HttpServletRequest:getServletPath(...)@69 != null
              * 
              *  Postconditions:
              *    java.lang.String:substring(...)._tainted == 0
              *    this.context in Addr_Set{&"weblog",&"main"}
              *    init'ed(this.excerpts)
              *    this.flavor != null
              *    init'ed(this.weblogCategory)
              *    this.weblogHandle == null
              * 
              *  Test Vectors:
              *    java.lang.String:equals(...)@138: {0}, {1}
              *    java.lang.String:length(...)@89: {0,1}, {2..232-1}
              *    java.lang.String:length(...)@94: {0}, {1..232-1}
              *    javax.servlet.http.HttpServletRequest:getParameter(...)@119: Addr_Set{null}, Inverse{null}
              *    javax.servlet.http.HttpServletRequest:getParameter(...)@123: Addr_Set{null}, Inverse{null}
              *    javax.servlet.http.HttpServletRequest:getParameter(...)@127: Addr_Set{null}, Inverse{null}
              *    javax.servlet.http.HttpServletRequest:getParameter(...)@131: Addr_Set{null}, Inverse{null}
              *    javax.servlet.http.HttpServletRequest:getPathInfo(...)@70: Addr_Set{null}, Inverse{null}
              */
    64      public OldFeedRequest(HttpServletRequest request) throws Exception {
    65          
    66          // parse the request object and figure out what we've got
    67          mLogger.debug("parsing url "+request.getRequestURL());
    68          
    69          String servlet = request.getServletPath();
    70          String 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("not a weblog feed request, "+request.getRequestURL());
    83              }
    84          } else {
    85              throw new Exception("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[] 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 getContext() {
                 /* 
    P/P           *  Method: String getContext()
                  * 
                  *  Preconditions:
                  *    init'ed(this.context)
                  * 
                  *  Postconditions:
                  *    return_value == this.context
                  *    init'ed(return_value)
                  */
   146          return context;
   147      }
   148  
   149      public String getFlavor() {
                 /* 
    P/P           *  Method: String getFlavor()
                  * 
                  *  Preconditions:
                  *    init'ed(this.flavor)
                  * 
                  *  Postconditions:
                  *    return_value == this.flavor
                  *    init'ed(return_value)
                  */
   150          return flavor;
   151      }
   152  
   153      public String getWeblogHandle() {
                 /* 
    P/P           *  Method: String getWeblogHandle()
                  * 
                  *  Preconditions:
                  *    init'ed(this.weblogHandle)
                  * 
                  *  Postconditions:
                  *    return_value == this.weblogHandle
                  *    init'ed(return_value)
                  */
   154          return weblogHandle;
   155      }
   156  
   157      public String getWeblogCategory() {
                 /* 
    P/P           *  Method: String getWeblogCategory()
                  * 
                  *  Preconditions:
                  *    init'ed(this.weblogCategory)
                  * 
                  *  Postconditions:
                  *    return_value == this.weblogCategory
                  *    init'ed(return_value)
                  */
   158          return weblogCategory;
   159      }
   160  
   161      public boolean isExcerpts() {
                 /* 
    P/P           *  Method: bool isExcerpts()
                  * 
                  *  Preconditions:
                  *    init'ed(this.excerpts)
                  * 
                  *  Postconditions:
                  *    return_value == this.excerpts
                  *    init'ed(return_value)
                  */
   162          return excerpts;
   163      }
   164  
   165  }








SofCheck Inspector Build Version : 2.18479
OldFeedRequest.java 2009-Jan-02 14:25:22
OldFeedRequest.class 2009-Sep-04 03:12:45