File Source: WeblogResourceRequest.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  import org.apache.roller.weblogger.util.URLUtilities;
    25  
    26  
    27  /**
    28   * Represents a request for a weblog resource file.
    29   *
    30   * /roller-ui/rendering/resources/*
    31   */
    32  public class WeblogResourceRequest extends WeblogRequest {
    33      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.util.WeblogResourceRequest__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    34      private static Log log = LogFactory.getLog(WeblogResourceRequest.class);
    35          
    36      // lightweight attributes
    37      private String resourcePath = null;
    38      
    39      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.ui.rendering.util.WeblogResourceRequest()
              * 
              *  Postconditions:
              *    this.authenticUser == null
              *    this.locale == null
              *    this.localeInstance == null
              *    this.pathInfo == null
              *    this.request == null
              *    this.resourcePath == null
              *    this.user == null
              *    this.weblog == null
              *    this.weblogHandle == null
              */
    40      public WeblogResourceRequest() {}
    41      
    42      
    43      /**
    44       * Construct the WeblogResourceRequest by parsing the incoming url
    45       */
    46      public WeblogResourceRequest(HttpServletRequest request) 
    47              throws InvalidRequestException {
    48          
    49          // let our parent take care of their business first
    50          // parent determines weblog handle and locale if specified
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.ui.rendering.util.WeblogResourceRequest(HttpServletRequest)
                  * 
                  *  Preconditions:
                  *    log != null
                  *    org/apache/roller/weblogger/ui/rendering/util/WeblogRequest.log != null
                  *    request != null
                  * 
                  *  Presumptions:
                  *    java.lang.String:length(...)@67 >= 2
                  * 
                  *  Postconditions:
                  *    java.lang.String:substring(...)._tainted == 0
                  *    init'ed(this.authenticUser)
                  *    init'ed(this.locale)
                  *    this.localeInstance == null
                  *    this.user == null
                  *    this.weblog == null
                  *    this.pathInfo != null
                  *    this.request == request
                  *    this.request != null
                  *    init'ed(this.resourcePath)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    java.lang.String:startsWith(...)@70: {0}, {1}
                  *    org.apache.commons.logging.Log:isDebugEnabled(...)@88: {0}, {1}
                  */
    51          super(request);
    52          
    53          String servlet = request.getServletPath();
    54          
    55          // we only want the path info left over from after our parents parsing
    56          String pathInfo = this.getPathInfo();
    57          
    58          // parse the request object and figure out what we've got
    59          log.debug("parsing path "+pathInfo);
    60                  
    61          
    62          /* 
    63           * any path is okay ...
    64           *
    65           * /<path>/<to>/<resource>
    66           */
    67          if(pathInfo != null && pathInfo.trim().length() > 1) {
    68              
    69              this.resourcePath = pathInfo;
    70              if(pathInfo.startsWith("/")) {
    71                  this.resourcePath = pathInfo.substring(1);
    72              }
    73              
    74              // Fix for ROL-1065: even though a + should mean space in a URL, folks
    75              // who upload files with plus signs expect them to work without
    76              // escaping. This is essentially what other systems do (e.g. JIRA) to
    77              // enable this.
    78              this.resourcePath = this.resourcePath.replaceAll("\\+", "%2B");
    79              
    80              // now we really decode the URL
    81              this.resourcePath = URLUtilities.decode(this.resourcePath);
    82          
    83          } else {
+   84              throw new InvalidRequestException("invalid resource path info, "+
    85                      request.getRequestURL());
    86          }
    87          
    88          if(log.isDebugEnabled()) {
    89              log.debug("resourcePath = "+this.resourcePath);
    90          }
    91      }
    92      
    93      public String getResourcePath() {
                 /* 
    P/P           *  Method: String getResourcePath()
                  * 
                  *  Preconditions:
                  *    init'ed(this.resourcePath)
                  * 
                  *  Postconditions:
                  *    return_value == this.resourcePath
                  *    init'ed(return_value)
                  */
    94          return resourcePath;
    95      }
    96  
    97      public void setResourcePath(String resourcePath) {
                 /* 
    P/P           *  Method: void setResourcePath(String)
                  * 
                  *  Postconditions:
                  *    this.resourcePath == resourcePath
                  *    init'ed(this.resourcePath)
                  */
    98          this.resourcePath = resourcePath;
    99      }
   100              
   101      protected boolean isLocale(String potentialLocale) {
   102          // We don't support locales in the resource Servlet so we've got to 
   103          // keep parent from treating upload sub-directory name as a locale.
                 /* 
    P/P           *  Method: bool isLocale(String)
                  * 
                  *  Postconditions:
                  *    return_value == 0
                  */
   104          return false;
   105      }
   106  }








SofCheck Inspector Build Version : 2.18479
WeblogResourceRequest.java 2009-Jan-02 14:24:50
WeblogResourceRequest.class 2009-Sep-04 03:12:46