1 package com.knowgate.workareas; 2 3 import java.lang.Exception ; 4 import java.util.Properties ; 5 import java.io.IOException ; 6 7 import com.enterprisedt.net.ftp.FTPException; 8 9 import com.knowgate.debug.DebugFile; 10 import com.knowgate.dfs.FileSystem; 11 12 public class FileSystemWorkArea extends FileSystem { 13 private Properties oPropsCNF; 14 15 private FileSystemWorkArea() { oPropsCNF= null; } 16 17 private FileSystemWorkArea(String sUser, String sPwd) { oPropsCNF= null; } 18 19 public FileSystemWorkArea(Properties oEnvProps) { 20 super(oEnvProps); 21 oPropsCNF = oEnvProps; 22 } 23 24 26 37 38 private boolean mkworkpath (Properties oProps, String sWorkArea, String sPath) 39 throws IOException ,IllegalArgumentException { 40 boolean bRetVal = false; 41 42 if (DebugFile.trace) { 43 DebugFile.writeln("Begin FileSystemWorkArea.mkworkpath(" + sPath + ")"); 44 DebugFile.incIdent(); 45 } 46 47 if (sWorkArea==null) 48 throw new IllegalArgumentException ("WorkArea GUID may not be null"); 49 50 String sWorkAreaPath = oProps.getProperty("workareasput"); 51 if (!sWorkAreaPath.endsWith(SLASH)) sWorkAreaPath += SLASH; 52 53 try { 54 if (null==sPath) 55 bRetVal = mkdirs("file://" + sWorkAreaPath + sWorkArea); 56 else 57 bRetVal = mkdirs("file://" + sWorkAreaPath + sWorkArea + SLASH + sPath); 58 } 59 catch (IOException ioe) { throw new IOException (ioe.getMessage()); } 60 catch (Exception e) { } 61 62 if (DebugFile.trace) { 63 DebugFile.decIdent(); 64 DebugFile.writeln("End FileSystemWorkArea.mkworkpath() : " + String.valueOf(bRetVal)); 65 } 66 67 return bRetVal; 68 } 70 72 78 private boolean mkworkpath (Properties oProps, String sWorkArea) 79 throws IOException ,IllegalArgumentException { 80 81 return mkworkpath(oProps, sWorkArea, null); 82 } 83 84 86 95 public boolean mkworkpath (String sWorkArea, String sPath) throws Exception ,IOException { 96 return mkworkpath(oPropsCNF, sWorkArea, sPath); 97 } 98 99 101 107 public boolean mkworkpath (String sWorkArea) 108 throws IOException ,IllegalArgumentException { 109 110 return mkworkpath(oPropsCNF, sWorkArea, null); 111 } 112 113 115 127 128 private boolean rmworkpath (Properties oProps, String sWorkArea, String sPath) 129 throws IOException ,IllegalArgumentException ,NullPointerException { 130 boolean bRetVal = false; 131 132 if (DebugFile.trace) { 133 DebugFile.writeln("Begin FileSystemWorkArea.rmworkpath(" + sPath + ")"); 134 DebugFile.incIdent(); 135 } 136 137 String sWorkAreaPath = oProps.getProperty("workareasput"); 138 139 if (sWorkAreaPath==null) { 140 throw new NullPointerException ("Cannot find property workareasput at configuration file"); 141 } 142 else { 143 if (sPath == null) { 144 bRetVal = rmdir ("file://" + sWorkAreaPath); 145 } 146 else { 147 if (!sWorkAreaPath.endsWith(SLASH) && !sPath.startsWith(SLASH)) sWorkAreaPath += SLASH; 148 bRetVal = rmdir ("file://" + sWorkAreaPath + sPath); 149 } 150 } 151 152 if (DebugFile.trace) { 153 DebugFile.decIdent(); 154 DebugFile.writeln("End FileSystemWorkArea.rmworkpath() : " + String.valueOf(bRetVal)); 155 } 156 157 return bRetVal; 158 } 160 162 172 173 public boolean rmworkpath (String sWorkArea, String sPath) 174 throws IOException ,IllegalArgumentException { 175 return rmworkpath(oPropsCNF, sWorkArea, sPath); 176 } 177 178 180 188 189 public boolean rmworkpath (String sWorkArea) 190 throws IOException ,IllegalArgumentException { 191 return rmworkpath(oPropsCNF, sWorkArea, null); 192 } 193 194 196 210 211 private boolean mkstorpath (Properties oProps, int iDomain, String sWorkArea, String sPath) 212 throws Exception ,IOException ,IllegalArgumentException { 213 boolean bRetVal = false; 214 215 if (DebugFile.trace) { 216 DebugFile.writeln("Begin FileSystemWorkArea.mkstorpath([Properties]," + String.valueOf(iDomain) + "," + sWorkArea + "," + sPath + ")"); 217 DebugFile.incIdent(); 218 } 219 220 if (sWorkArea==null) 221 throw new IllegalArgumentException ("WorkArea GUID may not be null"); 222 223 String sProtocol = oProps.getProperty("protocol", "file://"); 224 String sWorkAreaPath = oProps.getProperty("storage"); 225 226 if (sProtocol.equalsIgnoreCase("ftp://")) { 227 if (!sWorkAreaPath.endsWith("/")) sWorkAreaPath += "/"; 228 sWorkAreaPath += "domains/" + String.valueOf(iDomain) + "/workareas/" + sWorkArea; 229 230 if (null==sPath) 231 bRetVal = mkdirs(sProtocol + oProps.getProperty("protocol", "localhost") + "/" + sWorkAreaPath); 232 else 233 bRetVal = mkdirs(sProtocol + oProps.getProperty("protocol", "localhost") + "/" + sWorkAreaPath + (sPath.startsWith("/") ? sPath : "/" + sPath)); 234 } 235 else { 236 if (!sWorkAreaPath.endsWith(SLASH)) sWorkAreaPath += SLASH; 237 238 sWorkAreaPath += "domains" + SLASH + String.valueOf(iDomain) + SLASH + "workareas" + SLASH + sWorkArea; 239 240 if (null==sPath) 241 bRetVal = mkdirs(sProtocol + sWorkAreaPath); 242 else 243 bRetVal = mkdirs(sProtocol + sWorkAreaPath + (sPath.startsWith(SLASH) ? sPath : SLASH+sPath)); 244 } 246 if (DebugFile.trace) { 247 DebugFile.decIdent(); 248 DebugFile.writeln("End FileSystemWorkArea.mkstorpath() : " + String.valueOf(bRetVal)); 249 } 250 251 return bRetVal; 252 } 254 256 268 public boolean mkstorpath (int iDomain, String sWorkArea, String sPath) throws Exception ,IOException { 269 return mkstorpath(oPropsCNF, iDomain, sWorkArea, sPath); 270 } 271 272 281 private boolean rmstorpath (Properties oProps, int iDomain, String sWorkArea, String sPath) throws Exception ,IOException { 282 boolean bRetVal = false; 283 284 if (DebugFile.trace) { 285 DebugFile.writeln("Begin FileSystemWorkArea.rmstorpath (" + String.valueOf(iDomain) + "," + sWorkArea + "," + (sPath==null ? "null" : sPath) + ")"); 286 DebugFile.incIdent(); 287 } 288 289 String sProtocol = oProps.getProperty("protocol", "file://"); 290 String sWorkAreaPath = oProps.getProperty("storage"); 291 292 if (sProtocol.equalsIgnoreCase("ftp://")) { 293 if (!sWorkAreaPath.endsWith("/")) sWorkAreaPath += "/"; 294 sWorkAreaPath += "domains/" + String.valueOf(iDomain) + "/workareas/" + sWorkArea; 295 296 if (null==sPath) 297 bRetVal = rmdir(sProtocol + oProps.getProperty("protocol", "localhost") + "/" + sWorkAreaPath); 298 else 299 bRetVal = rmdir(sProtocol + oProps.getProperty("protocol", "localhost") + "/" + sWorkAreaPath + (sPath.startsWith("/") ? sPath : "/" + sPath)); 300 } 301 else { 302 if (!sWorkAreaPath.endsWith(SLASH)) sWorkAreaPath += SLASH; 303 304 sWorkAreaPath += "domains" + SLASH + String.valueOf(iDomain) + SLASH + "workareas" + SLASH + sWorkArea; 305 306 if (null==sPath) 307 bRetVal = rmdir(sProtocol + sWorkAreaPath); 308 else 309 bRetVal = rmdir(sProtocol + sWorkAreaPath + (sPath.startsWith(SLASH) ? sPath : SLASH+sPath)); 310 } 311 312 if (DebugFile.trace) { 313 DebugFile.decIdent(); 314 DebugFile.writeln("End FileSystemWorkArea.rmworkpath() : " + String.valueOf(bRetVal)); 315 } 316 317 return bRetVal; 318 } 320 322 330 331 public boolean rmstorpath (int iDomain, String sWorkArea, String sPath) throws Exception ,IOException { 332 return rmstorpath(oPropsCNF, iDomain, sWorkArea, sPath); 333 } 334 335 342 343 public boolean rmstorpath (int iDomain, String sWorkArea) throws Exception ,IOException { 344 return rmstorpath(oPropsCNF, iDomain, sWorkArea, null); 345 } 346 347 } | Popular Tags |