File Source: PingTargetEditBase.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.ui.struts2.common.PingTargetEditBase__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.common;
    20  
    21  import org.apache.commons.lang.StringUtils;
    22  import org.apache.commons.logging.Log;
    23  import org.apache.roller.weblogger.WebloggerException;
    24  import org.apache.roller.weblogger.business.WebloggerFactory;
    25  import org.apache.roller.weblogger.business.pings.PingTargetManager;
    26  import org.apache.roller.weblogger.pojos.PingTarget;
    27  import org.apache.roller.weblogger.ui.struts2.util.UIAction;
    28  
    29  
    30  /**
    31   * Base implementation for action that can edit an existing ping target.
    32   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.struts2.common.PingTargetEditBase()
          * 
          *  Postconditions:
          *    this.bean == &new PingTargetFormBean(PingTargetEditBase#1)
          *    this.pingTarget == null
          *    this.bean.id == null
          *    this.bean.name == null
          *    this.bean.pingUrl == null
          *    new PingTargetFormBean(PingTargetEditBase#1) num objects == 1
          */
    33  public abstract class PingTargetEditBase extends UIAction {
    34      
    35      // ping target we are working on, if any
    36      private PingTarget pingTarget = null;
    37      
    38      // a bean for managing submitted data
    39      private PingTargetFormBean bean = new PingTargetFormBean();
    40      
    41      
    42      // get logger
    43      protected abstract Log getLogger();
    44      
    45      
    46      /**
    47       * Prepare action by loading ping target to work on.
    48       */
    49      public void myPrepare() {
    50          
                 /* 
    P/P           *  Method: void myPrepare()
                  * 
                  *  Preconditions:
                  *    this.bean != null
                  *    init'ed(this.bean.id)
                  *    (soft) init'ed(this.pingTarget)
                  *    (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetEdit.log != null
                  *    (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargetEdit.log != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@51 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@51 != null
                  * 
                  *  Postconditions:
                  *    init'ed(this.pingTarget)
                  * 
                  *  Test Vectors:
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@52: {1}, {0}
                  */
    51          PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
    52          if(!StringUtils.isEmpty(getBean().getId())) {
    53              
    54              try {
    55                  setPingTarget(pingTargetMgr.getPingTarget(getBean().getId()));
    56              } catch (WebloggerException ex) {
    57                  getLogger().error("Error looking up ping target - "+getBean().getId());
    58              }
    59              
    60              if(getPingTarget() == null) {
    61                  // TODO: i18n
    62                  addError("No such ping target id: " + getBean().getId());
    63              }
    64              
    65          } else {
    66              // TODO: i18n
    67              addError("Missing ping target id: " + getBean().getId());
    68          }
    69      }
    70      
    71      
    72      public String execute() {
    73          
                 /* 
    P/P           *  Method: String execute()
                  * 
                  *  Preconditions:
                  *    (soft) this.bean != null
                  *    (soft) this.pingTarget != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&"error",&"input"}
                  *    possibly_updated(this.bean.id)
                  *    possibly_updated(this.bean.name)
                  *    possibly_updated(this.bean.pingUrl)
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.ui.struts2.common.PingTargetEditBase:hasActionErrors(...)@74: {1}, {0}
                  */
    74          if(!hasActionErrors()) {
    75              // load bean with data from ping target
    76              getBean().copyFrom(getPingTarget());
    77          } else {
    78              // if we already have an error then that means we couldn't load
    79              // an existing ping target to work on, so return ERROR result
    80              return ERROR;
    81          }
    82          
    83          return INPUT;
    84      }
    85      
    86      
    87      /**
    88       * Save ping target.
    89       */
    90      public String save() {
    91          
                 /* 
    P/P           *  Method: String save()
                  * 
                  *  Preconditions:
                  *    (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetEdit.log != null
                  *    (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargetEdit.log != null
                  *    (soft) this.bean != null
                  *    (soft) init'ed(this.bean.name)
                  *    (soft) init'ed(this.bean.pingUrl)
                  *    (soft) this.pingTarget != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@107 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@107 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@109 != null
                  * 
                  *  Postconditions:
                  *    return_value == &"input"
                  * 
                  *  Test Vectors:
                  *    org.apache.roller.weblogger.ui.struts2.common.PingTargetEditBase:hasActionErrors(...)@105: {1}, {0}
                  *    org.apache.roller.weblogger.ui.struts2.common.PingTargetEditBase:hasActionErrors(...)@92: {0}, {1}
                  */
    92          if(hasActionErrors()) {
    93              // if we already have an error then that means we couldn't load
    94              // an existing ping target to work on, so return ERROR result
    95              return INPUT;
    96          }
    97          
    98          // copy data from form into ping target
    99          getBean().copyTo(getPingTarget());
   100          
   101          // Call private helper to validate ping target
   102          // If there are errors, go back to the target edit page.
   103          myValidate(getPingTarget());
   104          
   105          if(!hasActionErrors()) try {
   106              // Appears to be ok.  Save it and flush.
   107              PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
   108              pingTargetMgr.savePingTarget(getPingTarget());
   109              WebloggerFactory.getWeblogger().flush();
   110              
   111              addMessage("pingTarget.saved");
   112              
   113          } catch (WebloggerException ex) {
   114              getLogger().error("Error saving ping target", ex);
   115              // TODO: i18n
   116              addError("Error saving ping target.");
   117          }
   118          
   119          return INPUT;
   120      }
   121      
   122      
   123      /**
   124       * Private helper to validate a ping target.
   125       */
   126      protected void myValidate(PingTarget pingTarget) {
   127          
   128          try {
                     /* 
    P/P               *  Method: void myValidate(PingTarget)
                      * 
                      *  Preconditions:
                      *    (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetEdit.log != null
                      *    (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargetEdit.log != null
                      * 
                      *  Presumptions:
                      *    org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@129 != null
                      *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@129 != null
                      * 
                      *  Test Vectors:
                      *    org.apache.roller.weblogger.business.pings.PingTargetManager:isHostnameKnown(...)@136: {1}, {0}
                      *    org.apache.roller.weblogger.business.pings.PingTargetManager:isNameUnique(...)@130: {1}, {0}
                      *    org.apache.roller.weblogger.business.pings.PingTargetManager:isUrlWellFormed(...)@134: {1}, {0}
                      */
   129              PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
   130              if (!pingTargetMgr.isNameUnique(pingTarget)) {
   131                  addError("pingTarget.nameNotUnique");
   132              }
   133              
   134              if (!pingTargetMgr.isUrlWellFormed(pingTarget)) {
   135                  addError("pingTarget.malformedUrl");
   136              } else if (!pingTargetMgr.isHostnameKnown(pingTarget)) {
   137                  addError("pingTarget.unknownHost");
   138              }
   139          } catch (WebloggerException ex) {
   140              getLogger().error("Error validating ping target", ex);
   141              // TODO: i18n
   142              addError("Error doing ping target validation");
   143          }
   144      }
   145      
   146      
   147      public PingTarget getPingTarget() {
                 /* 
    P/P           *  Method: PingTarget getPingTarget()
                  * 
                  *  Preconditions:
                  *    init'ed(this.pingTarget)
                  * 
                  *  Postconditions:
                  *    return_value == this.pingTarget
                  *    init'ed(return_value)
                  */
   148          return pingTarget;
   149      }
   150  
   151      public void setPingTarget(PingTarget pingTarget) {
                 /* 
    P/P           *  Method: void setPingTarget(PingTarget)
                  * 
                  *  Postconditions:
                  *    this.pingTarget == pingTarget
                  *    init'ed(this.pingTarget)
                  */
   152          this.pingTarget = pingTarget;
   153      }
   154      
   155      public PingTargetFormBean getBean() {
                 /* 
    P/P           *  Method: PingTargetFormBean getBean()
                  * 
                  *  Preconditions:
                  *    init'ed(this.bean)
                  * 
                  *  Postconditions:
                  *    return_value == this.bean
                  *    init'ed(return_value)
                  */
   156          return bean;
   157      }
   158  
   159      public void setBean(PingTargetFormBean bean) {
                 /* 
    P/P           *  Method: void setBean(PingTargetFormBean)
                  * 
                  *  Postconditions:
                  *    this.bean == bean
                  *    init'ed(this.bean)
                  */
   160          this.bean = bean;
   161      }
   162      
   163  }








SofCheck Inspector Build Version : 2.18479
PingTargetEditBase.java 2009-Jan-02 14:25:18
PingTargetEditBase.class 2009-Sep-04 03:12:45