mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUAC-587: Add support for translations and arbitrary static resources to the extension manifest.
This commit is contained in:
@@ -89,6 +89,19 @@ public class Extension {
|
||||
*/
|
||||
private final Map<String, Resource> 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<String, Resource> 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<String, Resource> 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<String, Resource> getClassPathResources(Map<String, String> resourceTypes) {
|
||||
|
||||
// If no paths are provided, just return an empty map
|
||||
if (resourceTypes == null)
|
||||
return Collections.<String, Resource>emptyMap();
|
||||
|
||||
// Add classpath resource for each path/mimetype pair provided
|
||||
Map<String, Resource> resources = new HashMap<String, Resource>(resourceTypes.size());
|
||||
for (Map.Entry<String, String> 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<String, Resource> 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<String, Resource> getStaticResources() {
|
||||
return staticResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all declared authentication providers classes associated with
|
||||
* this extension. Authentication providers are declared within the
|
||||
|
@@ -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<String> cssPaths;
|
||||
|
||||
/**
|
||||
* The paths of all translation JSON files within this extension, if any.
|
||||
*/
|
||||
private Collection<String> 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<String, String> 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<String> 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<String> 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<String, String> 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<String, String> resourceTypes) {
|
||||
this.resourceTypes = resourceTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the classnames of all authentication provider classes within the
|
||||
* extension. These classnames are defined within the manifest by the
|
||||
|
Reference in New Issue
Block a user