1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.jar;
18
19 import java.io.IOException;
20 import java.security.cert.Certificate;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Map.Entry;
24 import java.util.jar.Attributes;
25 import java.util.jar.JarEntry;
26 import java.util.jar.JarFile;
27 import java.util.jar.Manifest;
28 import java.util.zip.ZipEntry;
29
30 import org.apache.commons.vfs2.FileSystemException;
31 import org.apache.commons.vfs2.provider.AbstractFileName;
32 import org.apache.commons.vfs2.provider.zip.ZipFileObject;
33
34
35
36
37 public class JarFileObject extends ZipFileObject {
38
39 private final JarFileSystem fs;
40
41 private Attributes attributes;
42
43 protected JarFileObject(final AbstractFileName name, final ZipEntry entry, final JarFileSystem fs,
44 final boolean zipExists) throws FileSystemException {
45 super(name, entry, fs, zipExists);
46 if (entry != null) {
47
48
49
50 ((JarEntry) entry).getCertificates();
51 }
52 this.fs = fs;
53
54 try {
55 getAttributes();
56 } catch (final IOException e) {
57 throw new FileSystemException(e);
58 }
59 }
60
61
62
63
64 Manifest getManifest() throws IOException {
65 if (fs.getZipFile() == null) {
66 return null;
67 }
68
69 return ((JarFile) fs.getZipFile()).getManifest();
70 }
71
72
73
74
75 Attributes getAttributes() throws IOException {
76 if (attributes == null) {
77 if (entry == null) {
78 attributes = new Attributes(1);
79 } else {
80 attributes = ((JarEntry) entry).getAttributes();
81 if (attributes == null) {
82 attributes = new Attributes(1);
83 }
84 }
85 }
86
87 return attributes;
88 }
89
90
91
92
93 @Override
94 protected Map<String, Object> doGetAttributes() throws Exception {
95 final Map<String, Object> attrs = new HashMap<>();
96
97
98 final JarFileSystem../../../../../org/apache/commons/vfs2/provider/jar/JarFileSystem.html#JarFileSystem">JarFileSystem fs = (JarFileSystem) getFileSystem();
99 addAll(fs.getAttributes(), attrs);
100
101
102 addAll(getAttributes(), attrs);
103
104 return attrs;
105 }
106
107
108
109
110 private void addAll(final Attributes src, final Map<String, Object> dest) {
111 for (final Entry<Object, Object> entry : src.entrySet()) {
112
113 final String name = entry.getKey().toString();
114 dest.put(name, entry.getValue());
115 }
116 }
117
118
119
120
121 @Override
122 protected Certificate[] doGetCertificates() {
123 if (entry == null) {
124 return null;
125 }
126
127 return ((JarEntry) entry).getCertificates();
128 }
129 }