1 17 18 package com.finalist.jag.taglib; 19 20 21 22 import java.util.*; 23 24 import com.finalist.jag.*; 25 import com.finalist.jag.taglib.util.RequestUtil; 26 27 28 35 public class FileTag extends TagBodySupport { 36 37 38 private String path = null; 39 40 41 private String title = null; 42 43 44 private String ext = null; 45 46 47 private String name = null; 48 49 50 private String property = null; 51 52 53 protected int counter = 0; 54 55 56 63 public void setName(String name) { 64 this.name = name; 65 } 66 67 74 public void setProperty(String property) { 75 this.property = property; 76 } 77 78 85 public String getName() { 86 return (this.name); 87 } 88 89 96 public String getProperty() { 97 return (this.property); 98 } 99 100 107 public String getPath() { 108 return (this.path); 109 } 110 111 118 public void setPath(String path) { 119 this.path = path; 120 } 121 122 129 public String getTitle() { 130 return (this.title); 131 } 132 133 140 public void setTitle(String title) { 141 this.title = title; 142 } 143 144 151 public String getExt() { 152 return (this.ext); 153 } 154 155 162 public void setExt(String ext) { 163 this.ext = ext; 164 } 165 166 175 public int doStartTag() throws JagException { 176 return (EVAL_PAGE); 177 } 178 179 188 public int doAfterBodyTag() throws JagException { 189 190 counter++; 191 if ((title == null) || (title.length() < 1)) { 193 if (counter == 1) { 194 return (EVAL_BODY_TAG); 195 } 196 else { 197 title = getBodyText(); 198 title = title.replace('\n',' '); 199 title = title.replace('\r',' '); 200 title = title.trim(); 201 } 202 } 203 StringBuffer filePath = new StringBuffer (); 205 206 if ((path != null) && (path.length() > 0)) { 207 filePath.append(path); 208 } 209 else if(name != null && property != null) 210 { 211 String value = RequestUtil.lookupString(getPageContext(), name, 212 property); 213 if (value == null) { 214 throw new JagException("WriteTag: Invalid name field >" 215 + name + "<"); 216 } 217 218 filePath.append(value); 219 } 220 221 filePath.append(title); 222 223 if ((ext != null) && (ext.length() > 0)) { 224 filePath.append("."); 225 filePath.append(ext); 226 } 227 getWriter().createNewFile(filePath); 229 return (SKIP_CLEAR_BODY); 230 } 231 } 232 ; | Popular Tags |