1
17 package org.apache.catalina.webresources;
18
19 import java.io.File;
20 import java.io.InputStream;
21 import java.net.MalformedURLException;
22 import java.net.URL;
23 import java.security.cert.Certificate;
24 import java.util.jar.Manifest;
25
26 import org.apache.catalina.WebResourceRoot;
27 import org.apache.juli.logging.Log;
28 import org.apache.juli.logging.LogFactory;
29
30 public class JarResourceRoot extends AbstractResource {
31
32 private static final Log log = LogFactory.getLog(JarResourceRoot.class);
33
34 private final File base;
35 private final String baseUrl;
36 private final String name;
37
38 public JarResourceRoot(WebResourceRoot root, File base, String baseUrl,
39 String webAppPath) {
40 super(root, webAppPath);
41
42 if (!webAppPath.endsWith("/")) {
43 throw new IllegalArgumentException(sm.getString(
44 "jarResourceRoot.invalidWebAppPath", webAppPath));
45 }
46 this.base = base;
47 this.baseUrl = "jar:" + baseUrl;
48
49
50 String resourceName = webAppPath.substring(0, webAppPath.length() - 1);
51 int i = resourceName.lastIndexOf('/');
52 if (i > -1) {
53 resourceName = resourceName.substring(i + 1);
54 }
55 name = resourceName;
56 }
57
58 @Override
59 public long getLastModified() {
60 return base.lastModified();
61 }
62
63 @Override
64 public boolean exists() {
65 return true;
66 }
67
68 @Override
69 public boolean isVirtual() {
70 return false;
71 }
72
73 @Override
74 public boolean isDirectory() {
75 return true;
76 }
77
78 @Override
79 public boolean isFile() {
80 return false;
81 }
82
83 @Override
84 public boolean delete() {
85 return false;
86 }
87
88 @Override
89 public String getName() {
90 return name;
91 }
92
93 @Override
94 public long getContentLength() {
95 return -1;
96 }
97
98 @Override
99 public String getCanonicalPath() {
100 return null;
101 }
102
103 @Override
104 public boolean canRead() {
105 return true;
106 }
107
108 @Override
109 protected InputStream doGetInputStream() {
110 return null;
111 }
112
113 @Override
114 public byte[] getContent() {
115 return null;
116 }
117
118 @Override
119 public long getCreation() {
120 return base.lastModified();
121 }
122
123 @Override
124 public URL getURL() {
125 String url = baseUrl + "!/";
126 try {
127 return new URL(url);
128 } catch (MalformedURLException e) {
129 if (log.isDebugEnabled()) {
130 log.debug(sm.getString("fileResource.getUrlFail", url), e);
131 }
132 return null;
133 }
134 }
135
136 @Override
137 public URL getCodeBase() {
138 try {
139 return new URL(baseUrl);
140 } catch (MalformedURLException e) {
141 if (getLog().isDebugEnabled()) {
142 getLog().debug(sm.getString("fileResource.getUrlFail", baseUrl), e);
143 }
144 return null;
145 }
146 }
147 @Override
148 protected Log getLog() {
149 return log;
150 }
151
152 @Override
153 public Certificate[] getCertificates() {
154 return null;
155 }
156
157 @Override
158 public Manifest getManifest() {
159 return null;
160 }
161 }
162