From ec4f37032b54c9b55471f18e120ba5120bf4f29b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 19 Feb 2016 00:20:02 -0800 Subject: [PATCH] GUAC-1378: Read HTML patch resources from extensions into service. --- .../net/basic/extension/ExtensionModule.java | 16 +++- .../basic/extension/PatchResourceService.java | 84 +++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/PatchResourceService.java 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 6296ea5de..deca3c831 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 @@ -101,6 +101,11 @@ public class ExtensionModule extends ServletModule { * Service for adding and retrieving language resources. */ private final LanguageResourceService languageResourceService; + + /** + * Service for adding and retrieving HTML patch resources. + */ + private final PatchResourceService patchResourceService; /** * Returns the classloader that should be used as the parent classloader @@ -140,6 +145,7 @@ public class ExtensionModule extends ServletModule { public ExtensionModule(Environment environment) { this.environment = environment; this.languageResourceService = new LanguageResourceService(environment); + this.patchResourceService = new PatchResourceService(); } /** @@ -307,7 +313,7 @@ public class ExtensionModule extends ServletModule { * A modifiable collection of static JavaScript resources which may * receive new JavaScript resources from extensions. * - * @param cssResources + * @param cssResources * A modifiable collection of static CSS resources which may receive * new CSS resources from extensions. */ @@ -366,6 +372,9 @@ public class ExtensionModule extends ServletModule { // Add any translation resources serveLanguageResources(extension.getTranslationResources()); + // Add all HTML patch resources + patchResourceService.addPatchResources(extension.getHTMLResources().values()); + // Add all static resources under namespace-derived prefix String staticResourcePrefix = "/app/ext/" + extension.getNamespace() + "/"; serveStaticResources(staticResourcePrefix, extension.getStaticResources()); @@ -394,12 +403,13 @@ public class ExtensionModule extends ServletModule { @Override protected void configureServlets() { - // Bind language resource service + // Bind resource services bind(LanguageResourceService.class).toInstance(languageResourceService); + bind(PatchResourceService.class).toInstance(patchResourceService); // Load initial language resources from servlet context languageResourceService.addLanguageResources(getServletContext()); - + // Load authentication provider from guacamole.properties for sake of backwards compatibility Class authProviderProperty = getAuthProviderProperty(); if (authProviderProperty != null) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/PatchResourceService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/PatchResourceService.java new file mode 100644 index 000000000..7c882927b --- /dev/null +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/PatchResourceService.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2016 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.glyptodon.guacamole.net.basic.extension; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.glyptodon.guacamole.net.basic.resource.Resource; + +/** + * Service which provides access to all HTML patches as resources, and allows + * other patch resources to be added. + * + * @author Michael Jumper + */ +public class PatchResourceService { + + /** + * A list of all HTML patch resources currently defined, in the order they + * should be applied. + */ + private final List resources = new ArrayList(); + + /** + * Adds the given HTML patch resource such that it will apply to the + * Guacamole UI. The patch will be applied by the JavaScript side of the + * web application in the order that addPatchResource() is invoked. + * + * @param resource + * The HTML patch resource to add. This resource must have the mimetype + * "text/html". + */ + public void addPatchResource(Resource resource) { + resources.add(resource); + } + + /** + * Adds the given HTML patch resources such that they will apply to the + * Guacamole UI. The patches will be applied by the JavaScript side of the + * web application in the order provided. + * + * @param resources + * The HTML patch resources to add. Each resource must have the + * mimetype "text/html". + */ + public void addPatchResources(Collection resources) { + for (Resource resource : resources) + addPatchResource(resource); + } + + /** + * Returns a list of all HTML patches currently associated with this + * service, in the order they should be applied. The returned list cannot + * be modified. + * + * @return + * A list of all HTML patches currently associated with this service. + */ + public List getPatchResources() { + return Collections.unmodifiableList(resources); + } + +}