1 package hudson.model; 2 3 import hudson.XmlFile; 4 import hudson.Util; 5 6 import java.io.File ; 7 import java.io.IOException ; 8 import java.util.Collection ; 9 10 import org.kohsuke.stapler.StaplerRequest; 11 import org.kohsuke.stapler.StaplerResponse; 12 13 import javax.servlet.ServletException ; 14 15 20 public abstract class AbstractItem extends Actionable implements Item { 23 26 protected transient String name; 27 28 31 protected String description; 32 33 private transient ItemGroup parent; 34 35 protected AbstractItem(ItemGroup parent, String name) { 36 this.parent = parent; 37 doSetName(name); 38 } 39 40 public String getName() { 41 return name; 42 } 43 44 public String getDisplayName() { 45 return getName(); 46 } 47 48 public File getRootDir() { 49 return parent.getRootDirFor(this); 50 } 51 52 public ItemGroup getParent() { 53 assert parent!=null; 54 return parent; 55 } 56 57 60 public String getDescription() { 61 return description; 62 } 63 64 67 public void setDescription(String description) { 68 this.description = description; 69 } 70 71 75 protected void doSetName(String name) { 76 this.name = name; 77 getRootDir().mkdirs(); 78 } 79 80 83 public abstract Collection <? extends Job> getAllJobs(); 84 85 public final String getFullName() { 86 String n = getParent().getFullName(); 87 if(n.length()==0) return getName(); 88 else return n+'/'+getName(); 89 } 90 91 95 public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException { 96 this.parent = parent; 97 doSetName(name); 98 } 99 100 106 public void onCopiedFrom(Item src) { 107 } 108 109 public final String getUrl() { 110 return getParent().getUrl()+getShortUrl(); 111 } 112 113 public String getShortUrl() { 114 return getParent().getUrlChildPrefix()+'/'+getName()+'/'; 115 } 116 117 120 public synchronized void save() throws IOException { 121 getConfigFile().write(this); 122 } 123 124 protected final XmlFile getConfigFile() { 125 return Items.getConfigFile(this); 126 } 127 128 131 public synchronized void doSubmitDescription( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 132 if(!Hudson.adminCheck(req,rsp)) 133 return; 134 135 req.setCharacterEncoding("UTF-8"); 136 setDescription(req.getParameter("description")); 137 save(); 138 rsp.sendRedirect("."); } 140 141 144 public synchronized void doDoDelete( StaplerRequest req, StaplerResponse rsp ) throws IOException { 145 if(!Hudson.adminCheck(req,rsp)) 146 return; 147 Util.deleteRecursive(getRootDir()); 148 149 if(this instanceof TopLevelItem) 150 Hudson.getInstance().deleteJob((TopLevelItem)this); 151 rsp.sendRedirect2(req.getContextPath()+"/"); 152 } 153 } 154 | Popular Tags |