fix compile Java 8

This commit is contained in:
anhefti 2019-04-05 14:12:36 +02:00
parent 1d2b7c98cd
commit eb8e37a888
2 changed files with 19 additions and 4 deletions

View file

@ -8,6 +8,9 @@
package ch.ethz.seb.sebserver.gbl.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -21,6 +24,8 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -29,6 +34,8 @@ import ch.ethz.seb.sebserver.gbl.Constants;
public final class Utils {
private static final Logger log = LoggerFactory.getLogger(Utils.class);
/** Get an immutable List from a Collection of elements
*
* @param collection Collection of elements
@ -173,4 +180,13 @@ public final class Utils {
: null;
}
public static final String encodeFormURL_UTF_8(final String value) {
try {
return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
} catch (final UnsupportedEncodingException e) {
log.error("Unexpected error while trying to encode to from URL UTF-8: ", e);
return value;
}
}
}

View file

@ -8,8 +8,6 @@
package ch.ethz.seb.sebserver.gui.form;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
@ -35,6 +33,7 @@ import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.FormBinding;
import ch.ethz.seb.sebserver.gui.widget.ImageUpload;
import ch.ethz.seb.sebserver.gui.widget.Selection;
@ -268,11 +267,11 @@ public final class Form implements FormBinding {
final String[] nameValue = StringUtils.split(split[i], Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR);
buffer.append(nameValue[0])
.append(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)
.append(URLEncoder.encode(nameValue[1], StandardCharsets.UTF_8));
.append(Utils.encodeFormURL_UTF_8(nameValue[1]));
} else {
buffer.append(name)
.append(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)
.append(URLEncoder.encode(split[i], StandardCharsets.UTF_8));
.append(Utils.encodeFormURL_UTF_8(split[i]));
}
}
}