File Source: CommonPingTargets.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.admin;
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.pings.PingTargetManager;
26 import org.apache.roller.weblogger.ui.struts2.common.PingTargetsBase;
27
28
29 /**
30 * Admin action for managing global ping targets.
31 */
32 public class CommonPingTargets extends PingTargetsBase {
33
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.admin.CommonPingTargets__static_init
*
* Postconditions:
* init'ed(log)
*/
34 private static Log log = LogFactory.getLog(CommonPingTargets.class);
35
36
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.admin.CommonPingTargets()
*
* Presumptions:
* init'ed(org/apache/roller/weblogger/ui/struts2/common/PingTargetsBase.java.util.Collections.EMPTY_LIST)
*
* Postconditions:
* this.actionName == &"commonPingTargets"
* this.desiredMenu == &"admin"
* this.pageTitle == &"commonPingTargets.commonPingTargets"
* this.pingTarget == null
* this.pingTargetId == null
* this.pingTargets == org/apache/roller/weblogger/ui/struts2/common/PingTargetsBase.java.util.Collections.EMPTY_LIST
* init'ed(this.pingTargets)
*/
37 public CommonPingTargets() {
38 this.actionName = "commonPingTargets";
39 this.desiredMenu = "admin";
40 this.pageTitle = "commonPingTargets.commonPingTargets";
41 }
42
43
44 public String requiredUserRole() {
/*
P/P * Method: String requiredUserRole()
*
* Postconditions:
* return_value == &"admin"
*/
45 return "admin";
46 }
47
48 // no weblog required
49 public boolean isWeblogRequired() {
/*
P/P * Method: bool isWeblogRequired()
*
* Postconditions:
* return_value == 0
*/
50 return false;
51 }
52
53
54 protected Log getLogger() {
/*
P/P * Method: Log getLogger()
*
* Preconditions:
* init'ed(log)
*
* Postconditions:
* return_value == log
* init'ed(return_value)
*/
55 return log;
56 }
57
58
59 public void loadPingTargets() {
60 try {
/*
P/P * Method: void loadPingTargets()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@61 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@61 != null
*
* Postconditions:
* possibly_updated(this.pingTargets)
*/
61 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
62 setPingTargets(pingTargetMgr.getCommonPingTargets());
63 } catch (WebloggerException ex) {
64 log.error("Error loading common ping targets", ex);
65 // TODO: i18n
66 addError("Error loading common ping targets");
67 }
68 }
69
70
71 /**
72 * Set a ping target auto enabled to true.
73 */
74 public String enable() {
75
/*
P/P * Method: String enable()
*
* Preconditions:
* init'ed(this.pingTarget)
* (soft) log != null
* (soft) init'ed(this.pingTargetId)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@80 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@80 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@82 != null
*
* Postconditions:
* return_value == &"list"
*
* Test Vectors:
* this.pingTarget: Addr_Set{null}, Inverse{null}
*/
76 if(getPingTarget() != null) {
77 try {
78 getPingTarget().setAutoEnabled(true);
79
80 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
81 pingTargetMgr.savePingTarget(getPingTarget());
82 WebloggerFactory.getWeblogger().flush();
83 } catch (Exception ex) {
84 getLogger().error("Error saving ping target", ex);
85 // TODO: i18n
86 addError("Error saving ping target.");
87 }
88 } else {
89 // TODO: i18n
90 addError("Cannot enable ping target - "+getPingTargetId());
91 }
92
93 return LIST;
94 }
95
96
97 /**
98 * Set a ping target auto-enable to false.
99 */
100 public String disable() {
101
/*
P/P * Method: String disable()
*
* Preconditions:
* init'ed(this.pingTarget)
* (soft) log != null
* (soft) init'ed(this.pingTargetId)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@106 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@106 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@108 != null
*
* Postconditions:
* return_value == &"list"
*
* Test Vectors:
* this.pingTarget: Addr_Set{null}, Inverse{null}
*/
102 if(getPingTarget() != null) {
103 try {
104 getPingTarget().setAutoEnabled(false);
105
106 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
107 pingTargetMgr.savePingTarget(getPingTarget());
108 WebloggerFactory.getWeblogger().flush();
109 } catch (Exception ex) {
110 getLogger().error("Error saving ping target", ex);
111 // TODO: i18n
112 addError("Error saving ping target.");
113 }
114 } else {
115 // TODO: i18n
116 addError("Cannot disable ping target - "+getPingTargetId());
117 }
118
119 return LIST;
120 }
121
122 }
SofCheck Inspector Build Version : 2.18479
| CommonPingTargets.java |
2009-Jan-02 14:25:36 |
| CommonPingTargets.class |
2009-Sep-04 03:12:46 |