File Source: PingTargetAddBase.java
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.common.PingTargetAddBase__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.logging.Log;
22 import org.apache.roller.weblogger.WebloggerException;
23 import org.apache.roller.weblogger.business.WebloggerFactory;
24 import org.apache.roller.weblogger.business.pings.PingTargetManager;
25 import org.apache.roller.weblogger.pojos.PingTarget;
26 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
27
28
29 /**
30 * Base implementation for action that can add a new ping target.
31 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.common.PingTargetAddBase()
*
* Postconditions:
* this.bean == &new PingTargetFormBean(PingTargetAddBase#1)
* new PingTargetFormBean(PingTargetAddBase#1) num objects == 1
* this.bean.id == null
* this.bean.name == null
* this.bean.pingUrl == null
*/
32 public abstract class PingTargetAddBase extends UIAction {
33
34 // a bean for managing submitted data
35 private PingTargetFormBean bean = new PingTargetFormBean();
36
37
38 // get logger
39 protected abstract Log getLogger();
40
41 // create a new ping target
42 protected abstract PingTarget createPingTarget();
43
44
45 public String execute() {
/*
P/P * Method: String execute()
*
* Postconditions:
* return_value == &"input"
*/
46 return INPUT;
47 }
48
49
50 /**
51 * Save a new ping target.
52 */
53 public String save() {
54
/*
P/P * Method: String save()
*
* Preconditions:
* this.bean != null
* init'ed(this.bean.name)
* init'ed(this.bean.pingUrl)
* (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.log != null
* (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargetAdd.log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@63 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@63 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@65 != null
*
* Postconditions:
* return_value in Addr_Set{&"success",&"input"}
*
* Test Vectors:
* org.apache.roller.weblogger.ui.struts2.common.PingTargetAddBase:hasActionErrors(...)@61: {1}, {0}
*/
55 PingTarget pingTarget = createPingTarget();
56
57 // Call private helper to validate ping target
58 // If there are errors, go back to the target edit page.
59 myValidate(pingTarget);
60
61 if(!hasActionErrors()) try {
62 // Appears to be ok. Save it and flush.
63 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
64 pingTargetMgr.savePingTarget(pingTarget);
65 WebloggerFactory.getWeblogger().flush();
66
67 addMessage("pingTarget.saved");
68
69 return SUCCESS;
70
71 } catch (WebloggerException ex) {
72 getLogger().error("Error adding ping target", ex);
73 // TODO: i18n
74 addError("Error adding ping target.");
75 }
76
77 return INPUT;
78 }
79
80
81 /**
82 * Private helper to validate a ping target.
83 */
84 protected void myValidate(PingTarget pingTarget) {
85
86 try {
/*
P/P * Method: void myValidate(PingTarget)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.log != null
* (soft) org/apache/roller/weblogger/ui/struts2/editor/CustomPingTargetAdd.log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getPingTargetManager(...)@87 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@87 != null
*
* Test Vectors:
* org.apache.roller.weblogger.business.pings.PingTargetManager:isHostnameKnown(...)@94: {1}, {0}
* org.apache.roller.weblogger.business.pings.PingTargetManager:isNameUnique(...)@88: {1}, {0}
* org.apache.roller.weblogger.business.pings.PingTargetManager:isUrlWellFormed(...)@92: {1}, {0}
*/
87 PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
88 if (!pingTargetMgr.isNameUnique(pingTarget)) {
89 addError("pingTarget.nameNotUnique");
90 }
91
92 if (!pingTargetMgr.isUrlWellFormed(pingTarget)) {
93 addError("pingTarget.malformedUrl");
94 } else if (!pingTargetMgr.isHostnameKnown(pingTarget)) {
95 addError("pingTarget.unknownHost");
96 }
97 } catch (WebloggerException ex) {
98 getLogger().error("Error validating ping target", ex);
99 // TODO: i18n
100 addError("Error doing ping target validation");
101 }
102 }
103
104
105 public PingTargetFormBean getBean() {
/*
P/P * Method: PingTargetFormBean getBean()
*
* Preconditions:
* init'ed(this.bean)
*
* Postconditions:
* return_value == this.bean
* init'ed(return_value)
*/
106 return bean;
107 }
108
109 public void setBean(PingTargetFormBean bean) {
/*
P/P * Method: void setBean(PingTargetFormBean)
*
* Postconditions:
* this.bean == bean
* init'ed(this.bean)
*/
110 this.bean = bean;
111 }
112
113 }
SofCheck Inspector Build Version : 2.18479
| PingTargetAddBase.java |
2009-Jan-02 14:25:38 |
| PingTargetAddBase.class |
2009-Sep-04 03:12:45 |