roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gma...@apache.org
Subject svn commit: r1616985 - in /roller/trunk/app/src/main: java/org/apache/roller/weblogger/ui/struts2/admin/ java/org/apache/roller/weblogger/ui/struts2/common/ resources/
Date Sat, 09 Aug 2014 16:19:12 GMT
Author: gmazza
Date: Sat Aug  9 16:19:11 2014
New Revision: 1616985

URL: http://svn.apache.org/r1616985
Log:
CommonPingTargetAdd and PingTargetAddBase merged into PingTargetAdd

Added:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetAdd.java
      - copied, changed from r1616975, roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.java
Removed:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/common/PingTargetAddBase.java
Modified:
    roller/trunk/app/src/main/resources/struts.xml

Copied: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetAdd.java
(from r1616975, roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.java)
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetAdd.java?p2=roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetAdd.java&p1=roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.java&r1=1616975&r2=1616985&rev=1616985&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetAdd.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetAdd.java
Sat Aug  9 16:19:11 2014
@@ -22,45 +22,90 @@ import java.util.Collections;
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.business.pings.PingTargetManager;
 import org.apache.roller.weblogger.pojos.GlobalPermission;
 import org.apache.roller.weblogger.pojos.PingTarget;
-import org.apache.roller.weblogger.ui.struts2.common.PingTargetAddBase;
+import org.apache.roller.weblogger.ui.struts2.common.PingTargetFormBean;
+import org.apache.roller.weblogger.ui.struts2.util.UIAction;
 
 
 /**
  * Add or modify a common ping target.
  */
-public class CommonPingTargetAdd extends PingTargetAddBase {
-    
-    private static Log log = LogFactory.getLog(CommonPingTargetAdd.class);
-    
-    
-    public CommonPingTargetAdd() {
+public class PingTargetAdd extends UIAction {
+    private static Log log = LogFactory.getLog(PingTargetAdd.class);
+
+    // a bean for managing submitted data
+    private PingTargetFormBean bean = new PingTargetFormBean();
+
+    public PingTargetAdd() {
         this.desiredMenu = "admin";
         this.pageTitle = "pingTarget.pingTarget";
     }
-    
-    
+
+    public String execute() {
+        return INPUT;
+    }
+
     public List<String> requiredGlobalPermissionActions() {
         return Collections.singletonList(GlobalPermission.ADMIN);
     }
-    
+
+    public String save() {
+        PingTarget pingTarget = new PingTarget(null, getBean().getName(),
+                getBean().getPingUrl(), false);
+
+        myValidate(pingTarget);
+
+        if(!hasActionErrors()) {
+            try {
+                // Appears to be ok.  Save it and flush.
+                PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
+                pingTargetMgr.savePingTarget(pingTarget);
+                WebloggerFactory.getWeblogger().flush();
+                addMessage("pingTarget.saved");
+                return SUCCESS;
+            } catch (WebloggerException ex) {
+                log.error("Error adding ping target", ex);
+                addError("pingTarget.saved.error");
+            }
+        }
+        return INPUT;
+    }
+
     // no weblog required
     public boolean isWeblogRequired() {
         return false;
     }
     
-    
-    protected Log getLogger() {
-        return log;
+    /**
+     * Private helper to validate a ping target.
+     */
+    private void myValidate(PingTarget pingTarget) {
+
+        try {
+            PingTargetManager pingTargetMgr = WebloggerFactory.getWeblogger().getPingTargetManager();
+            if (!pingTargetMgr.isNameUnique(pingTarget)) {
+                addError("pingTarget.nameNotUnique");
+            }
+            if (!pingTargetMgr.isUrlWellFormed(pingTarget)) {
+                addError("pingTarget.malformedUrl");
+            } else if (!pingTargetMgr.isHostnameKnown(pingTarget)) {
+                addError("pingTarget.unknownHost");
+            }
+        } catch (WebloggerException ex) {
+            log.error("Error validating ping target", ex);
+            addError("generic.error.check.logs");
+        }
     }
 
-    protected PingTarget createPingTarget() {
-        return new PingTarget(
-                null, 
-                getBean().getName(), 
-                getBean().getPingUrl(), 
-                false);
+    public PingTargetFormBean getBean() {
+        return bean;
+    }
+
+    public void setBean(PingTargetFormBean bean) {
+        this.bean = bean;
     }
-    
 }

Modified: roller/trunk/app/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/struts.xml?rev=1616985&r1=1616984&r2=1616985&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/struts.xml (original)
+++ roller/trunk/app/src/main/resources/struts.xml Sat Aug  9 16:19:11 2014
@@ -194,7 +194,7 @@
         </action>
         
         <action name="commonPingTargetAdd!*" method="{1}"
-                class="org.apache.roller.weblogger.ui.struts2.admin.CommonPingTargetAdd">
+                class="org.apache.roller.weblogger.ui.struts2.admin.PingTargetAdd">
             <param name="actionName">commonPingTargetAdd</param>
             <result name="input" type="tiles">.PingTargetEdit</result>
             <result name="success" type="chain">commonPingTargets</result>



Mime
View raw message