File Source: UIAction.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.ui.struts2.util.UIAction__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.struts2.util;
    20  
    21  import com.opensymphony.xwork2.ActionSupport;
    22  import java.text.DateFormat;
    23  import java.text.SimpleDateFormat;
    24  import java.util.ArrayList;
    25  import java.util.List;
    26  import org.apache.roller.weblogger.config.WebloggerConfig;
    27  import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
    28  import org.apache.roller.weblogger.pojos.User;
    29  import org.apache.roller.weblogger.pojos.Weblog;
    30  import org.apache.roller.weblogger.ui.struts2.util.UIUtils;
    31  import org.apache.roller.weblogger.ui.core.util.menu.Menu;
    32  import org.apache.roller.weblogger.ui.core.util.menu.MenuHelper;
    33  
    34  
    35  /**
    36   * Extends the Struts2 ActionSupport class to add in support for handling an
    37   * error and status success.  Other actions extending this one only need to
    38   * calle setError() and setSuccess() accordingly.
    39   * 
    40   * NOTE: as a small convenience, all errors and messages are assumed to be keys
    41   * which point to a success in a resource bundle, so we automatically call
    42   * getText(key) on the param passed into setError() and setSuccess().
    43   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.struts2.util.UIAction()
          * 
          *  Postconditions:
          *    this.actionName == null
          *    this.actionWeblog == null
          *    this.authenticatedUser == null
          *    this.desiredMenu == null
          *    this.pageTitle == null
          *    this.weblog == null
          */
    44  public abstract class UIAction extends ActionSupport 
    45          implements UIActionPreparable, UISecurityEnforced {
    46      
    47      // a result that sends the user to an access denied warning
    48      public static final String DENIED = "access-denied";
    49      
    50      // a common result name used to indicate the result should list some data
    51      public static final String LIST = "list";
    52      
    53      // the authenticated user accessing this action, or null if client is not logged in
    54      private User authenticatedUser = null;
    55      
    56      // the weblog this action is intended to work on, or null if no weblog specified
    57      private Weblog actionWeblog = null;
    58      
    59      // the weblog handle of the action weblog
    60      private String weblog = null;
    61      
    62      // action name (used by tabbed menu utility)
    63      protected String actionName = null;
    64      
    65      // the name of the menu this action wants to show, or null for no menu
    66      protected String desiredMenu = null;
    67      
    68      // page title
    69      protected String pageTitle = null;
    70      
    71      
    72      public void myPrepare() {
    73          // no-op
             /* 
    P/P       *  Method: void myPrepare()
              */
    74      }
    75      
    76      
    77      // default action permissions, user is required
    78      public boolean isUserRequired() {
                 /* 
    P/P           *  Method: bool isUserRequired()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
    79          return true;
    80      }
    81      
    82      // default action permissions, weblog is required
    83      public boolean isWeblogRequired() {
                 /* 
    P/P           *  Method: bool isWeblogRequired()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
    84          return true;
    85      }
    86      
    87      // default action permissions, "editor" role required
    88      public String requiredUserRole() {
                 /* 
    P/P           *  Method: String requiredUserRole()
                  * 
                  *  Postconditions:
                  *    return_value == &"editor"
                  */
    89          return "editor";
    90      }
    91      
    92      // default action permissions, no perms required
    93      public short requiredWeblogPermissions() {
                 /* 
    P/P           *  Method: short requiredWeblogPermissions()
                  * 
                  *  Postconditions:
                  *    return_value == -1
                  */
    94          return -1;
    95      }
    96      
    97      // convenient way to tell if user being dealt with is an admin
    98      public boolean isUserIsAdmin() {
                 /* 
    P/P           *  Method: bool isUserIsAdmin()
                  * 
                  *  Preconditions:
                  *    this.authenticatedUser != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    99          return getAuthenticatedUser().hasRole("admin");
   100      }
   101      
   102      
   103      public String getSiteURL() {
                 /* 
    P/P           *  Method: String getSiteURL()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   104          return WebloggerRuntimeConfig.getRelativeContextURL();
   105      }
   106      
   107      public String getAbsoluteSiteURL() {
                 /* 
    P/P           *  Method: String getAbsoluteSiteURL()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   108          return WebloggerRuntimeConfig.getAbsoluteContextURL();
   109      }
   110      
   111      public String getProp(String key) {
   112          // first try static config
                 /* 
    P/P           *  Method: String getProp(String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.config.WebloggerConfig:getProperty(...)@113: Inverse{null}, Addr_Set{null}
                  */
   113          String value = WebloggerConfig.getProperty(key);
   114          if(value == null) {
   115              value = WebloggerRuntimeConfig.getProperty(key);
   116          }
   117          
   118          return (value == null) ? key : value;
   119      }
   120      
   121      public boolean getBooleanProp(String key) {
   122          // first try static config
                 /* 
    P/P           *  Method: bool getBooleanProp(String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.config.WebloggerConfig:getProperty(...)@123: Inverse{null}, Addr_Set{null}
                  */
   123          String value = WebloggerConfig.getProperty(key);
   124          if(value == null) {
   125              value = WebloggerRuntimeConfig.getProperty(key);
   126          }
   127          
   128          return (value == null) ? false : (new Boolean(value)).booleanValue();
   129      }
   130      
   131      public int getIntProp(String key) {
   132          // first try static config
                 /* 
    P/P           *  Method: int getIntProp(String)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.config.WebloggerConfig:getProperty(...)@133: Inverse{null}, Addr_Set{null}
                  */
   133          String value = WebloggerConfig.getProperty(key);
   134          if(value == null) {
   135              value = WebloggerRuntimeConfig.getProperty(key);
   136          }
   137          
   138          return (value == null) ? 0 : (new Integer(value)).intValue();
   139      }
   140      
   141      
   142      public void addError(String errorKey) {
                 /* 
    P/P           *  Method: void addError(String)
                  */
   143          addActionError(getText(errorKey));
   144      }
   145      
   146      public void addError(String errorKey, String param) {
                 /* 
    P/P           *  Method: void addError(String, String)
                  */
   147          addActionError(getText(errorKey, errorKey, param));
   148      }
   149      
   150      public void addError(String errorKey, List args) {
                 /* 
    P/P           *  Method: void addError(String, List)
                  */
   151          addActionError(getText(errorKey, args));
   152      }
   153      
   154      /**
   155       * This simply returns the result of hasActionErrors() but we need it
   156       * because without it you can't easily check if there were errors since
   157       * you can't call a hasXXX() method via OGNL.
   158       */
   159      public boolean errorsExist() {
                 /* 
    P/P           *  Method: bool errorsExist()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   160          return hasActionErrors();
   161      }
   162      
   163      
   164      public void addMessage(String msgKey) {
                 /* 
    P/P           *  Method: void addMessage(String)
                  */
   165          addActionMessage(getText(msgKey));
   166      }
   167      
   168      public void addMessage(String msgKey, String param) {
                 /* 
    P/P           *  Method: void addMessage(String, String)
                  */
   169          addActionMessage(getText(msgKey, msgKey, param));
   170      }
   171      
   172      public void addMessage(String msgKey, List args) {
                 /* 
    P/P           *  Method: void addMessage(String, List)
                  */
   173          addActionMessage(getText(msgKey, args));
   174      }
   175      
   176      /**
   177       * This simply returns the result of hasActionMessages() but we need it
   178       * because without it you can't easily check if there were messages since
   179       * you can't call a hasXXX() method via OGNL.
   180       */
   181      public boolean messagesExist() {
                 /* 
    P/P           *  Method: bool messagesExist()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   182          return hasActionMessages();
   183      }
   184      
   185  
   186      public User getAuthenticatedUser() {
                 /* 
    P/P           *  Method: User getAuthenticatedUser()
                  * 
                  *  Preconditions:
                  *    init'ed(this.authenticatedUser)
                  * 
                  *  Postconditions:
                  *    return_value == this.authenticatedUser
                  *    init'ed(return_value)
                  */
   187          return authenticatedUser;
   188      }
   189  
   190      public void setAuthenticatedUser(User authenticatedUser) {
                 /* 
    P/P           *  Method: void setAuthenticatedUser(User)
                  * 
                  *  Postconditions:
                  *    this.authenticatedUser == authenticatedUser
                  *    init'ed(this.authenticatedUser)
                  */
   191          this.authenticatedUser = authenticatedUser;
   192      }
   193  
   194      public Weblog getActionWeblog() {
                 /* 
    P/P           *  Method: Weblog getActionWeblog()
                  * 
                  *  Preconditions:
                  *    init'ed(this.actionWeblog)
                  * 
                  *  Postconditions:
                  *    return_value == this.actionWeblog
                  *    init'ed(return_value)
                  */
   195          return actionWeblog;
   196      }
   197  
   198      public void setActionWeblog(Weblog workingWeblog) {
                 /* 
    P/P           *  Method: void setActionWeblog(Weblog)
                  * 
                  *  Postconditions:
                  *    this.actionWeblog == workingWeblog
                  *    init'ed(this.actionWeblog)
                  */
   199          this.actionWeblog = workingWeblog;
   200      }
   201  
   202      public String getWeblog() {
                 /* 
    P/P           *  Method: String getWeblog()
                  * 
                  *  Preconditions:
                  *    init'ed(this.weblog)
                  * 
                  *  Postconditions:
                  *    return_value == this.weblog
                  *    init'ed(return_value)
                  */
   203          return weblog;
   204      }
   205  
   206      public void setWeblog(String weblog) {
                 /* 
    P/P           *  Method: void setWeblog(String)
                  * 
                  *  Postconditions:
                  *    this.weblog == weblog
                  *    init'ed(this.weblog)
                  */
   207          this.weblog = weblog;
   208      }
   209      
   210      public String getPageTitle() {
                 /* 
    P/P           *  Method: String getPageTitle()
                  * 
                  *  Preconditions:
                  *    init'ed(this.pageTitle)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   211          return getText(pageTitle);
   212      }
   213  
   214      public void setPageTitle(String pageTitle) {
                 /* 
    P/P           *  Method: void setPageTitle(String)
                  * 
                  *  Postconditions:
                  *    this.pageTitle == pageTitle
                  *    init'ed(this.pageTitle)
                  */
   215          this.pageTitle = pageTitle;
   216      }
   217      
   218      
   219      public String getActionName() {
                 /* 
    P/P           *  Method: String getActionName()
                  * 
                  *  Preconditions:
                  *    init'ed(this.actionName)
                  * 
                  *  Postconditions:
                  *    return_value == this.actionName
                  *    init'ed(return_value)
                  */
   220          return this.actionName;
   221      }
   222      
   223      public void setActionName(String actionName) {
                 /* 
    P/P           *  Method: void setActionName(String)
                  * 
                  *  Postconditions:
                  *    this.actionName == actionName
                  *    init'ed(this.actionName)
                  */
   224          this.actionName = actionName;
   225      }
   226  
   227      public String getDesiredMenu() {
                 /* 
    P/P           *  Method: String getDesiredMenu()
                  * 
                  *  Preconditions:
                  *    init'ed(this.desiredMenu)
                  * 
                  *  Postconditions:
                  *    return_value == this.desiredMenu
                  *    init'ed(return_value)
                  */
   228          return desiredMenu;
   229      }
   230  
   231      public void setDesiredMenu(String desiredMenu) {
                 /* 
    P/P           *  Method: void setDesiredMenu(String)
                  * 
                  *  Postconditions:
                  *    this.desiredMenu == desiredMenu
                  *    init'ed(this.desiredMenu)
                  */
   232          this.desiredMenu = desiredMenu;
   233      }
   234      
   235      public Menu getMenu() {
                 /* 
    P/P           *  Method: Menu getMenu()
                  * 
                  *  Preconditions:
                  *    init'ed(this.actionName)
                  *    init'ed(this.actionWeblog)
                  *    init'ed(this.authenticatedUser)
                  *    init'ed(this.desiredMenu)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   236          return MenuHelper.getMenu(getDesiredMenu(), getActionName(), getAuthenticatedUser(), getActionWeblog());
   237      }
   238      
   239      
   240      public String getShortDateFormat() {
                 /* 
    P/P           *  Method: String getShortDateFormat()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   241          DateFormat sdf = DateFormat.getDateInstance(
   242                  DateFormat.SHORT, getLocale());
   243          if (sdf instanceof SimpleDateFormat) {
   244              return ((SimpleDateFormat)sdf).toPattern();
   245          }
   246          return "yyyy/MM/dd";
   247      }
   248      
   249      public String getMediumDateFormat() {
                 /* 
    P/P           *  Method: String getMediumDateFormat()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   250          DateFormat sdf = DateFormat.getDateInstance(
   251                  DateFormat.MEDIUM, getLocale());
   252          if (sdf instanceof SimpleDateFormat) {
   253              return ((SimpleDateFormat)sdf).toPattern();
   254          }
   255          return "MMM dd, yyyy";
   256      }
   257      
   258      public List getLocalesList() {
                 /* 
    P/P           *  Method: List getLocalesList()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   259          return UIUtils.getLocales();
   260      }
   261      
   262      public List getTimeZonesList() {
                 /* 
    P/P           *  Method: List getTimeZonesList()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   263          return UIUtils.getTimeZones();
   264      }
   265      
   266      public List getHoursList() {
                 /* 
    P/P           *  Method: List getHoursList()
                  * 
                  *  Postconditions:
                  *    return_value == &new ArrayList(getHoursList#1)
                  *    new ArrayList(getHoursList#1) num objects == 1
                  */
   267          List ret = new ArrayList();
   268          for (int i=0; i<24; i++) {
   269              ret.add(i);
   270          }
   271          return ret;
   272      }
   273      
   274      public List getMinutesList() {
                 /* 
    P/P           *  Method: List getMinutesList()
                  * 
                  *  Postconditions:
                  *    return_value == &new ArrayList(getMinutesList#1)
                  *    new ArrayList(getMinutesList#1) num objects == 1
                  */
   275          List ret = new ArrayList();
   276          for (int i=0; i<60; i++) {
   277              ret.add(i);
   278          }
   279          return ret;
   280      }
   281      
   282      public List getSecondsList() {
                 /* 
    P/P           *  Method: List getSecondsList()
                  * 
                  *  Postconditions:
                  *    return_value == &new ArrayList(getMinutesList#1)
                  *    new ArrayList(getMinutesList#1) num objects == 1
                  */
   283          return getMinutesList();
   284      }
   285      
   286      public List getCommentDaysList() {
   287          
                 /* 
    P/P           *  Method: List getCommentDaysList()
                  * 
                  *  Postconditions:
                  *    return_value == &new ArrayList(getCommentDaysList#1)
                  *    new ArrayList(getCommentDaysList#1) num objects == 1
                  */
   288          List opts = new ArrayList();
   289          
   290          opts.add(new KeyValueObject(new Integer(0), getText("weblogEdit.unlimitedCommentDays")));
   291          opts.add(new KeyValueObject(new Integer(1), getText("weblogEdit.days1")));
   292          opts.add(new KeyValueObject(new Integer(2), getText("weblogEdit.days2")));
   293          opts.add(new KeyValueObject(new Integer(3), getText("weblogEdit.days3")));
   294          opts.add(new KeyValueObject(new Integer(4), getText("weblogEdit.days4")));
   295          opts.add(new KeyValueObject(new Integer(5), getText("weblogEdit.days5")));
   296          opts.add(new KeyValueObject(new Integer(7), getText("weblogEdit.days7")));
   297          opts.add(new KeyValueObject(new Integer(10), getText("weblogEdit.days10")));
   298          opts.add(new KeyValueObject(new Integer(20), getText("weblogEdit.days20")));
   299          opts.add(new KeyValueObject(new Integer(30), getText("weblogEdit.days30")));
   300          opts.add(new KeyValueObject(new Integer(60), getText("weblogEdit.days60")));
   301          opts.add(new KeyValueObject(new Integer(90), getText("weblogEdit.days90")));
   302          
   303          return opts;
   304      }
   305      
   306  }








SofCheck Inspector Build Version : 2.18479
UIAction.java 2009-Jan-02 14:24:56
UIAction.class 2009-Sep-04 03:12:43