diff --git a/.gitignore b/.gitignore
index a4a8548269346f1481131c97bd8b720517456704..9cab156c93bebaa219fd708f02a7dddb331b61d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
target/
classes/
jbossmodule/
+/nbproject/
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 22f0557a1447f5837b08f5a6755336c39e6719cb..ae28fa41d062c1ca753a5f4fde39986ea1ed8beb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,8 +90,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
- <source>1.7</source>
- <target>1.7</target>
+ <source>1.8</source>
+ <target>1.8</target>
</configuration>
</plugin>
</plugins>
diff --git a/src/main/java/no/nibio/vips/i18n/LanguageUtil.java b/src/main/java/no/nibio/vips/i18n/LanguageUtil.java
index 10341756a2f0a2b1cae09e3f2aa7a85b09e9ebd6..12862aee7671cc26775fe6619a9526a50a72be8f 100644
--- a/src/main/java/no/nibio/vips/i18n/LanguageUtil.java
+++ b/src/main/java/no/nibio/vips/i18n/LanguageUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 NIBIO <http://www.nibio.no/>.
+ * Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
@@ -19,47 +19,40 @@
package no.nibio.vips.i18n;
-import java.util.HashMap;
-import java.util.Map;
import com.ibm.icu.util.ULocale;
+import java.util.Arrays;
+import java.util.List;
+import static java.util.stream.Collectors.toList;
/**
- * @copyright 2014 <a href="http://www.nibio.no/">NIBIO</a>
+ * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class LanguageUtil {
- public static final ULocale[] AVAILABLE_LOCALES = {
- new ULocale("en"), // English
- new ULocale("nb"), // Norwegian bokmål
- new ULocale("bs"), // Bosnian
- new ULocale("hr"), // Croatian
- new ULocale("sr"), // Serbian
- new ULocale("fi"), // Finnish
- new ULocale("fr"), // French
- new ULocale("de"), // German
- new ULocale("lv") // Latvian
- };
-
- private static ULocale[] distinctLanguages;
+ private static List<ULocale> distinctLanguages;
/**
*
* @return All available locales with distinct languages
+ *
*/
- public static ULocale[] getAvailableLocalesWithDistinctLanguage()
+ public static List<ULocale> getAvailableLocalesWithDistinctLanguage()
{
-
if(distinctLanguages == null)
{
- Map<String, ULocale> localeBucket = new HashMap<>();
- for(ULocale locale:LanguageUtil.AVAILABLE_LOCALES)
- {
- localeBucket.put(locale.getLanguage(), locale);
- }
- distinctLanguages = localeBucket.values().toArray(new ULocale[0]);
+ String[] availableLanguages;
+ try{
+ availableLanguages = System.getProperty("no.nibio.vips.logic.AVAILABLE_LANGUAGES").split(",");
+ }
+ catch(NullPointerException ex){
+ availableLanguages = new String[1];
+ availableLanguages[0] = "en";
+ }
+ distinctLanguages = Arrays.asList(availableLanguages).stream()
+ .map(lang -> new ULocale(lang))
+ .collect(toList());
}
-
return distinctLanguages;
}
}
diff --git a/src/main/java/no/nibio/vips/util/ServletUtil.java b/src/main/java/no/nibio/vips/util/ServletUtil.java
index 9e00953f0179dbe8998c303b20860b2e8aaf415d..c39a912cfdbd3db6a7563711c64a81e67c9d2c18 100644
--- a/src/main/java/no/nibio/vips/util/ServletUtil.java
+++ b/src/main/java/no/nibio/vips/util/ServletUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 NIBIO <http://www.nibio.no/>.
+ * Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
@@ -19,12 +19,16 @@
package no.nibio.vips.util;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
+import java.util.List;
+import java.util.stream.Collectors;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
/**
- * @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
+ * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class ServletUtil {
@@ -162,4 +166,24 @@ public class ServletUtil {
}
return null;
}
+
+ /**
+ * Removes the given parameters from a query string
+ * @param parametersToRemove
+ * @return
+ */
+ public static String getCleanedQueryString(String servletPathWithQueryString, String parameterToRemove)
+ {
+ List<String> whatsLeft;
+ String servletPath = servletPathWithQueryString.split("\\?").length > 1 ?
+ servletPathWithQueryString.split("\\?")[0]
+ : "";
+ whatsLeft = (servletPathWithQueryString.split("\\?").length > 1 ?
+ Arrays.asList(servletPathWithQueryString.split("\\?")[1].split("&")) :
+ new ArrayList<String>())
+ .stream().filter(
+ paramStr -> ! paramStr.contains(parameterToRemove)
+ ).collect(Collectors.toList());
+ return servletPath + (!whatsLeft.isEmpty() ? "?" + String.join("&", whatsLeft) : "");
+ }
}
diff --git a/src/test/java/no/nibio/vips/util/ServletUtilTest.java b/src/test/java/no/nibio/vips/util/ServletUtilTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..af57c21004f1cb9b7688b55c77e3f60ee01601c0
--- /dev/null
+++ b/src/test/java/no/nibio/vips/util/ServletUtilTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016 NIBIO <http://www.nibio.no/>.
+ *
+ * This file is part of VIPSCommon.
+ * VIPSCommon is free software: you can redistribute it and/or modify
+ * it under the terms of the NIBIO Open Source License as published by
+ * NIBIO, either version 1 of the License, or (at your option) any
+ * later version.
+ *
+ * VIPSCommon is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * NIBIO Open Source License for more details.
+ *
+ * You should have received a copy of the NIBIO Open Source License
+ * along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
+ *
+ */
+package no.nibio.vips.util;
+
+import javax.servlet.http.HttpServletRequest;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author treinar
+ */
+public class ServletUtilTest extends TestCase {
+
+ public ServletUtilTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+ /**
+ * Test of getCleanedQueryString method, of class ServletUtil.
+ */
+ public void testGetCleanedQueryString() {
+ System.out.println("getCleanedQueryString");
+ String servletPathWithQueryString = "/blabla?removeParam=77&keepParam=66&keepAlso=uyt";
+ String parameterToRemove = "removeParam";
+ String expResult = "/blabla?keepParam=66&keepAlso=uyt";
+ String result = ServletUtil.getCleanedQueryString(servletPathWithQueryString, parameterToRemove);
+ System.out.println("result=" + result);
+ assertEquals(expResult, result);
+ servletPathWithQueryString = "/blabla?keepParam=66&removeParam=77&keepAlso=uyt";
+ result = ServletUtil.getCleanedQueryString(servletPathWithQueryString, parameterToRemove);
+ assertEquals(expResult, result);
+ servletPathWithQueryString = "/blabla?keepParam=66&keepAlso=uyt&removeParam=77";
+ result = ServletUtil.getCleanedQueryString(servletPathWithQueryString, parameterToRemove);
+ assertEquals(expResult, result);
+ servletPathWithQueryString = "/blabla?removeParam=77";
+ expResult = "/blabla";
+ result = ServletUtil.getCleanedQueryString(servletPathWithQueryString, parameterToRemove);
+ assertEquals(expResult, result);
+ }
+
+}