File Source: PingTargetsBase.java
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.common.PingTargetsBase__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 java.util.Collections;
22 import java.util.List;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.commons.logging.Log;
25 import org.apache.roller.weblogger.WebloggerException;
26 import org.apache.roller.weblogger.business.WebloggerFactory;
27 import org.apache.roller.weblogger.business.pings.PingTargetManager;
28 import org.apache.roller.weblogger.pojos.PingTarget;
29 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
30
31
32 /**
33 * Base implementation for action that lists available ping targets and can
34 * handle deletion of a single ping target (with confirmation).
35 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.common.PingTargetsBase()
*
* Presumptions:
* init'ed(java.util.Collections.EMPTY_LIST)
*
* Postconditions:
* this.pingTarget == null
* this.pingTargetId == null
* this.pingTargets == java.util.Collections.EMPTY_LIST
* (soft) init'ed(this.pingTargets)
*/
36 public abstract class PingTargetsBase extends UIAction {
37
38 // list of available ping targets
39 private List pingTargets = Collections.EMPTY_LIST;
40
41 // ping target we are working on, if any
42 private PingTarget pingTarget = null;
43
44 // id of the ping target to work on
45 private String pingTargetId = null;
46
47
48 // get logger
49 protected abstract Log getLogger();
50
51 // load up list of ping targets
52 protected abstract void loadPingTargets();
53
54
55 // prepare method needs to set ping targets list
56 public void myPrepare() {
57
58 // load list of ping targets
/*
P/P * Method: void myPrepare()
*
* Preconditions:
* init'ed(this.pingTargetId)
* (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargets.log != null
* (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargets.log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@64 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@64 != null
*
* Postconditions:
* possibly_updated(this.pingTarget)
* possibly_updated(this.pingTargets)
*
* Test Vectors:
* org.apache.commons.lang.StringUtils:isEmpty(...)@62: {1}, {0}
*/
59 loadPingTargets();
60
61 // load specified ping target if possible
62 if(!StringUtils.isEmpty(getPingTargetId())) {
63 try {
64 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
65 setPingTarget(pingTargetMgr.getPingTarget(getPingTargetId()));
66 } catch (WebloggerException ex) {
67 getLogger().error("Error looking up ping target - "+getPingTargetId(), ex);
68 }
69 }
70 }
71
72
73 /**
74 * Display the ping targets.
75 */
76 public String execute() {
/*
P/P * Method: String execute()
*
* Postconditions:
* return_value == &"list"
*/
77 return LIST;
78 }
79
80
81 /**
82 * Delete a ping target (load delete confirmation view).
83 */
84 public String deleteConfirm() {
85
/*
P/P * Method: String deleteConfirm()
*
* Preconditions:
* init'ed(this.pingTarget)
* (soft) init'ed(this.pingTargetId)
*
* Postconditions:
* return_value in Addr_Set{&"list",&"confirm"}
*
* Test Vectors:
* this.pingTarget: Addr_Set{null}, Inverse{null}
*/
86 if(getPingTarget() != null) {
87 setPageTitle("pingTarget.confirmRemoveTitle");
88
89 return "confirm";
90 } else {
91 // TODO: i18n
92 addError("Cannot delete ping target: " + getPingTargetId());
93 }
94
95 return LIST;
96 }
97
98
99 /**
100 * Delete a ping target.
101 */
102 public String delete() {
103
/*
P/P * Method: String delete()
*
* Preconditions:
* init'ed(this.pingTarget)
* (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargets.log != null
* (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargets.log != null
* (soft) init'ed(this.pingTargetId)
* (soft) this.pingTargets != 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 == &"list"
*
* Test Vectors:
* this.pingTarget: Addr_Set{null}, Inverse{null}
*/
104 if(getPingTarget() != null) {
105
106 try {
107 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
108 pingTargetMgr.removePingTarget(getPingTarget());
109 WebloggerFactory.getWeblogger().flush();
110
111 // remove deleted target from list
112 getPingTargets().remove(getPingTarget());
113
114 // TODO: i18n
115 addMessage("Successfully deleted ping target: "+getPingTarget().getName());
116
117 } catch (WebloggerException ex) {
118 getLogger().error("Error deleting ping target - "+getPingTargetId(), ex);
119 // TODO: i18n
120 addError("Error deleting ping target - "+getPingTargetId());
121 }
122 } else {
123 // TODO: i18n
124 addError("Cannot delete ping target: " + getPingTargetId());
125 }
126
127 return LIST;
128 }
129
130
131 public List getPingTargets() {
/*
P/P * Method: List getPingTargets()
*
* Preconditions:
* init'ed(this.pingTargets)
*
* Postconditions:
* return_value == this.pingTargets
* init'ed(return_value)
*/
132 return pingTargets;
133 }
134
135 public void setPingTargets(List pingTargets) {
/*
P/P * Method: void setPingTargets(List)
*
* Postconditions:
* this.pingTargets == pingTargets
* init'ed(this.pingTargets)
*/
136 this.pingTargets = pingTargets;
137 }
138
139 public PingTarget getPingTarget() {
/*
P/P * Method: PingTarget getPingTarget()
*
* Preconditions:
* init'ed(this.pingTarget)
*
* Postconditions:
* return_value == this.pingTarget
* init'ed(return_value)
*/
140 return pingTarget;
141 }
142
143 public void setPingTarget(PingTarget pingTarget) {
/*
P/P * Method: void setPingTarget(PingTarget)
*
* Postconditions:
* this.pingTarget == pingTarget
* init'ed(this.pingTarget)
*/
144 this.pingTarget = pingTarget;
145 }
146
147 public String getPingTargetId() {
/*
P/P * Method: String getPingTargetId()
*
* Preconditions:
* init'ed(this.pingTargetId)
*
* Postconditions:
* return_value == this.pingTargetId
* init'ed(return_value)
*/
148 return pingTargetId;
149 }
150
151 public void setPingTargetId(String pingTargetId) {
/*
P/P * Method: void setPingTargetId(String)
*
* Postconditions:
* this.pingTargetId == pingTargetId
* init'ed(this.pingTargetId)
*/
152 this.pingTargetId = pingTargetId;
153 }
154
155 }
SofCheck Inspector Build Version : 2.18479
| PingTargetsBase.java |
2009-Jan-02 14:24:54 |
| PingTargetsBase.class |
2009-Sep-04 03:12:45 |