1 16 31 package org.apache.commons.vfs.provider.jar; 32 33 import org.apache.commons.vfs.FileName; 34 import org.apache.commons.vfs.FileObject; 35 import org.apache.commons.vfs.FileSystemException; 36 import org.apache.commons.vfs.FileSystemOptions; 37 import org.apache.commons.vfs.provider.zip.ZipFileObject; 38 import org.apache.commons.vfs.provider.zip.ZipFileSystem; 39 40 import java.io.File ; 41 import java.io.IOException ; 42 import java.util.Collection ; 43 import java.util.jar.Attributes ; 44 import java.util.jar.Attributes.Name; 45 import java.util.jar.JarFile ; 46 import java.util.jar.Manifest ; 47 import java.util.zip.ZipEntry ; 48 import java.util.zip.ZipFile ; 49 50 55 public class JarFileSystem 56 extends ZipFileSystem 57 { 58 private Attributes attributes; 59 60 protected JarFileSystem(final FileName rootName, 61 final FileObject file, 62 final FileSystemOptions fileSystemOptions) throws FileSystemException 63 { 64 super(rootName, file, fileSystemOptions); 65 } 66 67 protected ZipFile createZipFile(File file) throws FileSystemException 68 { 69 try 70 { 71 return new JarFile (file); 72 } 73 catch (IOException ioe) 74 { 75 throw new FileSystemException("vfs.provider.jar/open-jar-file.error", file, ioe); 76 } 77 } 78 79 protected ZipFileObject createZipFileObject(FileName name, 80 ZipEntry entry) throws FileSystemException 81 { 82 return new JarFileObject(name, entry, this, true); 83 } 84 85 88 protected void addCapabilities(final Collection caps) 89 { 90 caps.addAll(JarFileProvider.capabilities); 92 } 93 94 Attributes getAttributes() throws IOException 95 { 96 if (attributes == null) 97 { 98 final Manifest man = ((JarFile ) getZipFile()).getManifest(); 99 if (man == null) 100 { 101 attributes = new Attributes (1); 102 } 103 else 104 { 105 attributes = man.getMainAttributes(); 106 if (attributes == null) 107 { 108 attributes = new Attributes (1); 109 } 110 } 111 } 112 113 return attributes; 114 } 115 116 Object getAttribute(Name attrName) 117 throws FileSystemException 118 { 119 try 120 { 121 final Attributes attr = getAttributes(); 122 final String value = attr.getValue(attrName); 123 return value; 124 } 125 catch (IOException ioe) 126 { 127 throw new FileSystemException(attrName.toString(), ioe); 128 } 129 } 130 131 Name lookupName(String attrName) 132 { 133 if (Name.CLASS_PATH.equals(attrName)) 134 { 135 return Name.CLASS_PATH; 136 } 137 else if (Name.CONTENT_TYPE.equals(attrName)) 138 { 139 return Name.CONTENT_TYPE; 140 } 141 else if (Name.EXTENSION_INSTALLATION.equals(attrName)) 142 { 143 return Name.EXTENSION_INSTALLATION; 144 } 145 else if (Name.EXTENSION_LIST.equals(attrName)) 146 { 147 return Name.EXTENSION_LIST; 148 } 149 else if (Name.EXTENSION_NAME.equals(attrName)) 150 { 151 return Name.EXTENSION_NAME; 152 } 153 else if (Name.IMPLEMENTATION_TITLE.equals(attrName)) 154 { 155 return Name.IMPLEMENTATION_TITLE; 156 } 157 else if (Name.IMPLEMENTATION_URL.equals(attrName)) 158 { 159 return Name.IMPLEMENTATION_URL; 160 } 161 else if (Name.IMPLEMENTATION_VENDOR.equals(attrName)) 162 { 163 return Name.IMPLEMENTATION_VENDOR; 164 } 165 else if (Name.IMPLEMENTATION_VENDOR_ID.equals(attrName)) 166 { 167 return Name.IMPLEMENTATION_VENDOR_ID; 168 } 169 else if (Name.IMPLEMENTATION_VERSION.equals(attrName)) 170 { 171 return Name.IMPLEMENTATION_VENDOR; 172 } 173 else if (Name.MAIN_CLASS.equals(attrName)) 174 { 175 return Name.MAIN_CLASS; 176 } 177 else if (Name.MANIFEST_VERSION.equals(attrName)) 178 { 179 return Name.MANIFEST_VERSION; 180 } 181 else if (Name.SEALED.equals(attrName)) 182 { 183 return Name.SEALED; 184 } 185 else if (Name.SIGNATURE_VERSION.equals(attrName)) 186 { 187 return Name.SIGNATURE_VERSION; 188 } 189 else if (Name.SPECIFICATION_TITLE.equals(attrName)) 190 { 191 return Name.SPECIFICATION_TITLE; 192 } 193 else if (Name.SPECIFICATION_VENDOR.equals(attrName)) 194 { 195 return Name.SPECIFICATION_VENDOR; 196 } 197 else if (Name.SPECIFICATION_VERSION.equals(attrName)) 198 { 199 return Name.SPECIFICATION_VERSION; 200 } 201 else 202 { 203 return new Name(attrName); 204 } 205 } 206 207 211 public Object getAttribute(String attrName) throws FileSystemException 212 { 213 final Name name = lookupName(attrName); 214 return getAttribute(name); 215 } 216 217 218 protected ZipFile getZipFile() throws FileSystemException 219 { 220 return super.getZipFile(); 221 } 222 } 223 | Popular Tags |