Commit 0843657a authored by Vincent Calame's avatar Vincent Calame

Réduction des paramètres de requête suivant un suffixe

parent 075f0304
......@@ -14,9 +14,11 @@ import java.io.IOException;
import java.text.ParseException;
import java.util.AbstractList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.RandomAccess;
import java.util.Set;
import net.mapeadores.util.attr.AttributeUtils;
import net.mapeadores.util.attr.Attributes;
import net.mapeadores.util.localisation.Lang;
......@@ -133,6 +135,13 @@ public final class RequestUtils {
return new SupplementaryParameterList(array);
}
public static RequestMap reduceToSuffix(RequestMap requestMap, String suffix) {
if ((suffix == null) || (suffix.isEmpty())) {
return requestMap;
}
return new SuffixRequestMap(requestMap, suffix);
}
private static class EmptyRequestConf implements RequestConf {
......@@ -172,4 +181,62 @@ public final class RequestUtils {
}
private static class SuffixRequestMap implements RequestMap {
private final RequestMap requestMap;
private final String suffix;
private final Set<String> paramNameSet;
private SuffixRequestMap(RequestMap requestMap, String suffix) {
this.requestMap = requestMap;
this.suffix = suffix;
int suffixLength = suffix.length();
Set<String> set = new HashSet<String>();
for (String paramName : requestMap.getParameterNameSet()) {
if (paramName.startsWith(suffix)) {
set.add(paramName.substring(suffixLength));
}
}
this.paramNameSet = Collections.unmodifiableSet(set);
}
@Override
public FileValue getFileValue(String name) {
return requestMap.getFileValue(suffix + name);
}
@Override
public FileValue[] getFileValues(String name) {
return requestMap.getFileValues(suffix + name);
}
@Override
public String getParameter(String name) {
return requestMap.getParameter(suffix + name);
}
@Override
public String[] getParameterValues(String name) {
return requestMap.getParameterValues(suffix + name);
}
@Override
public Set<String> getParameterNameSet() {
return paramNameSet;
}
@Override
public Locale[] getAcceptableLocaleArray() {
return requestMap.getAcceptableLocaleArray();
}
@Override
public Object getSourceObject() {
return requestMap.getSourceObject();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment