From ee17c99b2335c8cbfb7dfcfed7680a9ae1ec5d19 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 17 May 2015 14:16:47 -0700 Subject: [PATCH] GUAC-587: Preserve resource path information within the extension class. --- .../net/basic/extension/Extension.java | 50 +++++++++++-------- .../net/basic/extension/ExtensionModule.java | 4 +- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/Extension.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/Extension.java index a7891cb4d..a186b7378 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/Extension.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/Extension.java @@ -33,6 +33,8 @@ import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; @@ -76,14 +78,16 @@ public class Extension { private final ClassLoader classLoader; /** - * The collection of all JavaScript resources defined within the extension. + * Map of all JavaScript resources defined within the extension, where each + * key is the path to that resource within the extension. */ - private final Collection javaScriptResources; + private final Map javaScriptResources; /** - * The collection of all CSS resources defined within the extension. + * Map of all CSS resources defined within the extension, where each key is + * the path to that resource within the extension. */ - private final Collection cssResources; + private final Map cssResources; /** * The collection of all AuthenticationProvider classes defined within the @@ -92,9 +96,9 @@ public class Extension { private final Collection> authenticationProviderClasses; /** - * Returns a new collection of resources corresponding to the collection of + * Returns a new map of all resources corresponding to the collection of * paths provided. Each resource will be associated with the given - * mimetype. + * mimetype, and stored in the map using its path as the key. * * @param mimetype * The mimetype to associate with each resource. @@ -103,22 +107,23 @@ public class Extension { * The paths corresponding to the resources desired. * * @return - * A new, unmodifiable collection of resources corresponding to the - * collection of paths provided. + * A new, unmodifiable map of resources corresponding to the + * collection of paths provided, where the key of each entry in the + * map is the path for the resource stored in that entry. */ - private Collection getClassPathResources(String mimetype, Collection paths) { + private Map getClassPathResources(String mimetype, Collection paths) { - // If no paths are provided, just return an empty list + // If no paths are provided, just return an empty map if (paths == null) - return Collections.emptyList(); + return Collections.emptyMap(); // Add classpath resource for each path provided - Collection resources = new ArrayList(paths.size()); + Map resources = new HashMap(paths.size()); for (String path : paths) - resources.add(new ClassPathResource(classLoader, mimetype, path)); + resources.put(path, new ClassPathResource(classLoader, mimetype, path)); // Callers should not rely on modifying the result - return Collections.unmodifiableCollection(resources); + return Collections.unmodifiableMap(resources); } @@ -326,25 +331,28 @@ public class Extension { } /** - * Returns all declared JavaScript resources associated with this - * extension. JavaScript resources are declared within the extension - * manifest. + * Returns a map of all declared JavaScript resources associated with this + * extension, where the key of each entry in the map is the path to that + * resource within the extension .jar. JavaScript resources are declared + * within the extension manifest. * * @return * All declared JavaScript resources associated with this extension. */ - public Collection getJavaScriptResources() { + public Map getJavaScriptResources() { return javaScriptResources; } /** - * Returns all declared CSS resources associated with this extension. CSS - * resources are declared within the extension manifest. + * Returns a map of all declared CSS resources associated with this + * extension, where the key of each entry in the map is the path to that + * resource within the extension .jar. CSS resources are declared within + * the extension manifest. * * @return * All declared CSS resources associated with this extension. */ - public Collection getCSSResources() { + public Map getCSSResources() { return cssResources; } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionModule.java index adbe6a0e2..2f16f1477 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionModule.java @@ -270,8 +270,8 @@ public class ExtensionModule extends ServletModule { } // Add any JavaScript / CSS resources - javaScriptResources.addAll(extension.getJavaScriptResources()); - cssResources.addAll(extension.getCSSResources()); + javaScriptResources.addAll(extension.getJavaScriptResources().values()); + cssResources.addAll(extension.getCSSResources().values()); // Attempt to load all authentication providers Collection> authenticationProviders = extension.getAuthenticationProviderClasses();