File Source: WeblogPreviewRequest.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.WebloggerException;
    25  import org.apache.roller.weblogger.business.themes.ThemeNotFoundException;
    26  import org.apache.roller.weblogger.business.WebloggerFactory;
    27  import org.apache.roller.weblogger.business.themes.ThemeManager;
    28  import org.apache.roller.weblogger.business.WeblogManager;
    29  import org.apache.roller.weblogger.pojos.Theme;
    30  import org.apache.roller.weblogger.pojos.WeblogEntry;
    31  import org.apache.roller.weblogger.util.URLUtilities;
    32  
    33  
    34  /**
    35   * Represents a request for a weblog preview.
    36   */
    37  public class WeblogPreviewRequest extends WeblogPageRequest {
    38      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.util.WeblogPreviewRequest__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    39      private static Log log = LogFactory.getLog(WeblogPreviewRequest.class);
    40      
    41      private static final String PREVIEW_SERVLET = "/roller-ui/authoring/preview";
    42      
    43      // lightweight attributes
    44      private String themeName = null;
    45      private String previewEntry = null;
    46      
    47      // heavyweight attributes
    48      private Theme theme = null;
    49      private WeblogEntry weblogEntry = null;
    50      
    51      public WeblogPreviewRequest(HttpServletRequest request) 
    52              throws InvalidRequestException {
    53          
    54          // let parent go first
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.ui.rendering.util.WeblogPreviewRequest(HttpServletRequest)
                  * 
                  *  Preconditions:
                  *    log != null
                  *    org/apache/roller/weblogger/ui/rendering/util/WeblogPageRequest.log != null
                  *    org/apache/roller/weblogger/ui/rendering/util/WeblogRequest.log != null
                  *    request != null
                  * 
                  *  Postconditions:
                  *    java.lang.String:substring(...)._tainted == 0
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    init'ed(this.authenticUser)
                  *    possibly_updated(this.context)
                  *    this.customParams == &new HashMap(WeblogPageRequest#17)
                  *    init'ed(this.locale)
                  *    init'ed(this.localeInstance)
                  *    init'ed(this.pageNum)
                  *    init'ed(this.pathInfo)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    javax.servlet.http.HttpServletRequest:getParameter(...)@58: Addr_Set{null}, Inverse{null}
                  *    javax.servlet.http.HttpServletRequest:getParameter(...)@63: Addr_Set{null}, Inverse{null}
                  *    org.apache.commons.logging.Log:isDebugEnabled(...)@67: {0}, {1}
                  */
    55          super(request);
    56          
    57          // we may have a specific theme to preview
    58          if(request.getParameter("theme") != null) {
    59              this.themeName = request.getParameter("theme");
    60          }
    61          
    62          // we may also have a specific entry to preview
    63          if(request.getParameter("previewEntry") != null) {
    64              this.previewEntry = URLUtilities.decode(request.getParameter("previewEntry"));
    65          }
    66          
    67          if(log.isDebugEnabled()) {
    68              log.debug("theme = "+this.themeName);
    69          }
    70      }
    71      
    72      
    73      boolean isValidDestination(String servlet) {
                 /* 
    P/P           *  Method: bool isValidDestination(String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    74          return (servlet != null && PREVIEW_SERVLET.equals(servlet));
    75      }
    76      
    77      
    78      public String getThemeName() {
                 /* 
    P/P           *  Method: String getThemeName()
                  * 
                  *  Preconditions:
                  *    init'ed(this.themeName)
                  * 
                  *  Postconditions:
                  *    return_value == this.themeName
                  *    init'ed(return_value)
                  */
    79          return themeName;
    80      }
    81  
    82      public void setThemeName(String theme) {
                 /* 
    P/P           *  Method: void setThemeName(String)
                  * 
                  *  Postconditions:
                  *    this.themeName == theme
                  *    init'ed(this.themeName)
                  */
    83          this.themeName = theme;
    84      }
    85      
    86      // override so that previews never show login status
    87      public String getAuthenticUser() {
                 /* 
    P/P           *  Method: String getAuthenticUser()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
    88          return null;
    89      }
    90      
    91      // override so that previews never show login status
    92      public boolean isLoggedIn() {
                 /* 
    P/P           *  Method: bool isLoggedIn()
                  * 
                  *  Postconditions:
                  *    return_value == 0
                  */
    93          return false;
    94      }
    95  
    96      public Theme getTheme() {
    97          
                 /* 
    P/P           *  Method: Theme getTheme()
                  * 
                  *  Preconditions:
                  *    init'ed(this.theme)
                  *    (soft) log != null
                  *    (soft) init'ed(this.themeName)
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getThemeManager(...)@100 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@100 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  *    this.theme == return_value
                  * 
                  *  Test Vectors:
                  *    this.theme: Inverse{null}, Addr_Set{null}
                  *    this.themeName: Addr_Set{null}, Inverse{null}
                  */
    98          if(theme == null && themeName != null) {
    99              try {
   100                  ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
   101                  theme = themeMgr.getTheme(themeName);
   102              } catch(ThemeNotFoundException tnfe) {
   103                  // bogus theme specified ... don't worry about it
   104              } catch(WebloggerException re) {
   105                  log.error("Error looking up theme "+themeName, re);
   106              }
   107          }
   108          
   109          return theme;
   110      }
   111  
   112      public void setTheme(Theme theme) {
                 /* 
    P/P           *  Method: void setTheme(Theme)
                  * 
                  *  Postconditions:
                  *    this.theme == theme
                  *    init'ed(this.theme)
                  */
   113          this.theme = theme;
   114      }
   115  
   116      public String getPreviewEntry() {
                 /* 
    P/P           *  Method: String getPreviewEntry()
                  * 
                  *  Preconditions:
                  *    init'ed(this.previewEntry)
                  * 
                  *  Postconditions:
                  *    return_value == this.previewEntry
                  *    init'ed(return_value)
                  */
   117          return previewEntry;
   118      }
   119  
   120      public void setPreviewEntry(String previewEntry) {
                 /* 
    P/P           *  Method: void setPreviewEntry(String)
                  * 
                  *  Postconditions:
                  *    this.previewEntry == previewEntry
                  *    init'ed(this.previewEntry)
                  */
   121          this.previewEntry = previewEntry;
   122      }
   123      
   124      // if we have a preview entry we would prefer to return that
   125      public WeblogEntry getWeblogEntry() {
   126          
                 /* 
    P/P           *  Method: WeblogEntry getWeblogEntry()
                  * 
                  *  Preconditions:
                  *    init'ed(this.weblogEntry)
                  *    (soft) log != null
                  *    (soft) init'ed(this.weblog)
                  *    (soft) org/apache/roller/weblogger/ui/rendering/util/WeblogRequest.log != null
                  *    (soft) init'ed(this.previewEntry)
                  *    (soft) init'ed(this.weblogAnchor)
                  *    (soft) init'ed(this.weblogHandle)
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@136 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@136 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  *    this.weblogEntry == return_value
                  *    init'ed(this.weblog)
                  * 
                  *  Test Vectors:
                  *    this.weblogEntry: Inverse{null}, Addr_Set{null}
                  *    this.previewEntry: Inverse{null}, Addr_Set{null}
                  *    this.weblogAnchor: Addr_Set{null}, Inverse{null}
                  */
   127          if(weblogEntry == null && 
   128                  (previewEntry != null || super.getWeblogAnchor() != null)) {
   129              
   130              String anchor = previewEntry;
   131              if(previewEntry == null) {
   132                  anchor = super.getWeblogAnchor();
   133              }
   134              
   135              try {
   136                  WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
   137                  weblogEntry = wmgr.getWeblogEntryByAnchor(getWeblog(), anchor);
   138              } catch (WebloggerException ex) {
   139                  log.error("Error getting weblog entry "+anchor, ex);
   140              }
   141          }
   142          
   143          return weblogEntry;
   144      }
   145      
   146      public void setWeblogEntry(WeblogEntry weblogEntry) {
                 /* 
    P/P           *  Method: void setWeblogEntry(WeblogEntry)
                  * 
                  *  Postconditions:
                  *    this.weblogEntry == weblogEntry
                  *    init'ed(this.weblogEntry)
                  */
   147          this.weblogEntry = weblogEntry;
   148      }
   149      
   150  }








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