/**
* {@inheritDoc}
*/
@Override
public Object format(TemplateContext templateContext, Object data, Map<String, Object> parameters) {
FreenetRequest request = (FreenetRequest) data;
String name = String.valueOf(parameters.get("name"));
String value = String.valueOf(parameters.get("value"));
Map<String, String> values = new HashMap<String, String>();
Collection<String> parameterNames = request.getHttpRequest().getParameterNames();
for (String parameterName : parameterNames) {
values.put(parameterName, request.getHttpRequest().getParam(parameterName));
}
values.put(name, value);
StringBuilder query = new StringBuilder();
try {
for (Entry<String, String> parameterEntry : values.entrySet()) {
query.append((query.length() == 0) ? '?' : '&');
query.append(URLEncoder.encode(parameterEntry.getKey(), "UTF-8"));
query.append('=');
query.append(URLEncoder.encode(parameterEntry.getValue(), "UTF-8"));
}
String oldUri = request.getUri().toString();
int questionMark = oldUri.indexOf('?');
if (questionMark == -1) {
questionMark = oldUri.length();
}
URI u = new URI(oldUri.substring(0, questionMark) + query.toString());