blob: ea2de33636372cff04bd66a6998f4c52f9db430d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.eclipse.jst.jsf.designtime.internal.resources;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import org.eclipse.jst.jsf.common.internal.resource.ContentTypeResolver;
/**
* A JSF Resource that references an entry in the jar. Because of changes in the
* underlying system since it was created, there is no guarantee that the jarURI
* is still valid. Callers should call isAccessible to determine this.
*
* @author cbateman
*
*/
public class JarBasedJSFResource extends JSFResource
{
private final URL _jarURL;
/**
* @param id
* @param jarURL
* @param contentTypeResolver
*/
public JarBasedJSFResource(final ResourceIdentifier id, final URL jarURL, final ContentTypeResolver contentTypeResolver)
{
super(id, contentTypeResolver);
_jarURL = jarURL;
}
/**
* @return the uri pointing in the the jar where the resource lives.
*/
public final URL getJarURL()
{
return _jarURL;
}
/**
* @return the jar entry name for this resource.
*/
protected String getJarEntryName()
{
return String.format("META-INF/resources/%s", getId().toString()); //$NON-NLS-1$
}
/**
* @return true if is accessible.
*/
@Override
public final boolean isAccessible()
{
URLConnection connection = null;
try
{
connection = _jarURL.openConnection();
connection.connect();
if (connection instanceof JarURLConnection)
{
JarFile jarFile = ((JarURLConnection)connection).getJarFile();
ZipEntry entry = jarFile.getEntry(getJarEntryName());
return entry != null;
}
} catch (IOException e)
{
// fall-through
}
return false;
}
}
|