1 19 package org.openharmonise.vfs; 20 21 import java.net.URI ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.StringTokenizer ; 26 27 import org.openharmonise.vfs.authentication.*; 28 import org.openharmonise.vfs.metadata.*; 29 import org.openharmonise.vfs.search.*; 30 import org.openharmonise.vfs.status.*; 31 32 33 41 public abstract class AbstractVirtualFileSystem { 42 43 46 private static String PATH_SEPATATOR = "\\"; 47 48 51 private URI m_uri = null; 52 53 56 protected String m_sInitialPath = null; 57 60 protected String m_sRootPathSegment = null; 61 62 65 private AuthInfo m_authInfo = null; 66 67 70 private AbstractAuthenticationStore m_authStore = null; 71 72 75 private ArrayList m_errorListeners = new ArrayList (3); 76 77 80 public AbstractVirtualFileSystem(URI uri) { 81 super(); 82 m_uri = uri; 83 this.pathSetup(uri.getPath()); 84 } 85 86 90 public AbstractVirtualFileSystem(URI uri, AuthInfo authInfo) { 91 super(); 92 m_uri = uri; 93 m_authInfo = authInfo; 94 this.pathSetup(uri.getPath()); 95 } 96 97 101 public AbstractVirtualFileSystem(URI uri, AbstractAuthenticationStore authStore) { 102 super(); 103 m_uri = uri; 104 m_authStore = authStore; 105 this.pathSetup(uri.getPath()); 106 } 107 108 114 protected String getParentPath(String sFullPath) { 115 return sFullPath.substring(0, sFullPath.lastIndexOf('/')); 116 } 117 118 125 public String getInitialPath() { 126 return this.m_sInitialPath; 127 } 128 129 136 public String getRootPathSegment() { 137 return this.m_sRootPathSegment; 138 } 139 140 147 private void pathSetup(String sPath) { 148 149 StringTokenizer sTok = new StringTokenizer (sPath, "/", false); 150 151 String sInitialPath = ""; 152 ArrayList aPathSegments = new ArrayList (5); 153 154 while(sTok.hasMoreElements()) { 155 aPathSegments.add(sTok.nextElement()); 156 } 157 Iterator itor = aPathSegments.iterator(); 158 String sPathSegment = null; 159 while(itor.hasNext()) { 160 sPathSegment = (String )itor.next(); 161 if( itor.hasNext()) { 162 sInitialPath = sInitialPath + "/" + sPathSegment; 163 } 164 } 165 this.m_sInitialPath = sInitialPath; 166 this.m_sRootPathSegment = sPathSegment; 167 } 168 169 174 public AuthInfo getAuthentication() { 175 AuthInfo authInfo = null; 176 177 if( this.m_authInfo!=null ) { 178 authInfo = this.m_authInfo; 179 } else if(this.m_authStore!=null) { 180 this.m_authInfo = this.m_authStore.getAuthentication(this.m_uri); 181 authInfo = this.m_authInfo; 182 } else { 183 authInfo = new AuthInfo(); 184 authInfo.setUsername("simulacra"); 185 this.m_authInfo = authInfo; 186 } 187 188 return authInfo; 189 } 190 191 196 public void addErrorListener( VirtualFileSystemErrorListener listener) { 197 this.m_errorListeners.add(listener); 198 } 199 200 207 protected void fireErrorEvent(String sMessage, String sDetails) { 208 ErrorEvent error = new ErrorEvent(sMessage, sDetails); 209 Iterator itor = this.m_errorListeners.iterator(); 210 while(itor.hasNext()) { 211 ((VirtualFileSystemErrorListener)itor.next()).error(error); 212 } 213 } 214 215 223 public static List getPathSegments(String sPath, String sPathSeparator) { 224 ArrayList aSegments = new ArrayList (7); 225 226 StringTokenizer sTok = new StringTokenizer (sPath, sPathSeparator, false); 227 while(sTok.hasMoreElements()) { 228 String sTemp = (String )sTok.nextElement(); 229 aSegments.add(sTemp); 230 } 231 232 return aSegments; 233 } 234 235 240 public URI getURI() { 241 return this.m_uri; 242 } 243 244 249 public abstract List getOptions(); 250 251 258 public abstract ResourceStatusWrapper getVirtualFile(String sFullPath); 259 260 267 public abstract ResourceStatusWrapper addVirtualFile(String sPath, VirtualFile vfFile); 268 269 274 protected void clearVirtualFileChildren(VirtualFile vfFile) { 275 vfFile.clearChildren(); 276 } 277 278 285 public abstract StatusData orderVirtualFileChildren(List aPaths, VirtualFile vfDir); 286 287 294 public abstract StatusData moveVirtualFile(String sFromFullPath, String sToFullPath); 295 296 303 public abstract StatusData copyVirtualFile(String sFromFullPath, String sToFullPath); 304 305 311 public abstract StatusData deleteVirtualFile(String sFullPath); 312 313 319 public abstract StatusData lockVirtualFile(String sFullPath); 320 321 327 public abstract StatusData unlockVirtualFile(String sFullPath); 328 329 335 public abstract StatusData createVirtualDirectory(String sFullPath); 336 337 344 public abstract StatusData createShortcut(String sFullPath, String sToFullPath); 345 346 353 public abstract ResourceListStatusWrapper search( Query query); 354 355 362 public abstract boolean exists(String sFullPath); 363 364 370 public abstract VirtualFileSystemView getVirtualFileSystemView(); 371 372 378 public abstract byte[] getVirtualFileContent(String sFullPath); 379 380 387 protected abstract void fullyPopulateFileMetadata(VirtualFile vfFile); 388 389 395 protected abstract void fullyPopulateFileChildren(VirtualFile vfFile); 396 397 404 public abstract StatusData synchroniseFile(VirtualFile vfFile); 405 406 413 public abstract StatusData synchroniseAllFiles(); 414 415 423 public abstract boolean rejectAllChanges(); 424 425 431 protected boolean isFileContentPopulated(VirtualFile vfFile) { 432 return vfFile.isContentPopulated(); 433 } 434 435 441 protected void setFileContentPopulated(VirtualFile vfFile, boolean bContentPopulated) { 442 vfFile.setContentPopulated(bContentPopulated); 443 } 444 445 451 protected boolean isFileChildrenPopulated(VirtualFile vfFile) { 452 return vfFile.isChildrenPopulated(); 453 } 454 455 461 protected void setFileChildrenPopulated(VirtualFile vfFile, boolean bChildrenPopulated) { 462 vfFile.setChildrenPopulated(bChildrenPopulated); 463 } 464 465 471 protected boolean isFileMetadataPopulated(VirtualFile vfFile) { 472 return vfFile.isMetadataPopulated(); 473 } 474 475 481 protected void setFileMetadataPopulated(VirtualFile vfFile, boolean bMetadataPopulated) { 482 vfFile.setMetadataPopulated(bMetadataPopulated); 483 } 484 485 491 protected void setFileIsVersionable(VirtualFile vfFile, boolean bVersionable) { 492 vfFile.setVersionable(bVersionable); 493 } 494 495 501 protected void setFileState(VirtualFile vfFile, String sState) { 502 vfFile.setState(sState); 503 } 504 505 511 protected void addFileAllowedMethod(VirtualFile vfFile, String sMethod) { 512 vfFile.addAllowedMethods(sMethod); 513 } 514 515 520 protected abstract void fullyPopulateFileAllowedMethods(VirtualFile vfFile); 521 522 527 protected void clearFileAllowedMethods(VirtualFile vfFile) { 528 vfFile.clearAllowedMethods(); 529 } 530 531 538 protected abstract void refreshChildren(VirtualFile vfFile); 539 540 545 public void discardFileChanges(String sPath) { 546 VirtualFile vfFile = this.getVirtualFile(sPath).getResource(); 547 vfFile.discardChanges(); 548 } 549 550 557 protected void setOrderableDirectory(VirtualFile vfFile, boolean bOrderableDirectory) { 558 vfFile.setOrderableDirectory(bOrderableDirectory); 559 } 560 561 566 protected void clearAllFileProperties(VirtualFile vfFile) { 567 vfFile.clearAllProperties(); 568 } 569 570 577 public abstract ValueInstance getNewValueInstance(PropertyInstance propInst); 578 579 586 public abstract String currentUserResourcePath(AuthInfo authInfo); 587 588 public abstract List getChangedVirtualFiles(); 589 590 public abstract VirtualFile getPropertyVirtualFile(String sPropPath); 591 592 } 593
| Popular Tags
|