1 package org.naftulin.classpathexplorer.dublicate.imlp; 2 3 import java.io.File; 4 import java.io.IOException; 5 6 import org.naftulin.classpathexplorer.AccessibleResource; 7 8 9 /*** 10 * Representing an archive which is a directory or jar (zip). 11 * 12 * @author henry naftulin 13 * @version 1.0 14 */ 15 public abstract class AccessibleArchive implements AccessibleResource { 16 private final String path; 17 private final long lastModified; 18 19 /*** 20 * Creates accessible archive based on the given the file or directory 21 * @param file archive file or directory 22 */ 23 AccessibleArchive(File file) { 24 this.path = file.getPath(); 25 this.lastModified = file.lastModified(); 26 } 27 28 /*** 29 * Returns the path for the resource. 30 * @return the path for the resource. 31 */ 32 public String getPath() { 33 return path; 34 } 35 /*** 36 * Returns the path, since for archives key is the path. 37 * Key is needed for resource registry. 38 * @return key which is the path 39 */ 40 public String getKey() { 41 return getPath(); 42 } 43 44 /*** 45 * Returns the name of the archive. 46 * @return the name of the archive. 47 */ 48 public String getName() { 49 String name = path; 50 int dirSepartaorIndex =path.lastIndexOf(File.separator); 51 if (dirSepartaorIndex >0){ 52 name = path.substring(dirSepartaorIndex+1); 53 } 54 return name; 55 } 56 57 /*** 58 * Returns the archive the resource is located in. By default 59 * returns null. 60 * @return null 61 */ 62 public AccessibleArchive getArchive() { return null; } 63 64 /*** 65 * Returns the path for the resource. If resource resides in an archive, 66 * (e.g. zip or jar) path represents a full path: path to the 67 * archive and path of the resource within an archive. 68 * @return the path for the resource. 69 */ 70 public String getFullPath() { return path; } 71 72 /*** 73 * Returns the last modified Date as long 74 * @return the last modified Date as long 75 */ 76 public long getLastModified() { return lastModified; } 77 78 /*** 79 * Returns all of the resources in this archive or directory. 80 * @return all of the resources in this archive or directory. 81 * @throws IOException if an error occurs while reading the content of 82 * the archive or the directory. 83 */ 84 public abstract AccessibleResource[] getAccessibleResources() throws IOException; 85 86 /*** 87 * Supplies part of the toString implementation for the overwriting classes 88 * @return part of the toString implementation for the overwriting classes 89 */ 90 public String toString() { 91 StringBuffer sb = new StringBuffer(50); 92 sb.append("path=").append(getPath()); 93 return sb.toString(); 94 } 95 96 /*** 97 * Supplies part of the toXml implementation for the overwriting classes 98 * @return part of the toXml implementation for the overwriting classes 99 */ 100 public String toXml() { 101 StringBuffer sb = new StringBuffer(50); 102 sb.append(" path='").append(getPath()).append("' "); 103 return sb.toString(); 104 } 105 }