/*
- * Sone - RequestChangeFilter.java - Copyright © 2010 David Roden
+ * Sone - RequestChangeFilter.java - Copyright © 2010–2020 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* This filter expects a {@link FreenetRequest} as input and outputs a
* {@link URI} that is modified by the parameters. The name of the parameter is
- * handed in as “name”, the value may either be stored in “value”, or in a
- * template variable whose key is stored in “key”.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ * handed in as “name”, the new value is stored in “value”.
*/
public class RequestChangeFilter implements Filter {
* {@inheritDoc}
*/
@Override
- public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, Object> parameters) {
FreenetRequest request = (FreenetRequest) data;
- String name = parameters.get("name");
- String nameKey = parameters.get("nameKey");
- if (nameKey != null) {
- name = String.valueOf(templateContext.get(nameKey));
- }
- String key = parameters.get("key");
- String value = null;
- if (key != null) {
- value = String.valueOf(templateContext.get(key));
- }
- if (value == null) {
- value = parameters.get("value");
- }
- if (value == null) {
- return request.getUri();
- }
+ String name = String.valueOf(parameters.get("name"));
+ String value = String.valueOf(parameters.get("value"));
- Map<String, String> values = new HashMap<String, String>();
+ Map<String, String> values = new HashMap<>();
Collection<String> parameterNames = request.getHttpRequest().getParameterNames();
for (String parameterName : parameterNames) {
values.put(parameterName, request.getHttpRequest().getParam(parameterName));
if (questionMark == -1) {
questionMark = oldUri.length();
}
- URI u = new URI(oldUri.substring(0, questionMark) + query.toString());
- return u;
+ return new URI(oldUri.substring(0, questionMark) + query.toString());
} catch (UnsupportedEncodingException uee1) {
/* UTF-8 not supported? I don’t think so. */
} catch (URISyntaxException use1) {