1 package hudson.model; 2 3 import hudson.Util; 4 import org.kohsuke.stapler.StaplerRequest; 5 import org.kohsuke.stapler.StaplerResponse; 6 7 import javax.servlet.ServletException ; 8 import java.io.IOException ; 9 import java.util.Arrays ; 10 import java.util.List ; 11 import java.util.Set ; 12 import java.util.TreeSet ; 13 14 19 public class ListView extends View { 20 21 private final Hudson owner; 22 23 26 final Set <String > jobNames = new TreeSet <String >(); 27 28 31 private String name; 32 33 36 private String description; 37 38 39 public ListView(Hudson owner, String name) { 40 this.name = name; 41 this.owner = owner; 42 } 43 44 51 public synchronized List <TopLevelItem> getItems() { 52 TopLevelItem[] items = new TopLevelItem[jobNames.size()]; 53 int i=0; 54 for (String name : jobNames) 55 items[i++] = owner.getItem(name); 56 return Arrays.asList(items); 57 } 58 59 public TopLevelItem getJob(String name) { 60 return owner.getItem(name); 61 } 62 63 public boolean contains(TopLevelItem item) { 64 return jobNames.contains(item.getName()); 65 } 66 67 public String getViewName() { 68 return name; 69 } 70 71 public String getDescription() { 72 return description; 73 } 74 75 public String getDisplayName() { 76 return name; 77 } 78 79 public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException , ServletException { 80 if(!Hudson.adminCheck(req,rsp)) 81 return null; 82 83 Item item = owner.doCreateItem(req, rsp); 84 if(item!=null) { 85 jobNames.add(item.getName()); 86 owner.save(); 87 } 88 return item; 89 } 90 91 public String getUrl() { 92 return "view/"+name+'/'; 93 } 94 95 98 public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException { 99 if(!Hudson.adminCheck(req,rsp)) 100 return; 101 102 req.setCharacterEncoding("UTF-8"); 103 104 jobNames.clear(); 105 for (TopLevelItem item : owner.getItems()) { 106 if(req.getParameter(item.getName())!=null) 107 jobNames.add(item.getName()); 108 } 109 110 description = Util.nullify(req.getParameter("description")); 111 112 owner.save(); 113 114 rsp.sendRedirect("."); 115 } 116 117 120 public synchronized void doSubmitDescription( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 121 if(!Hudson.adminCheck(req,rsp)) 122 return; 123 124 req.setCharacterEncoding("UTF-8"); 125 description = req.getParameter("description"); 126 owner.save(); 127 rsp.sendRedirect("."); } 129 130 133 public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException { 134 if(!Hudson.adminCheck(req,rsp)) 135 return; 136 137 owner.deleteView(this); 138 rsp.sendRedirect2(req.getContextPath()+"/"); 139 } 140 } 141 | Popular Tags |