From a9e309caa3919aa25068cde2879be938445e646c Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 31 Dec 2008 13:51:59 +0000 Subject: [PATCH] refactored the doConfigSubmit method. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14020 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/AllView.java | 7 ++++ core/src/main/java/hudson/model/ListView.java | 27 +++---------- core/src/main/java/hudson/model/MyView.java | 6 +++ core/src/main/java/hudson/model/View.java | 38 +++++++++++++++++++ 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/hudson/model/AllView.java b/core/src/main/java/hudson/model/AllView.java index f425e7e8d7..effc739673 100644 --- a/core/src/main/java/hudson/model/AllView.java +++ b/core/src/main/java/hudson/model/AllView.java @@ -8,6 +8,8 @@ import javax.servlet.ServletException; import java.io.IOException; import java.util.Collection; +import hudson.model.Descriptor.FormException; + /** * {@link View} that contains everything. * @@ -46,6 +48,11 @@ public class AllView extends View { // noop } + @Override + protected void submit(StaplerRequest req) throws IOException, ServletException, FormException { + // noop + } + public ViewDescriptor getDescriptor() { return DESCRIPTOR; } diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index 7b528849b2..86f83cee68 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -97,27 +97,23 @@ public class ListView extends View { @Override public synchronized void onJobRenamed(Item item, String oldName, String newName) { - jobNames.remove(oldName); - if(newName!=null) + if(jobNames.remove(oldName) && newName!=null) jobNames.add(newName); } /** - * Accepts submission from the configuration page. + * Handles the configuration submission. + * + * Load view-specific properties here. */ - public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { - checkPermission(CONFIGURE); - - req.setCharacterEncoding("UTF-8"); - + @Override + protected void submit(StaplerRequest req) { jobNames.clear(); for (TopLevelItem item : Hudson.getInstance().getItems()) { if(req.getParameter(item.getName())!=null) jobNames.add(item.getName()); } - description = Util.nullify(req.getParameter("description")); - if (req.getParameter("useincluderegex") != null) { includeRegex = Util.nullify(req.getParameter("includeRegex")); includePattern = Pattern.compile(includeRegex); @@ -125,17 +121,6 @@ public class ListView extends View { includeRegex = null; includePattern = null; } - - try { - rename(req.getParameter("name")); - } catch (ParseException e) { - sendError(e, req, rsp); - return; - } - - owner.save(); - - rsp.sendRedirect2("../"+name); } public ViewDescriptor getDescriptor() { diff --git a/core/src/main/java/hudson/model/MyView.java b/core/src/main/java/hudson/model/MyView.java index 9afab9c584..5556533476 100644 --- a/core/src/main/java/hudson/model/MyView.java +++ b/core/src/main/java/hudson/model/MyView.java @@ -11,6 +11,7 @@ import javax.servlet.ServletException; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.DataBoundConstructor; +import hudson.model.Descriptor.FormException; /** * {@link View} that only contains projects for which the current user has access to. @@ -56,6 +57,11 @@ public class MyView extends View { // noop } + @Override + protected void submit(StaplerRequest req) throws IOException, ServletException, FormException { + // noop + } + public ViewDescriptor getDescriptor() { return DESCRIPTOR; } diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 01b8934093..d3c3256851 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -2,6 +2,7 @@ package hudson.model; import hudson.ExtensionPoint; import hudson.Util; +import hudson.model.Descriptor.FormException; import hudson.scm.ChangeLogSet.Entry; import hudson.search.CollectionSearchIndex; import hudson.search.SearchIndexBuilder; @@ -404,6 +405,43 @@ public abstract class View extends AbstractModelObject implements AccessControll rsp.sendRedirect("."); // go to the top page } + /** + * Accepts submission from the configuration page. + * + * Subtypes should override the {@link #submit()} method. + */ + public final synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { + try { + checkPermission(CONFIGURE); + + req.setCharacterEncoding("UTF-8"); + + submit(req); + + description = Util.nullify(req.getParameter("description")); + + try { + rename(req.getParameter("name")); + } catch (ParseException e) { + sendError(e, req, rsp); + return; + } + + owner.save(); + + rsp.sendRedirect2("../"+name); + } catch (FormException e) { + sendError(e,req,rsp); + } + } + + /** + * Handles the configuration submission. + * + * Load view-specific properties here. + */ + protected abstract void submit(StaplerRequest req) throws IOException, ServletException, FormException; + /** * Deletes this view. */ -- GitLab