implement resource manager api

This commit is contained in:
Sebastian Sdorra
2012-02-03 19:28:48 +01:00
parent 6baaefe824
commit 2f7800cde7
7 changed files with 1025 additions and 0 deletions

View File

@@ -69,6 +69,9 @@ import sonia.scm.repository.RepositoryBrowserUtil;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryProvider;
import sonia.scm.repository.xml.XmlRepositoryManager;
import sonia.scm.resources.DefaultResourceManager;
import sonia.scm.resources.DevelopmentResourceManager;
import sonia.scm.resources.ResourceManager;
import sonia.scm.security.CipherHandler;
import sonia.scm.security.CipherUtil;
import sonia.scm.security.EncryptionHandler;
@@ -259,6 +262,16 @@ public class ScmServletModule extends ServletModule
// bind httpclient
bind(HttpClient.class).to(URLHttpClient.class);
// bind resourcemanager
if (context.getStage() == Stage.DEVELOPMENT)
{
bind(ResourceManager.class).to(DevelopmentResourceManager.class);
}
else
{
bind(ResourceManager.class).to(DefaultResourceManager.class);
}
// bind url provider staff
bind(UrlProvider.class).annotatedWith(
Names.named(UrlProviderFactory.TYPE_RESTAPI_JSON)).toProvider(

View File

@@ -0,0 +1,215 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.boot.BootstrapUtil;
import sonia.scm.plugin.ScriptResourceServlet;
import sonia.scm.util.IOUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
public abstract class AbstractResource implements Resource
{
/**
* the logger for AbstractResource
*/
private static final Logger logger =
LoggerFactory.getLogger(AbstractResource.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param servletContext
* @param resources
* @param resourceHandlers
*/
public AbstractResource(ServletContext servletContext,
List<String> resources,
List<ResourceHandler> resourceHandlers)
{
this.servletContext = servletContext;
this.resources = resources;
this.resourceHandlers = resourceHandlers;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param stream
*
* @throws IOException
*/
protected void appendResources(OutputStream stream) throws IOException
{
if (Util.isNotEmpty(resources))
{
for (String resource : resources)
{
appendResource(stream, resource);
}
}
if (Util.isNotEmpty(resourceHandlers))
{
Collections.sort(resourceHandlers, new ResourceHandlerComparator());
for (ResourceHandler resourceHandler : resourceHandlers)
{
if (resourceHandler.getType() == ResourceType.SCRIPT)
{
appendResource(resourceHandler.getResource(), stream);
}
}
}
}
/**
* Method description
*
*
* @param stream
* @param resource
*
* @throws IOException
*/
private void appendResource(OutputStream stream, String resource)
throws IOException
{
InputStream input = getResourceAsStream(resource);
if (input != null)
{
appendResource(input, stream);
}
else if (logger.isWarnEnabled())
{
logger.warn("could not find resource {}", resource);
}
}
/**
* Method description
*
*
* @param input
* @param stream
*
* @throws IOException
*/
private void appendResource(InputStream input, OutputStream stream)
throws IOException
{
if (input != null)
{
try
{
IOUtil.copy(input, stream);
}
finally
{
IOUtil.close(input);
}
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param resource
*
* @return
*/
private InputStream getResourceAsStream(String resource)
{
InputStream input = null;
ClassLoader classLoader = BootstrapUtil.getClassLoader(servletContext);
if (classLoader != null)
{
String classLoaderResource = resource;
if (classLoaderResource.startsWith("/"))
{
classLoaderResource = classLoaderResource.substring(1);
}
input = classLoader.getResourceAsStream(classLoaderResource);
}
if (input == null)
{
input = ScriptResourceServlet.class.getResourceAsStream(resource);
}
return input;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected List<ResourceHandler> resourceHandlers;
/** Field description */
protected List<String> resources;
/** Field description */
private ServletContext servletContext;
}

View File

@@ -0,0 +1,309 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginResources;
//~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
public abstract class AbstractResourceManager implements ResourceManager
{
/**
* Constructs ...
*
*
*
* @param servletContext
* @param pluginLoader
* @param resourceHandlers
*/
public AbstractResourceManager(ServletContext servletContext,
PluginLoader pluginLoader,
Set<ResourceHandler> resourceHandlers)
{
this.servletContext = servletContext;
this.pluginLoader = pluginLoader;
this.resourceHandlers = resourceHandlers;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resourceMap
*/
protected abstract void collectResources(Map<ResourceKey,
Resource> resourceMap);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param type
* @param name
*
* @return
*/
@Override
public Resource getResource(ResourceType type, String name)
{
return resourceMap.get(new ResourceKey(name, type));
}
/**
* Method description
*
*
* @param type
*
* @return
*/
@Override
public List<Resource> getResources(ResourceType type)
{
List<Resource> resources = new ArrayList<Resource>();
for (Entry<ResourceKey, Resource> e : resourceMap.entrySet())
{
if (e.getKey().getType() == type)
{
resources.add(e.getValue());
}
}
return resources;
}
/**
* Method description
*
*
* @return
*/
protected List<String> getScriptResources()
{
List<String> resources = new ArrayList<String>();
Collection<Plugin> plugins = pluginLoader.getInstalledPlugins();
if (plugins != null)
{
for (Plugin plugin : plugins)
{
processPlugin(resources, plugin);
}
}
return resources;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resources
* @param plugin
*/
private void processPlugin(List<String> resources, Plugin plugin)
{
PluginResources pluginResources = plugin.getResources();
if (pluginResources != null)
{
Set<String> scriptResources = pluginResources.getScriptResources();
if (scriptResources != null)
{
resources.addAll(scriptResources);
}
}
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here..., 12/02/03
* @author Enter your name here...
*/
protected static class ResourceKey
{
/**
* Constructs ...
*
*
* @param name
* @param type
*/
public ResourceKey(String name, ResourceType type)
{
this.name = name;
this.type = type;
}
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final ResourceKey other = (ResourceKey) obj;
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if (this.type != other.type)
{
return false;
}
return true;
}
/**
* Method description
*
*
* @return
*/
@Override
public int hashCode()
{
int hash = 7;
hash = 53 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 53 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
return hash;
}
//~--- get methods --------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
public ResourceType getType()
{
return type;
}
//~--- fields -------------------------------------------------------------
/** Field description */
private String name;
/** Field description */
private ResourceType type;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected PluginLoader pluginLoader;
/** Field description */
protected Set<ResourceHandler> resourceHandlers;
/** Field description */
protected Map<ResourceKey, Resource> resourceMap = new HashMap<ResourceKey,
Resource>();
/** Field description */
protected ServletContext servletContext;
}

View File

@@ -0,0 +1,141 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.ChecksumUtil;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
public class DefaultResource extends AbstractResource
{
/**
* Constructs ...
*
*
* @param servletContext
* @param resources
* @param resourceHandlers
* @param type
*
* @throws IOException
*/
public DefaultResource(ServletContext servletContext, List<String> resources,
List<ResourceHandler> resourceHandlers,
ResourceType type)
throws IOException
{
super(servletContext, resources, resourceHandlers);
this.type = type;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
appendResources(baos);
this.content = baos.toByteArray();
this.name = ChecksumUtil.createChecksum(this.content);
}
finally
{
IOUtil.close(baos);
}
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param output
*
* @throws IOException
*/
@Override
public void copyTo(OutputStream output) throws IOException
{
output.write(content);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
@Override
public ResourceType getType()
{
return type;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private byte[] content;
/** Field description */
private String name;
/** Field description */
private ResourceType type;
}

View File

@@ -0,0 +1,112 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.plugin.PluginLoader;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
public class DefaultResourceManager extends AbstractResourceManager
{
/**
* the logger for DefaultResourceManager
*/
private static final Logger logger =
LoggerFactory.getLogger(DefaultResourceManager.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param servletContext
* @param pluginLoader
* @param resourceHandlers
*/
@Inject
public DefaultResourceManager(ServletContext servletContext,
PluginLoader pluginLoader,
Set<ResourceHandler> resourceHandlers)
{
super(servletContext, pluginLoader, resourceHandlers);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resourceMap
*/
@Override
protected void collectResources(Map<ResourceKey, Resource> resourceMap)
{
List<String> resources = getScriptResources();
try
{
Resource resource = new DefaultResource(servletContext, resources,
new ArrayList<ResourceHandler>(resourceHandlers),
ResourceType.SCRIPT);
resourceMap.put(new ResourceKey(resource.getName(), ResourceType.SCRIPT),
resource);
}
catch (IOException ex)
{
logger.error("could not collect resources", ex);
}
}
}

View File

@@ -0,0 +1,120 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.resources;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
public class DevelopmentResource extends AbstractResource
{
/**
* Constructs ...
*
*
*
* @param servletContext
* @param resources
* @param resourceHandlers
* @param name
* @param type
*/
public DevelopmentResource(ServletContext servletContext,
List<String> resources,
List<ResourceHandler> resourceHandlers,
String name, ResourceType type)
{
super(servletContext, resources, resourceHandlers);
this.name = name;
this.type = type;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param output
*
* @throws IOException
*/
@Override
public void copyTo(OutputStream output) throws IOException
{
appendResources(output);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getName()
{
return name;
}
/**
* Method description
*
*
* @return
*/
@Override
public ResourceType getType()
{
return type;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String name;
/** Field description */
private ResourceType type;
}

View File

@@ -0,0 +1,115 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.plugin.PluginLoader;
//~--- JDK imports ------------------------------------------------------------
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
public class DevelopmentResourceManager extends AbstractResourceManager
{
/** Field description */
public static final String PREFIX_HANDLER = "handler/";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param servletContext
* @param pluginLoader
* @param resourceHandlers
*/
@Inject
public DevelopmentResourceManager(ServletContext servletContext,
PluginLoader pluginLoader,
Set<ResourceHandler> resourceHandlers)
{
super(servletContext, pluginLoader, resourceHandlers);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param resourceMap
*/
@Override
protected void collectResources(Map<ResourceKey, Resource> resourceMap)
{
List<String> scripts = getScriptResources();
for (String script : scripts)
{
resourceMap.put(new ResourceKey(script, ResourceType.SCRIPT),
new DevelopmentResource(servletContext,
Arrays.asList(script), Collections.EMPTY_LIST, script,
ResourceType.SCRIPT));
}
for (ResourceHandler handler : resourceHandlers)
{
String name = handler.getName();
if (name.startsWith("/"))
{
name = name.substring(1);
}
name = PREFIX_HANDLER.concat(name);
resourceMap.put(new ResourceKey(name, ResourceType.SCRIPT),
new DevelopmentResource(servletContext,
Collections.EMPTY_LIST, Arrays.asList(handler), name,
ResourceType.SCRIPT));
}
}
}