mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1378: Read HTML patch resources from extensions into service.
This commit is contained in:
@@ -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<AuthenticationProvider> authProviderProperty = getAuthProviderProperty();
|
||||
if (authProviderProperty != null)
|
||||
|
@@ -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<Resource> resources = new ArrayList<Resource>();
|
||||
|
||||
/**
|
||||
* 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<Resource> 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<Resource> getPatchResources() {
|
||||
return Collections.unmodifiableList(resources);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user