File Source: MenuModel.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.model;
    20  
    21  import java.util.Map;
    22  import org.apache.commons.logging.Log;
    23  import org.apache.commons.logging.LogFactory;
    24  import org.apache.roller.weblogger.WebloggerException;
    25  import org.apache.roller.weblogger.ui.core.util.menu.Menu;
    26  import org.apache.roller.weblogger.ui.core.util.menu.MenuHelper;
    27  import org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest;
    28  import org.apache.roller.weblogger.ui.rendering.util.WeblogRequest;
    29  
    30  
    31  /**
    32   * Model which provides methods for displaying editor menu/navigation-bar.
    33   * 
    34   * Implemented by calling hybrid JSP tag.
    35   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.rendering.model.MenuModel()
          * 
          *  Postconditions:
          *    this.pageRequest == null
          */
    36  public class MenuModel implements Model {
    37      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.model.MenuModel__static_init
              * 
              *  Postconditions:
              *    init'ed(logger)
              */
    38      private static Log logger = LogFactory.getLog(MenuModel.class);
    39      
    40      private WeblogPageRequest pageRequest = null;
    41      
    42      
    43      /** Template context name to be used for model */
    44      public String getModelName() {
                 /* 
    P/P           *  Method: String getModelName()
                  * 
                  *  Postconditions:
                  *    return_value == &"menuModel"
                  */
    45          return "menuModel";
    46      }
    47      
    48      
    49      /** Init page model based on request */
    50      public void init(Map initData) throws WebloggerException {
    51          
    52          // we expect the init data to contain a weblogRequest object
                 /* 
    P/P           *  Method: void init(Map)
                  * 
                  *  Preconditions:
                  *    initData != null
                  * 
                  *  Presumptions:
                  *    java.util.Map:get(...)@53 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:instanceof(...)@60 == 1
                  * 
                  *  Postconditions:
                  *    (soft) this.pageRequest != null
                  */
    53          WeblogRequest weblogRequest = (WeblogRequest) initData.get("parsedRequest");
    54          if(weblogRequest == null) {
    55              throw new WebloggerException("expected weblogRequest from init data");
    56          }
    57          
    58          // MenuModel only works on page requests, so cast weblogRequest
    59          // into a WeblogPageRequest and if it fails then throw exception
    60          if(weblogRequest instanceof WeblogPageRequest) {
    61              this.pageRequest = (WeblogPageRequest) weblogRequest;
    62          } else {
    63              throw new WebloggerException("weblogRequest is not a WeblogPageRequest."+
    64                      "  MenuModel only supports page requests.");
    65          }
    66      }
    67      
    68      
    69      /**
    70       * Get a Menu representing the admin UI action menu, if the user is 
    71       * currently logged in and is an admin.
    72       */
    73      public Menu getAdminMenu() {
                 /* 
    P/P           *  Method: Menu getAdminMenu()
                  * 
                  *  Preconditions:
                  *    this.pageRequest != null
                  *    (soft) org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.log != null
                  *    (soft) org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.menus != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:getUser(...)@74 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:getUser(...)@75 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:getWeblog(...)@75 != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{null,&new Menu(buildMenu#2)}
                  *    new ArrayList(Menu#1) num objects <= 1
                  *    new Menu(buildMenu#2) num objects <= 1
                  *    new Menu(buildMenu#2).tabs == &new ArrayList(Menu#1)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.pojos.User:hasRole(...)@74: {0}, {1}
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:isLoggedIn(...)@74: {0}, {1}
                  */
    74          if(pageRequest.isLoggedIn() && pageRequest.getUser().hasRole("admin")) {
    75              return MenuHelper.getMenu("admin", "noAction", pageRequest.getUser(), pageRequest.getWeblog());
    76          }
    77          return null;
    78      }
    79      
    80      
    81      /**
    82       * Get a Menu representing the author UI action menu, if the use is
    83       * currently logged in.
    84       */
    85      public Menu getAuthorMenu() {
                 /* 
    P/P           *  Method: Menu getAuthorMenu()
                  * 
                  *  Preconditions:
                  *    this.pageRequest != null
                  *    (soft) org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.log != null
                  *    (soft) org/apache/roller/weblogger/ui/core/util/menu/MenuHelper.menus != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:getUser(...)@87 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:getWeblog(...)@87 != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{null,&new Menu(buildMenu#2)}
                  *    new ArrayList(Menu#1) num objects <= 1
                  *    new Menu(buildMenu#2) num objects <= 1
                  *    new Menu(buildMenu#2).tabs == &new ArrayList(Menu#1)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:isLoggedIn(...)@86: {0}, {1}
                  */
    86          if(pageRequest.isLoggedIn()) {
    87              return MenuHelper.getMenu("editor", "noAction", pageRequest.getUser(), pageRequest.getWeblog());
    88          }
    89          return null;
    90      }
    91      
    92  }








SofCheck Inspector Build Version : 2.18479
MenuModel.java 2009-Jan-02 14:25:12
MenuModel.class 2009-Sep-04 03:12:44