File Source: TemplateRemove.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.struts2.editor;
    20  
    21  import org.apache.commons.logging.Log;
    22  import org.apache.commons.logging.LogFactory;
    23  import org.apache.roller.weblogger.WebloggerException;
    24  import org.apache.roller.weblogger.business.WebloggerFactory;
    25  import org.apache.roller.weblogger.business.UserManager;
    26  import org.apache.roller.weblogger.pojos.WeblogPermission;
    27  import org.apache.roller.weblogger.pojos.WeblogTemplate;
    28  import org.apache.roller.weblogger.ui.struts2.util.UIAction;
    29  import org.apache.roller.weblogger.util.cache.CacheManager;
    30  
    31  
    32  /**
    33   * Remove a template.
    34   */
    35  public class TemplateRemove extends UIAction {
    36      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.struts2.editor.TemplateRemove__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    37      private static Log log = LogFactory.getLog(TemplateRemove.class);
    38      
    39      // id of template to remove
    40      private String removeId = null;
    41      
    42      // template object that we will remove
    43      private WeblogTemplate template = null;
    44      
    45      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.ui.struts2.editor.TemplateRemove()
              * 
              *  Postconditions:
              *    this.actionName == &"templateRemove"
              *    this.actionWeblog == null
              *    this.authenticatedUser == null
              *    this.removeId == null
              *    this.template == null
              *    this.weblog == null
              *    this.desiredMenu == &"editor"
              *    this.pageTitle == &"editPages.title.removeOK"
              */
    46      public TemplateRemove() {
    47          this.actionName = "templateRemove";
    48          this.desiredMenu = "editor";
    49          this.pageTitle = "editPages.title.removeOK";
    50      }
    51      
    52      
    53      // must be a weblog admin to use this action
    54      public short requiredWeblogPermissions() {
                 /* 
    P/P           *  Method: short requiredWeblogPermissions()
                  * 
                  *  Presumptions:
                  *    init'ed(org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN)
                  * 
                  *  Postconditions:
                  *    return_value == org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN
                  *    (soft) init'ed(return_value)
                  */
    55          return WeblogPermission.ADMIN;
    56      }
    57      
    58      
    59      public void myPrepare() {
                 /* 
    P/P           *  Method: void myPrepare()
                  * 
                  *  Preconditions:
                  *    init'ed(this.removeId)
                  *    (soft) log != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@61 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@61 != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.template)
                  * 
                  *  Test Vectors:
                  *    this.removeId: Addr_Set{null}, Inverse{null}
                  */
    60          if(getRemoveId() != null) try {
    61              UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
    62              setTemplate(umgr.getPage(getRemoveId()));
    63          } catch (WebloggerException ex) {
    64              log.error("Error looking up template by id - "+getRemoveId(), ex);
    65              // TODO: i18n
    66              addError("Could not find template to remove - "+getRemoveId());
    67          }
    68      }
    69      
    70      
    71      /**
    72       * Display the remove template confirmation.
    73       */
    74      public String execute() {
                 /* 
    P/P           *  Method: String execute()
                  * 
                  *  Postconditions:
                  *    return_value == &"confirm"
                  */
    75          return "confirm";
    76      }
    77      
    78      
    79      /**
    80       * Remove a new template.
    81       */
    82      public String remove() {
    83          
                 /* 
    P/P           *  Method: String remove()
                  * 
                  *  Preconditions:
                  *    init'ed(this.template)
                  *    (soft) log != null
                  *    (soft) init'ed(this.removeId)
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@86 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@86 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@92 != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&"success",&"confirm"}
                  * 
                  *  Test Vectors:
                  *    this.template: Addr_Set{null}, Inverse{null}
                  *    org.apache.roller.weblogger.pojos.WeblogTemplate:isRequired(...)@85: {1}, {0}
                  */
    84          if(getTemplate() != null) try {
    85              if(!getTemplate().isRequired()) {
    86                  UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
    87  
    88                  // notify cache
    89                  CacheManager.invalidate(getTemplate());
    90  
    91                  umgr.removePage(getTemplate());
    92                  WebloggerFactory.getWeblogger().flush();
    93                                  
    94                  return SUCCESS;
    95              } else {
    96                  // TODO: i18n
    97                  addError("Cannot remove required template");
    98              }
    99              
   100          } catch(Exception ex) {
   101              log.error("Error removing page - "+getRemoveId(), ex);
   102              // TODO: i18n
   103              addError("Error removing page");
   104          }
   105          
   106          return "confirm";
   107      }
   108  
   109      
   110      public String getRemoveId() {
                 /* 
    P/P           *  Method: String getRemoveId()
                  * 
                  *  Preconditions:
                  *    init'ed(this.removeId)
                  * 
                  *  Postconditions:
                  *    return_value == this.removeId
                  *    init'ed(return_value)
                  */
   111          return removeId;
   112      }
   113  
   114      public void setRemoveId(String removeId) {
                 /* 
    P/P           *  Method: void setRemoveId(String)
                  * 
                  *  Postconditions:
                  *    this.removeId == removeId
                  *    init'ed(this.removeId)
                  */
   115          this.removeId = removeId;
   116      }
   117  
   118      public WeblogTemplate getTemplate() {
                 /* 
    P/P           *  Method: WeblogTemplate getTemplate()
                  * 
                  *  Preconditions:
                  *    init'ed(this.template)
                  * 
                  *  Postconditions:
                  *    return_value == this.template
                  *    init'ed(return_value)
                  */
   119          return template;
   120      }
   121  
   122      public void setTemplate(WeblogTemplate template) {
                 /* 
    P/P           *  Method: void setTemplate(WeblogTemplate)
                  * 
                  *  Postconditions:
                  *    this.template == template
                  *    init'ed(this.template)
                  */
   123          this.template = template;
   124      }
   125      
   126  }








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