File Source: MessageModel.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.ui.rendering.model.MessageModel__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.List;
    22  import java.util.Map;
    23  import org.apache.roller.weblogger.WebloggerException;
    24  import org.apache.roller.weblogger.ui.rendering.util.WeblogRequest;
    25  import org.apache.roller.weblogger.util.I18nMessages;
    26  
    27  
    28  /**
    29   * Provides access to application resources required for I18N.
    30   * Uses model name 'text' because that's what the Velocity Tools did.
    31   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.rendering.model.MessageModel()
          * 
          *  Postconditions:
          *    this.messages == null
          */
    32  public class MessageModel implements Model {  
    33      
    34      I18nMessages messages = null;
    35      
    36      
    37      /** Template context name to be used for model */
    38      public String getModelName() {
                 /* 
    P/P           *  Method: String getModelName()
                  * 
                  *  Postconditions:
                  *    return_value == &"text"
                  */
    39          return "text";
    40      }
    41      
    42      
    43      /** Init page model based on request */
    44      public void init(Map initData) throws WebloggerException {
    45          
    46          // we expect the init data to contain a weblogRequest object
                 /* 
    P/P           *  Method: void init(Map)
                  * 
                  *  Preconditions:
                  *    initData != null
                  *    org/apache/roller/weblogger/util/I18nMessages.messagesMap != null
                  * 
                  *  Presumptions:
                  *    java.util.Map:get(...)@47 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogRequest:getLocaleInstance(...)@53 != null
                  * 
                  *  Postconditions:
                  *    this.messages != null
                  *    new I18nMessages(getMessages#2) num objects <= 1
                  *    init'ed(new I18nMessages(getMessages#2).bundle)
                  *    new I18nMessages(getMessages#2).locale != null
                  */
    47          WeblogRequest weblogRequest = (WeblogRequest) initData.get("parsedRequest");
    48          if(weblogRequest == null) {
    49              throw new WebloggerException("expected weblogRequest from init data");
    50          }
    51          
    52          // get messages util based on desired locale
    53          this.messages = I18nMessages.getMessages(weblogRequest.getLocaleInstance());
    54      }
    55      
    56      
    57      /** Return message string */
    58      public String get(String key) {
                 /* 
    P/P           *  Method: String get(String)
                  * 
                  *  Preconditions:
                  *    this.messages != null
                  *    (soft) this.messages.bundle != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    59          return messages.getString(key);
    60      }
    61      
    62      
    63      /** Return parameterized message string */
    64      public String get(String key, List args) {
                 /* 
    P/P           *  Method: String get(String, List)
                  * 
                  *  Preconditions:
                  *    this.messages != null
                  *    (soft) args != null
                  *    (soft) this.messages.bundle != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    65          return messages.getString(key, args);
    66      }
    67  
    68  }








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