1 16 package org.apache.commons.vfs.provider.jar; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.provider.zip.ZipFileObject; 21 22 import java.io.IOException ; 23 import java.security.cert.Certificate ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import java.util.jar.Attributes ; 28 import java.util.jar.JarEntry ; 29 import java.util.jar.JarFile ; 30 import java.util.jar.Manifest ; 31 import java.util.zip.ZipEntry ; 32 33 38 public class JarFileObject extends ZipFileObject 39 { 40 private Attributes attributes; 41 42 final JarFileSystem fs; 43 44 protected JarFileObject(final FileName name, 45 final ZipEntry entry, 46 final JarFileSystem fs, 47 final boolean zipExists) throws FileSystemException 48 { 49 super(name, entry, fs, zipExists); 50 this.fs = fs; 51 52 try 53 { 54 getAttributes(); } 56 catch (IOException e) 57 { 58 throw new FileSystemException(e); 59 } 60 } 61 62 65 Manifest getManifest() throws IOException 66 { 67 if (fs.getZipFile() == null) 68 { 69 return null; 70 } 71 72 return ((JarFile ) fs.getZipFile()).getManifest(); 73 } 74 75 78 Attributes getAttributes() throws IOException 79 { 80 if (attributes == null) 81 { 82 if (entry == null) 83 { 84 attributes = new Attributes (1); 85 } 86 else 87 { 88 attributes = ((JarEntry ) entry).getAttributes(); 89 if (attributes == null) 90 { 91 attributes = new Attributes (1); 92 } 93 } 94 } 95 96 return attributes; 97 } 98 99 102 protected Map doGetAttributes() 103 throws Exception 104 { 105 final Map attrs = new HashMap (); 106 107 final JarFileSystem fs = (JarFileSystem) getFileSystem(); 109 addAll(fs.getAttributes(), attrs); 110 111 addAll(getAttributes(), attrs); 113 114 return attrs; 115 } 116 117 120 private void addAll(final Attributes src, final Map dest) 121 { 122 for (Iterator iterator = src.entrySet().iterator(); iterator.hasNext();) 123 { 124 final Map.Entry entry = (Map.Entry ) iterator.next(); 125 final String name = entry.getKey().toString().toLowerCase(); 126 dest.put(name, entry.getValue()); 127 } 128 } 129 130 133 protected Certificate [] doGetCertificates() 134 { 135 if (entry == null) 136 { 137 return null; 138 } 139 140 return ((JarEntry ) entry).getCertificates(); 141 } 142 } 143 | Popular Tags |