refactored view creation

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14029 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2008-12-31 14:48:47 +00:00
1 parent e666ecb18b
commit 0e4a7acc13
3 files changed
+33 -21

No files matched your search

+3 -20
View File
@@ -1888,27 +1888,10 @@ public final class Hudson extends AbstractModelObject implements ItemGroup<TopLe
public synchronized void doCreateView( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
try {
checkPermission(View.CREATE);
req.setCharacterEncoding("UTF-8");
String name = req.getParameter("name");
String mode = req.getParameter("mode");
try {
checkGoodName(name);
} catch (ParseException e) {
sendError(e, req, rsp);
return;
}
// create a view
View v = View.LIST.findByName(mode).newInstance(req,req.getSubmittedForm());
v.owner = this;
views.add(v);
views.add(View.create(req,rsp, this));
save();
// redirect to the config screen
rsp.sendRedirect2("./"+v.getUrl()+v.getPostConstructLandingPage());
} catch (ParseException e) {
sendError(e,req,rsp);
} catch (FormException e) {
sendError(e,req,rsp);
}
@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.text.ParseException;
/**
*
@@ -112,6 +113,18 @@ public class TreeView extends View implements ViewGroup {
owner.save();
}
public void doCreateView( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
try {
checkPermission(View.CREATE);
views.add(View.create(req,rsp, this));
save();
} catch (ParseException e) {
sendError(e,req,rsp);
} catch (FormException e) {
sendError(e,req,rsp);
}
}
public ViewDescriptor getDescriptor() {
return DESCRIPTOR;
}
+17 -1
View File
@@ -3,6 +3,7 @@ package hudson.model;
import hudson.ExtensionPoint;
import hudson.Util;
import hudson.model.Descriptor.FormException;
import static hudson.model.Hudson.checkGoodName;
import hudson.scm.ChangeLogSet.Entry;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndexBuilder;
@@ -113,7 +114,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
*/
public void rename(String newName) throws ParseException {
if(name.equals(newName)) return; // noop
Hudson.checkGoodName(newName);
checkGoodName(newName);
String oldName = name;
name = newName;
owner.onViewRenamed(this,oldName,newName);
@@ -526,4 +527,19 @@ public abstract class View extends AbstractModelObject implements AccessControll
public static Permission getItemCreatePermission() {
return Item.CREATE;
}
public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup owner) throws ParseException, FormException, IOException, ServletException {
req.setCharacterEncoding("UTF-8");
checkGoodName(req.getParameter("name"));
// create a view
View v = LIST.findByName(req.getParameter("mode")).newInstance(req,req.getSubmittedForm());
v.owner = owner;
// redirect to the config screen
rsp.sendRedirect2("./"+v.getUrl()+v.getPostConstructLandingPage());
return v;
}
}