use of java.util.HashSet in project jetty.project by eclipse.
the class BalancerServlet method getBalancerNames.
private Set<String> getBalancerNames() throws ServletException {
Set<String> names = new HashSet<>();
for (String initParameterName : Collections.list(getServletConfig().getInitParameterNames())) {
if (!initParameterName.startsWith(BALANCER_MEMBER_PREFIX))
continue;
int endOfNameIndex = initParameterName.lastIndexOf(".");
if (endOfNameIndex <= BALANCER_MEMBER_PREFIX.length())
throw new UnavailableException(initParameterName + " parameter does not provide a balancer member name");
names.add(initParameterName.substring(BALANCER_MEMBER_PREFIX.length(), endOfNameIndex));
}
return names;
}
use of java.util.HashSet in project jetty.project by eclipse.
the class JarResourceTest method testJarFile.
@Test
public void testJarFile() throws Exception {
String s = "jar:" + testResURI + "TestData/test.zip!/subdir/";
Resource r = Resource.newResource(s);
Set<String> entries = new HashSet<>(Arrays.asList(r.list()));
assertEquals(3, entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
assertTrue(entries.contains("subsubdir/"));
File extract = File.createTempFile("extract", null);
if (extract.exists())
extract.delete();
extract.mkdir();
extract.deleteOnExit();
r.copyTo(extract);
Resource e = Resource.newResource(extract.getAbsolutePath());
entries = new HashSet<>(Arrays.asList(e.list()));
assertEquals(3, entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
assertTrue(entries.contains("subsubdir/"));
IO.delete(extract);
s = "jar:" + testResURI + "TestData/test.zip!/subdir/subsubdir/";
r = Resource.newResource(s);
entries = new HashSet<>(Arrays.asList(r.list()));
assertEquals(2, entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
extract = File.createTempFile("extract", null);
if (extract.exists())
extract.delete();
extract.mkdir();
extract.deleteOnExit();
r.copyTo(extract);
e = Resource.newResource(extract.getAbsolutePath());
entries = new HashSet<>(Arrays.asList(e.list()));
assertEquals(2, entries.size());
assertTrue(entries.contains("alphabet"));
assertTrue(entries.contains("numbers"));
IO.delete(extract);
}
use of java.util.HashSet in project jetty.project by eclipse.
the class MetaInfConfiguration method scanForResources.
/**
* Scan for META-INF/resources dir in the given jar.
*
* @param context the context for the scan
* @param target the target resource to scan for
* @param cache the resource cache
* @throws Exception if unable to scan for resources
*/
public void scanForResources(WebAppContext context, Resource target, ConcurrentHashMap<Resource, Resource> cache) throws Exception {
Resource resourcesDir = null;
if (cache != null && cache.containsKey(target)) {
resourcesDir = cache.get(target);
if (resourcesDir == EmptyResource.INSTANCE) {
if (LOG.isDebugEnabled())
LOG.debug(target + " cached as containing no META-INF/resources");
return;
} else if (LOG.isDebugEnabled())
LOG.debug(target + " META-INF/resources found in cache ");
} else {
//not using caches or not in the cache so check for the resources dir
if (LOG.isDebugEnabled())
LOG.debug(target + " META-INF/resources checked");
if (target.isDirectory()) {
//TODO think how to handle an unpacked jar file (eg for osgi)
resourcesDir = target.addPath("/META-INF/resources");
} else {
//Resource represents a packed jar
URI uri = target.getURI();
resourcesDir = Resource.newResource(uriJarPrefix(uri, "!/META-INF/resources"));
}
if (!resourcesDir.exists() || !resourcesDir.isDirectory()) {
resourcesDir.close();
resourcesDir = EmptyResource.INSTANCE;
}
if (cache != null) {
Resource old = cache.putIfAbsent(target, resourcesDir);
if (old != null)
resourcesDir = old;
else if (LOG.isDebugEnabled())
LOG.debug(target + " META-INF/resources cache updated");
}
if (resourcesDir == EmptyResource.INSTANCE) {
return;
}
}
//add it to the meta inf resources for this context
Set<Resource> dirs = (Set<Resource>) context.getAttribute(METAINF_RESOURCES);
if (dirs == null) {
dirs = new HashSet<Resource>();
context.setAttribute(METAINF_RESOURCES, dirs);
}
if (LOG.isDebugEnabled())
LOG.debug(resourcesDir + " added to context");
dirs.add(resourcesDir);
}
use of java.util.HashSet in project jetty.project by eclipse.
the class MetaInfConfiguration method getTlds.
/**
* Find all .tld files in all subdirs of the given dir.
*
* @param dir the directory to scan
* @return the list of tlds found
* @throws IOException if unable to scan the directory
*/
public Collection<URL> getTlds(File dir) throws IOException {
if (dir == null || !dir.isDirectory())
return Collections.emptySet();
HashSet<URL> tlds = new HashSet<URL>();
File[] files = dir.listFiles();
if (files != null) {
for (File f : files) {
if (f.isDirectory())
tlds.addAll(getTlds(f));
else {
String name = f.getCanonicalPath();
if (name.contains("META-INF") && name.endsWith(".tld"))
tlds.add(f.toURI().toURL());
}
}
}
return tlds;
}
use of java.util.HashSet in project jetty.project by eclipse.
the class MetaInfConfiguration method getTlds.
/**
* Find all .tld files in the given jar.
*
* @param uri the uri to jar file
* @return the collection of tlds as url references
* @throws IOException if unable to scan the jar file
*/
public Collection<URL> getTlds(URI uri) throws IOException {
HashSet<URL> tlds = new HashSet<URL>();
String jarUri = uriJarPrefix(uri, "!/");
URL url = new URL(jarUri);
JarURLConnection jarConn = (JarURLConnection) url.openConnection();
jarConn.setUseCaches(Resource.getDefaultUseCaches());
JarFile jarFile = jarConn.getJarFile();
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
String name = e.getName();
if (name.startsWith("META-INF") && name.endsWith(".tld")) {
tlds.add(new URL(jarUri + name));
}
}
if (!Resource.getDefaultUseCaches())
jarFile.close();
return tlds;
}
Aggregations