uk.ac.ceh.dynamo.providers.GridMapMapProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamo-mapping Show documentation
Show all versions of dynamo-mapping Show documentation
A Spring MVC plugin for creating dynamic MapServer maps with freemarker templates
package uk.ac.ceh.dynamo.providers;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import uk.ac.ceh.dynamo.GridMapMethod;
import uk.ac.ceh.dynamo.Provides;
/**
*
* @author Chris Johnson
*/
public class GridMapMapProvider {
private static final Map FORMATS;
static {
FORMATS = new HashMap<>();
FORMATS.put("png", "image/png");
FORMATS.put("gif", "image/gif");
FORMATS.put("jpeg", "image/jpeg");
}
@Provides(GridMapMethod.MAP)
public Map processRequestParameters(HttpServletRequest request) {
Map toReturn = new HashMap<>();
toReturn.put("SERVICE", new String[]{"WMS"});
toReturn.put("VERSION", new String[]{"1.1.1"});
toReturn.put("REQUEST", new String[]{"GetMap"});
toReturn.put("STYLES", new String[]{""});
toReturn.put("TRANSPARENT", new String[]{"true"});
toReturn.put("FORMAT", new String[]{ checkAndGetValue(FORMATS, getValue(request.getParameterMap(), "format", "png")) });
return toReturn;
}
private static String checkAndGetValue(Map map, String toGet) {
if(!map.containsKey(toGet)) {
throw new IllegalArgumentException("I don't understand " + toGet +
" valid values are " + map.keySet());
}
return map.get(toGet);
}
private static String getValue(Map query, String toGet, String defaultVal) {
return (query.containsKey(toGet)) ? query.get(toGet)[0] : defaultVal;
}
}