File Source: PreviewURLModel.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.ui.rendering.model.PreviewURLModel__static_init
          */
     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.model;
    20  
    21  import java.util.Map;
    22  import org.apache.roller.weblogger.WebloggerException;
    23  import org.apache.roller.weblogger.business.URLStrategy;
    24  import org.apache.roller.weblogger.business.WebloggerFactory;
    25  import org.apache.roller.weblogger.pojos.Weblog;
    26  import org.apache.roller.weblogger.ui.rendering.util.WeblogPreviewRequest;
    27  import org.apache.roller.weblogger.ui.rendering.util.WeblogRequest;
    28  
    29  /**
    30   * Special subclass of URLModel which can change some of the urls which are
    31   * generated to make them work for previewing mode.
    32   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.rendering.model.PreviewURLModel()
          * 
          *  Postconditions:
          *    this.locale == null
          *    this.previewRequest == null
          *    this.urlStrategy == null
          *    this.weblog == null
          */
    33  public class PreviewURLModel extends URLModel {
    34      
    35      private WeblogPreviewRequest previewRequest = null;
    36      private Weblog weblog = null;
    37      private String locale = null;
    38      
    39      private URLStrategy urlStrategy = null;
    40      
    41      
    42      public void init(Map initData) throws WebloggerException {
    43          
    44          // need a weblog request so that we can know the weblog and locale
                 /* 
    P/P           *  Method: void init(Map)
                  * 
                  *  Preconditions:
                  *    initData != null
                  * 
                  *  Presumptions:
                  *    java.util.Map:get(...)@45 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@65 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPreviewRequest:instanceof(...)@52 == 1
                  * 
                  *  Postconditions:
                  *    init'ed(this.locale)
                  *    (soft) this.previewRequest != null
                  *    init'ed(this.urlStrategy)
                  *    init'ed(this.weblog)
                  * 
                  *  Test Vectors:
                  *    java.util.Map:get(...)@63: Inverse{null}, Addr_Set{null}
                  */
    45          WeblogRequest weblogRequest = (WeblogRequest) initData.get("parsedRequest");
    46          if(weblogRequest == null) {
    47              throw new WebloggerException("Expected 'weblogRequest' init param!");
    48          }
    49          
    50          // PreviewURLModel only works on preview requests, so cast weblogRequest
    51          // into a WeblogPreviewRequest and if it fails then throw exception
    52          if(weblogRequest instanceof WeblogPreviewRequest) {
    53              this.previewRequest = (WeblogPreviewRequest) weblogRequest;
    54          } else {
    55              throw new WebloggerException("weblogRequest is not a WeblogPreviewRequest."+
    56                      "  PreviewURLModel only supports preview requests.");
    57          }
    58          
    59          this.weblog = weblogRequest.getWeblog();
    60          this.locale = weblogRequest.getLocale();
    61          
    62          // look for url strategy
    63          urlStrategy = (URLStrategy) initData.get("urlStrategy");
    64          if(urlStrategy == null) {
    65              urlStrategy = WebloggerFactory.getWeblogger().getUrlStrategy();
    66          }
    67          
    68          super.init(initData);
    69      }
    70      
    71      
    72      /**
    73       * We need resource urls to point to our custom PreviewResourceServlet
    74       * because when previewing a theme the ResourceServlet has no way of
    75       * knowing what theme you are previewing and thus couldn't find the
    76       * resources for that theme.
    77       */
    78      public String resource(String filePath) {
                 /* 
    P/P           *  Method: String resource(String)
                  * 
                  *  Preconditions:
                  *    this.urlStrategy != null
                  *    init'ed(this.weblog)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    79          return urlStrategy.getWeblogResourceURL(weblog, filePath, true);
    80      }
    81      
    82  }








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