* @throws Exception
*/
private static GetMapRequest replaceRequestParams(GetMapRequest theRequest, String param,
String value) throws Exception {
// look for the GetMapRequest reader
GetMapKvpRequestReader kvpRequestReader = (GetMapKvpRequestReader) Dispatcher.findKvpRequestReader(GetMapRequest.class);
// clone the original request object using the reflection
GetMapRequest request = (GetMapRequest) BeanUtils.cloneBean(theRequest);
// looking for composite parameters like env:color or viewparams:param ...
Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>(theRequest.getRawKvp()));
if (param.contains(":")) {
// going to replace composite param values for each frame in the KVP map
String compositeParamKey = param.split(":")[0].toUpperCase();
String simpleParamKey = param.split(":")[1].toUpperCase();
List<String> kvps = null;
if (rawKvp.get(compositeParamKey) != null) {
kvps = KvpUtils.escapedTokens(rawKvp.get(compositeParamKey), ';');
// purge old value
Iterator<String> it = kvps.iterator();
while (it.hasNext()) {
String k = it.next().toUpperCase();
if (k.toUpperCase().startsWith(simpleParamKey)) {
it.remove();
}
}
} else {
kvps = new ArrayList<String>();
}
// insert the right one
kvps.add(simpleParamKey + ":" + value);
// merge back to the composite value
rawKvp.remove(compositeParamKey);
rawKvp.put(compositeParamKey, mergeParams(kvps));
} else {
// just a simple plain request parameter... replacing it on the KVP map
// purge old value
if (rawKvp.containsKey(param)) {
rawKvp.remove(param);
}
// insert the frame one
rawKvp.put(param, value);
}
// setting up the right RAW-KVP map for the single frame request
request.setRawKvp(rawKvp);
// building the request KVP map using the reflection
HashMap<String, String> kvp = new HashMap<String, String>(rawKvp);
KvpUtils.parse(kvp);
// finally building the request
request = kvpRequestReader.read(new GetMapRequest(), kvp, rawKvp);
// add the param value for text decorations to use
request.getEnv().put("avalue", value);
return request;