File Source: CalendarModel.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 javax.servlet.jsp.PageContext;
    23  import org.apache.commons.logging.Log;
    24  import org.apache.commons.logging.LogFactory;
    25  import org.apache.roller.weblogger.WebloggerException;
    26  import org.apache.roller.weblogger.pojos.wrapper.WeblogWrapper;
    27  import org.apache.roller.weblogger.ui.core.tags.calendar.BigWeblogCalendarModel;
    28  import org.apache.roller.weblogger.ui.core.tags.calendar.CalendarTag;
    29  import org.apache.roller.weblogger.ui.core.tags.calendar.WeblogCalendarModel;
    30  import org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest;
    31  import org.apache.roller.weblogger.ui.rendering.util.WeblogRequest;
    32  
    33  
    34  /**
    35   * Model which provides functionality for displaying weblog calendar.
    36   * 
    37   * Implemented by calling hybrid JSP tag.
    38   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.rendering.model.CalendarModel()
          * 
          *  Postconditions:
          *    this.pageContext == null
          *    this.pageRequest == null
          */
    39  public class CalendarModel implements Model {
    40      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.model.CalendarModel__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    41      private static Log log = LogFactory.getLog(CalendarModel.class);
    42      
    43      private PageContext pageContext = null;
    44      private WeblogPageRequest pageRequest = null;
    45      
    46      
    47      /** Template context name to be used for model */
    48      public String getModelName() {
                 /* 
    P/P           *  Method: String getModelName()
                  * 
                  *  Postconditions:
                  *    return_value == &"calendarModel"
                  */
    49          return "calendarModel";
    50      }
    51      
    52      
    53      /** Init page model based on request */
    54      public void init(Map initData) throws WebloggerException {
    55          
    56          // extract page context
                 /* 
    P/P           *  Method: void init(Map)
                  * 
                  *  Preconditions:
                  *    initData != null
                  * 
                  *  Presumptions:
                  *    java.util.Map:get(...)@60 != null
                  *    org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest:instanceof(...)@67 == 1
                  * 
                  *  Postconditions:
                  *    init'ed(this.pageContext)
                  *    (soft) this.pageRequest != null
                  */
    57          this.pageContext = (PageContext) initData.get("pageContext");
    58          
    59          // we expect the init data to contain a weblogRequest object
    60          WeblogRequest weblogRequest = (WeblogRequest) initData.get("parsedRequest");
    61          if(weblogRequest == null) {
    62              throw new WebloggerException("expected weblogRequest from init data");
    63          }
    64          
    65          // CalendarModel only works on page requests, so cast weblogRequest
    66          // into a WeblogPageRequest and if it fails then throw exception
    67          if(weblogRequest instanceof WeblogPageRequest) {
    68              this.pageRequest = (WeblogPageRequest) weblogRequest;
    69          } else {
    70              throw new WebloggerException("weblogRequest is not a WeblogPageRequest."+
    71                      "  CalendarModel only supports page requests.");
    72          }
    73      }
    74      
    75      
    76      public String showWeblogEntryCalendar(WeblogWrapper websiteWrapper, String catArgument) {        
                 /* 
    P/P           *  Method: String showWeblogEntryCalendar(WeblogWrapper, String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    77          return showWeblogEntryCalendar(websiteWrapper, catArgument, false);
    78      }
    79      
    80      
    81      public String showWeblogEntryCalendarBig(WeblogWrapper websiteWrapper, String catArgument) { 
                 /* 
    P/P           *  Method: String showWeblogEntryCalendarBig(WeblogWrapper, String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    82          return showWeblogEntryCalendar(websiteWrapper, catArgument, true);
    83      }
    84      
    85      
    86      private String showWeblogEntryCalendar(WeblogWrapper websiteWrapper, String catArgument, boolean big) {
    87          
                 /* 
    P/P           *  Method: String showWeblogEntryCalendar(WeblogWrapper, String, bool)
                  * 
                  *  Preconditions:
                  *    (soft) log != null
                  *    (soft) org/apache/roller/weblogger/ui/core/tags/calendar/CalendarTag.mLogger != null
                  *    (soft) org/apache/roller/weblogger/ui/core/tags/calendar/WeblogCalendarModel.log != null
                  *    (soft) this.pageContext != null
                  *    (soft) this.pageRequest != null
                  * 
                  *  Presumptions:
                  *    calTag.pageContext@102 != null
                  * 
                  *  Postconditions:
                  *    java.io.StringWriter:toString(...)._tainted == 0
                  *    return_value == One-of{&java.io.StringWriter:toString(...), &"Exception in tag", null}
                  *    return_value in Addr_Set{null,&java.io.StringWriter:toString(...),&"Exception in tag"}
                  * 
                  *  Test Vectors:
                  *    big: {0}, {1}
                  *    java.lang.String:equals(...)@88: {0}, {1}
                  */
    88          if ("nil".equals(catArgument)) catArgument = null;        
    89          String ret = null;
    90          try {
    91              org.apache.roller.weblogger.ui.core.tags.calendar.CalendarModel model = null;
    92              if (big) {
    93                  model = new BigWeblogCalendarModel(pageRequest, catArgument);
    94              } else {
    95                  model = new WeblogCalendarModel(pageRequest, catArgument);
    96              }
    97              
    98              // save model in JSP page context so CalendarTag can find it
    99              pageContext.setAttribute("calendarModel", model);
   100              
   101              CalendarTag calTag = new CalendarTag();
   102              calTag.setPageContext(pageContext);
   103              calTag.setName("calendar");
   104              calTag.setModel("calendarModel");
   105              calTag.setLocale(pageRequest.getLocaleInstance());
   106              if (big) {
   107                  calTag.setClassSuffix("Big");
   108              }
   109              ret = calTag.emit();
   110          } catch (Exception e) {
   111              log.error("ERROR: initializing calendar tag",e);
   112          }
   113          return ret;
   114      }
   115      
   116  }








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