Author: gmazza
Date: Sat Aug  9 17:14:11 2014
New Revision: 1616995

URL: http://svn.apache.org/r1616995
Log:
CommonPingTargetEdit and PingTargetEditBase merged into PingTargetEdit

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

Copied: 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetEdit.java
 (from r1616975, 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetEdit.java)
URL: 
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetEdit.java?p2=roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetEdit.java&p1=roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetEdit.java&r1=1616975&r2=1616995&rev=1616995&view=diff
==============================================================================
--- 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/CommonPingTargetEdit.java
 (original)
+++ 
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargetEdit.java
 Sat Aug  9 17:14:11 2014
@@ -18,36 +18,132 @@
 
 package org.apache.roller.weblogger.ui.struts2.admin;
 
-import java.util.Collections;
-import java.util.List;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.weblogger.pojos.GlobalPermission;
-import org.apache.roller.weblogger.ui.struts2.common.PingTargetEditBase;
+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.PingTarget;
+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 CommonPingTargetEdit extends PingTargetEditBase {
+public class PingTargetEdit extends UIAction {
     
-    private static Log log = LogFactory.getLog(CommonPingTargetEdit.class);
+    private static Log log = LogFactory.getLog(PingTargetEdit.class);
 
-    public CommonPingTargetEdit() {
+    // ping target we are working on, if any
+    private PingTarget pingTarget = null;
+
+    // a bean for managing submitted data
+    private PingTargetFormBean bean = new PingTargetFormBean();
+
+    public PingTargetEdit() {
         this.desiredMenu = "admin";
         this.pageTitle = "pingTarget.pingTarget";
     }
 
-    public List<String> requiredGlobalPermissionActions() {
-        return Collections.singletonList(GlobalPermission.ADMIN);
-    }
-    
     // no weblog required
     public boolean isWeblogRequired() {
         return false;
     }
 
-    protected Log getLogger() {
-        return log;
+    public void myPrepare() {
+        PingTargetManager pingTargetMgr = 
WebloggerFactory.getWeblogger().getPingTargetManager();
+        if(!StringUtils.isEmpty(getBean().getId())) {
+            try {
+                pingTarget = pingTargetMgr.getPingTarget(getBean().getId());
+            } catch (WebloggerException ex) {
+                log.error("Error looking up ping target - "+getBean().getId());
+            }
+            if(pingTarget == null) {
+                addError("pingTarget.notFound", getBean().getId());
+            }
+        } else {
+            addError("pingTarget.unspecified");
+        }
+    }
+
+    public String execute() {
+        if(!hasActionErrors()) {
+            // load bean with data from ping target
+            getBean().copyFrom(pingTarget);
+        } else {
+            // if we already have an error then that means we couldn't load
+            // an existing ping target to work on, so return ERROR result
+            return ERROR;
+        }
+        return INPUT;
+    }
+
+    /**
+     * Save ping target.
+     */
+    public String save() {
+
+        if(hasActionErrors()) {
+            // if we already have an error then that means we couldn't load
+            // an existing ping target to work on, so return ERROR result
+            return INPUT;
+        }
+
+        // copy data from form into ping target
+        getBean().copyTo(pingTarget);
+
+        // Call private helper to validate ping target
+        // If there are errors, go back to the target edit page.
+        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");
+            } catch (WebloggerException ex) {
+                log.error("Error saving ping target", ex);
+                addError("pingTarget.saved.error");
+            }
+        }
+
+        return INPUT;
     }
 
+
+    /**
+     * Private helper to validate a ping target.
+     */
+    protected 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("pingTarget.saved.error");
+        }
+    }
+
+    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=1616995&r1=1616994&r2=1616995&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/struts.xml (original)
+++ roller/trunk/app/src/main/resources/struts.xml Sat Aug  9 17:14:11 2014
@@ -201,7 +201,7 @@
         </action>
         
         <action name="commonPingTargetEdit!*" method="{1}"
-                
class="org.apache.roller.weblogger.ui.struts2.admin.CommonPingTargetEdit">
+                
class="org.apache.roller.weblogger.ui.struts2.admin.PingTargetEdit">
             <param name="actionName">commonPingTargetEdit</param>
             <result name="input" type="tiles">.PingTargetEdit</result>
             <result name="error" type="chain">commonPingTargets</result>


Reply via email to