
io.dropwizard.bundles.assets.AssetsConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-configurable-assets-bundle Show documentation
Show all versions of dropwizard-configurable-assets-bundle Show documentation
An implementation of an AssetBundle for use in Dropwizard that allows user configuration.
(forked from https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle)Three pull requests are send to the dropwizard-bundles project.
This project becomes obsolete when these have been merged into dropwizard-bundles
The newest version!
package io.dropwizard.bundles.assets;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import java.util.Map;
import javax.validation.constraints.NotNull;
public class AssetsConfiguration {
public static final String SLASH = "/";
@JsonProperty
private Map mappings = Maps.newHashMap();
protected Map mappings() {
return mappings;
}
/**
* Initialize cacheSpec to null so that whatever may be specified by code is able to be
* by configuration. If null the default cache spec of "maximumSize=100" will be used.
*
* @see ConfiguredAssetsBundle#DEFAULT_CACHE_SPEC
*/
@JsonProperty
private String cacheSpec = null;
@NotNull
@JsonProperty
private Map overrides = Maps.newHashMap();
@NotNull
@JsonProperty
private Map mimeTypes = Maps.newHashMap();
private Map resourcePathToUriMappings;
/**
* A series of mappings from resource paths (in the classpath)
* to the uri path that hosts the resource
* @return The resourcePathToUriMappings.
*/
public Map getResourcePathToUriMappings() {
if (resourcePathToUriMappings == null) {
ImmutableMap.Builder mapBuilder = ImmutableMap.builder();
// Ensure that resourcePath and uri ends with a '/'
for (Map.Entry mapping : mappings().entrySet()) {
mapBuilder
.put(ensureEndsWithSlash(mapping.getKey()), ensureEndsWithSlash(mapping.getValue()));
}
resourcePathToUriMappings = mapBuilder.build();
}
return resourcePathToUriMappings;
}
private String ensureEndsWithSlash(String value) {
return value != null ? (value.endsWith(SLASH) ? value : value + SLASH) : SLASH;
}
/**
* The caching specification for how to memoize assets.
*
* @return The cacheSpec.
*/
public String getCacheSpec() {
return cacheSpec;
}
public Iterable> getOverrides() {
return Iterables.unmodifiableIterable(overrides.entrySet());
}
public Iterable> getMimeTypes() {
return Iterables.unmodifiableIterable(mimeTypes.entrySet());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy