/*
- * Sone - RequestChangeFilter.java - Copyright © 2010 David Roden
+ * Sone - RequestChangeFilter.java - Copyright © 2010–2013 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
import java.util.Map;
import java.util.Map.Entry;
-import net.pterodactylus.sone.web.page.Page.Request;
-import net.pterodactylus.util.template.DataProvider;
+import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
/**
- * This filter expects a {@link Request} 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”.
+ * 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 new value is stored in “value”.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
- Request request = (Request) data;
- String name = parameters.get("name");
- String nameKey = parameters.get("nameKey");
- if (nameKey != null) {
- name = String.valueOf(dataProvider.get(nameKey));
- }
- String key = parameters.get("key");
- String value = null;
- if (key != null) {
- value = String.valueOf(dataProvider.get(key));
- }
- if (value == null) {
- value = parameters.get("value");
- }
- if (value == null) {
- return request.getUri();
- }
+ 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();
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) {