提交 a9e309ca 编写于 作者: K kohsuke

refactored the doConfigSubmit method.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14020 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c8de7dda
...@@ -8,6 +8,8 @@ import javax.servlet.ServletException; ...@@ -8,6 +8,8 @@ import javax.servlet.ServletException;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import hudson.model.Descriptor.FormException;
/** /**
* {@link View} that contains everything. * {@link View} that contains everything.
* *
...@@ -46,6 +48,11 @@ public class AllView extends View { ...@@ -46,6 +48,11 @@ public class AllView extends View {
// noop // noop
} }
@Override
protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
// noop
}
public ViewDescriptor getDescriptor() { public ViewDescriptor getDescriptor() {
return DESCRIPTOR; return DESCRIPTOR;
} }
......
...@@ -97,27 +97,23 @@ public class ListView extends View { ...@@ -97,27 +97,23 @@ public class ListView extends View {
@Override @Override
public synchronized void onJobRenamed(Item item, String oldName, String newName) { public synchronized void onJobRenamed(Item item, String oldName, String newName) {
jobNames.remove(oldName); if(jobNames.remove(oldName) && newName!=null)
if(newName!=null)
jobNames.add(newName); 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 { @Override
checkPermission(CONFIGURE); protected void submit(StaplerRequest req) {
req.setCharacterEncoding("UTF-8");
jobNames.clear(); jobNames.clear();
for (TopLevelItem item : Hudson.getInstance().getItems()) { for (TopLevelItem item : Hudson.getInstance().getItems()) {
if(req.getParameter(item.getName())!=null) if(req.getParameter(item.getName())!=null)
jobNames.add(item.getName()); jobNames.add(item.getName());
} }
description = Util.nullify(req.getParameter("description"));
if (req.getParameter("useincluderegex") != null) { if (req.getParameter("useincluderegex") != null) {
includeRegex = Util.nullify(req.getParameter("includeRegex")); includeRegex = Util.nullify(req.getParameter("includeRegex"));
includePattern = Pattern.compile(includeRegex); includePattern = Pattern.compile(includeRegex);
...@@ -125,17 +121,6 @@ public class ListView extends View { ...@@ -125,17 +121,6 @@ public class ListView extends View {
includeRegex = null; includeRegex = null;
includePattern = null; includePattern = null;
} }
try {
rename(req.getParameter("name"));
} catch (ParseException e) {
sendError(e, req, rsp);
return;
}
owner.save();
rsp.sendRedirect2("../"+name);
} }
public ViewDescriptor getDescriptor() { public ViewDescriptor getDescriptor() {
......
...@@ -11,6 +11,7 @@ import javax.servlet.ServletException; ...@@ -11,6 +11,7 @@ import javax.servlet.ServletException;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;
import hudson.model.Descriptor.FormException;
/** /**
* {@link View} that only contains projects for which the current user has access to. * {@link View} that only contains projects for which the current user has access to.
...@@ -56,6 +57,11 @@ public class MyView extends View { ...@@ -56,6 +57,11 @@ public class MyView extends View {
// noop // noop
} }
@Override
protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
// noop
}
public ViewDescriptor getDescriptor() { public ViewDescriptor getDescriptor() {
return DESCRIPTOR; return DESCRIPTOR;
} }
......
...@@ -2,6 +2,7 @@ package hudson.model; ...@@ -2,6 +2,7 @@ package hudson.model;
import hudson.ExtensionPoint; import hudson.ExtensionPoint;
import hudson.Util; import hudson.Util;
import hudson.model.Descriptor.FormException;
import hudson.scm.ChangeLogSet.Entry; import hudson.scm.ChangeLogSet.Entry;
import hudson.search.CollectionSearchIndex; import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndexBuilder; import hudson.search.SearchIndexBuilder;
...@@ -404,6 +405,43 @@ public abstract class View extends AbstractModelObject implements AccessControll ...@@ -404,6 +405,43 @@ public abstract class View extends AbstractModelObject implements AccessControll
rsp.sendRedirect("."); // go to the top page 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. * Deletes this view.
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册