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 a186b7378..6a1462c16 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 @@ -89,6 +89,19 @@ public class Extension { */ private final Map cssResources; + /** + * Map of all translation resources defined within the extension, where + * each key is the path to that resource within the extension. + */ + private final Map translationResources; + + /** + * Map of all resources defined within the extension which are not already + * associated as JavaScript, CSS, or translation resources, where each key + * is the path to that resource within the extension. + */ + private final Map staticResources; + /** * The collection of all AuthenticationProvider classes defined within the * extension. @@ -127,6 +140,43 @@ public class Extension { } + /** + * Returns a new map of all resources corresponding to the map of resource + * paths provided. Each resource will be associated with the mimetype + * stored in the given map using its path as the key. + * + * @param resourceTypes + * A map of all paths to their corresponding mimetypes. + * + * @return + * 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 Map getClassPathResources(Map resourceTypes) { + + // If no paths are provided, just return an empty map + if (resourceTypes == null) + return Collections.emptyMap(); + + // Add classpath resource for each path/mimetype pair provided + Map resources = new HashMap(resourceTypes.size()); + for (Map.Entry resource : resourceTypes.entrySet()) { + + // Get path and mimetype from entry + String path = resource.getKey(); + String mimetype = resource.getValue(); + + // Store as path/resource pair + resources.put(path, new ClassPathResource(classLoader, mimetype, path)); + + } + + // Callers should not rely on modifying the result + return Collections.unmodifiableMap(resources); + + } + /** * Retrieve the AuthenticationProvider subclass having the given name. If * the class having the given name does not exist or isn't actually a @@ -290,6 +340,8 @@ public class Extension { // Define static resources cssResources = getClassPathResources("text/css", manifest.getCSSPaths()); javaScriptResources = getClassPathResources("text/javascript", manifest.getJavaScriptPaths()); + translationResources = getClassPathResources("application/json", manifest.getTranslationPaths()); + staticResources = getClassPathResources(manifest.getResourceTypes()); // Define authentication providers authenticationProviderClasses = getAuthenticationProviderClasses(manifest.getAuthProviders()); @@ -356,6 +408,33 @@ public class Extension { return cssResources; } + /** + * Returns a map of all declared translation resources associated with this + * extension, where the key of each entry in the map is the path to that + * resource within the extension .jar. Translation resources are declared + * within the extension manifest. + * + * @return + * All declared translation resources associated with this extension. + */ + public Map getTranslationResources() { + return translationResources; + } + + /** + * Returns a map of all declared resources associated with this extension, + * where these resources are not already associated as JavaScript, CSS, or + * translation resources. The key of each entry in the map is the path to + * that resource within the extension .jar. Static resources are declared + * within the extension manifest. + * + * @return + * All declared static resources associated with this extension. + */ + public Map getStaticResources() { + return staticResources; + } + /** * Returns all declared authentication providers classes associated with * this extension. Authentication providers are declared within the diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionManifest.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionManifest.java index 093af3b0d..9b2331af5 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionManifest.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/ExtensionManifest.java @@ -23,6 +23,7 @@ package org.glyptodon.guacamole.net.basic.extension; import java.util.Collection; +import java.util.Map; import org.codehaus.jackson.annotate.JsonProperty; /** @@ -66,6 +67,19 @@ public class ExtensionManifest { */ private Collection cssPaths; + /** + * The paths of all translation JSON files within this extension, if any. + */ + private Collection translationPaths; + + /** + * The mimetypes of all resources within this extension which are not + * already declared as JavaScript, CSS, or translation resources, if any. + * The key of each entry is the resource path, while the value is the + * corresponding mimetype. + */ + private Map resourceTypes; + /** * The names of all authentication provider classes within this extension, * if any. @@ -206,6 +220,70 @@ public class ExtensionManifest { this.cssPaths = cssPaths; } + /** + * Returns the paths to all translation resources within the extension. + * These paths are defined within the manifest by the "translations" + * property as an array of strings, where each string is a path relative to + * the root of the extension .jar. + * + * @return + * A collection of paths to all translation resources within the + * extension. + */ + @JsonProperty("translations") + public Collection getTranslationPaths() { + return translationPaths; + } + + /** + * Sets the paths to all translation resources within the extension. These + * paths are defined within the manifest by the "translations" property as + * an array of strings, where each string is a path relative to the root of + * the extension .jar. + * + * @param translationPaths + * A collection of paths to all translation resources within the + * extension. + */ + @JsonProperty("translations") + public void setTranslationPaths(Collection translationPaths) { + this.translationPaths = translationPaths; + } + + /** + * Returns a map of all resources to their corresponding mimetypes, for all + * resources not already declared as JavaScript, CSS, or translation + * resources. These paths and corresponding types are defined within the + * manifest by the "resources" property as an object, where each property + * name is a path relative to the root of the extension .jar, and each + * value is a mimetype. + * + * @return + * A map of all resources within the extension to their corresponding + * mimetypes. + */ + @JsonProperty("resources") + public Map getResourceTypes() { + return resourceTypes; + } + + /** + * Sets the map of all resources to their corresponding mimetypes, for all + * resources not already declared as JavaScript, CSS, or translation + * resources. These paths and corresponding types are defined within the + * manifest by the "resources" property as an object, where each property + * name is a path relative to the root of the extension .jar, and each + * value is a mimetype. + * + * @param resourceTypes + * A map of all resources within the extension to their corresponding + * mimetypes. + */ + @JsonProperty("resources") + public void setResourceTypes(Map resourceTypes) { + this.resourceTypes = resourceTypes; + } + /** * Returns the classnames of all authentication provider classes within the * extension. These classnames are defined within the manifest by the