1 16 17 package org.apache.taglibs.gnat; 18 19 import org.apache.taglibs.gnat.util.*; 20 import javax.servlet.ServletContext ; 21 import javax.servlet.jsp.*; 22 import javax.servlet.jsp.tagext.*; 23 import java.io.*; 24 import java.util.*; 25 26 public class mkdirTag extends TagSupport 27 { 28 private File _f; 30 private String dir = ""; 31 private boolean clobber= false; 32 private ResourceBundle gnatRB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatTagStrings"); 33 private ResourceBundle gnatERB = ListResourceBundle.getBundle("org.apache.taglibs.gnat.util.GnatExceptionStrings"); 34 35 public void setDir(String dir) 36 { 37 this.dir = dir; 38 } 39 40 public void setClobber(boolean clobber) 41 { 42 this.clobber = clobber; 43 } 44 45 46 public int doStartTag() throws JspException 47 { 48 _f = new File(dir); 49 return SKIP_BODY; 50 } 51 52 public int doEndTag() throws JspException 53 { 54 55 if (_f == null) 56 { 57 throw new JspTagException( gnatRB.getString("mkdir.tag") + ": " + 58 gnatERB.getString("empty.dir.attribute") ); 59 } 60 61 ServletContext ctx = pageContext.getServletContext(); 62 if (clobber) { 64 if (_f.exists()) 65 { ctx.log(gnatRB.getString("mkdir.tag") + ": " +"Overwriting dir " + _f.toString()); 67 try { FileUtil.forceDelete(_f); 69 } 70 catch(IOException ioe) { 71 throw new JspTagException( gnatRB.getString("mkdir.tag") + ": " + 72 ioe.getMessage() ); 73 } 74 } 75 76 boolean result = _f.mkdirs(); 77 if (result == false) 78 { 79 String msg = gnatRB.getString("mkdir.tag") + ": " + 80 gnatERB.getString("unknown.mkdir.fail") + 81 _f.getAbsolutePath(); 82 83 throw new JspTagException(msg); 84 } 85 ctx.log( gnatRB.getString("mkdir.tag") + ": " + 86 gnatRB.getString("mkdir.success") + 87 _f.getAbsolutePath() ); 88 } 89 else if(!clobber) { 91 if (_f.exists()) { 93 throw new JspTagException( gnatRB.getString("mkdir.tag") + ": " + 94 gnatERB.getString("duplicate.mkdir.fail") + 95 _f.getAbsolutePath() ); 96 } 97 else 98 { 99 100 boolean result = _f.mkdirs(); 101 if (result == false) 102 { 103 String msg = gnatRB.getString("mkdir.tag") + ": " + 104 gnatERB.getString("unknown.mkdir.fail") + 105 _f.getAbsolutePath(); 106 107 throw new JspTagException(msg); 108 } 109 ctx.log( gnatRB.getString("mkdir.tag") + ": " + 110 gnatRB.getString("mkdir.success") + 111 _f.getAbsolutePath() ); 112 } 113 } 114 115 return EVAL_PAGE; 116 } 117 118 public String getDir() { return dir; } 119 public boolean getClobber() { return clobber; } 120 } 121 | Popular Tags |