You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2016/11/24 03:30:39 UTC
svn commit: r1771070 - in /openmeetings/application:
branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/
branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/
branches/3.1.x/openmeetings-util/...
Author: solomax
Date: Thu Nov 24 03:30:38 2016
New Revision: 1771070
URL: http://svn.apache.org/viewvc?rev=1771070&view=rev
Log:
[OPENMEETINGS-1512] country is now validated against Java country list
Added:
openmeetings/application/branches/3.1.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java
openmeetings/application/branches/3.1.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java
openmeetings/application/branches/3.2.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java
openmeetings/application/branches/3.2.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java
openmeetings/application/trunk/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java
openmeetings/application/trunk/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java
Modified:
openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java
openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java
openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java
openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java
openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java
openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java
Modified: openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java (original)
+++ openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java Thu Nov 24 03:30:38 2016
@@ -19,6 +19,7 @@
package org.apache.openmeetings.core.ldap;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.openmeetings.util.LocaleHelper.validateCountry;
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DEFAULT_GROUP_ID;
import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
@@ -361,7 +362,7 @@ public class LdapLoginManagement {
u.getAddress().setAdditionalname(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_ADDITIONAL_NAME, LDAP_KEY_ADDITIONAL_NAME));
u.getAddress().setFax(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_FAX, LDAP_KEY_FAX));
u.getAddress().setZip(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_ZIP, LDAP_KEY_ZIP));
- u.getAddress().setCountry(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_COUNTRY, LDAP_KEY_COUNTRY));
+ u.getAddress().setCountry(validateCountry(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_COUNTRY, LDAP_KEY_COUNTRY)));
u.getAddress().setTown(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_TOWN, LDAP_KEY_TOWN));
u.getAddress().setPhone(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_PHONE, LDAP_KEY_PHONE));
String tz = getStringAttr(config, entry, LdapOptions.CONFIGKEY_LDAP_TIMEZONE_NAME, LDAP_KEY_TIMEZONE);
Modified: openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java (original)
+++ openmeetings/application/branches/3.1.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java Thu Nov 24 03:30:38 2016
@@ -23,6 +23,7 @@ import static org.apache.openmeetings.ut
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_OAUTH_REGISTER_KEY;
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_SOAP_REGISTER_KEY;
import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+import static org.apache.openmeetings.util.LocaleHelper.getCountryName;
import java.util.ArrayList;
import java.util.Arrays;
@@ -93,7 +94,7 @@ public class MobileService {
public Map<String, String> getStates() {
Map<String, String> result = new Hashtable<>();
for (String code : Locale.getISOCountries()) {
- result.put(code, new Locale.Builder().setRegion(code).build().getDisplayCountry());
+ result.put(code, getCountryName(code));
}
return result;
}
Added: openmeetings/application/branches/3.1.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java?rev=1771070&view=auto
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java (added)
+++ openmeetings/application/branches/3.1.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java Thu Nov 24 03:30:38 2016
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util;
+
+import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.red5.logging.Red5LoggerFactory;
+import org.slf4j.Logger;
+
+public class LocaleHelper {
+ private static final Logger log = Red5LoggerFactory.getLogger(LocaleHelper.class, webAppRootKey);
+ public static List<String> getCountries() {
+ return Arrays.asList(Locale.getISOCountries());
+ }
+
+ public static String getCountryName(String code, Locale l) {
+ return new Locale.Builder().setRegion(code).build().getDisplayCountry(l);
+ }
+
+ public static String getCountryName(String code) {
+ return new Locale.Builder().setRegion(code).build().getDisplayCountry();
+ }
+
+ public static String validateCountry(String code) {
+ List<String> list = getCountries();
+ Set<String> countries = new HashSet<>(list);
+ code = code == null ? "" : code.toUpperCase();
+ if (!countries.contains(code)) {
+ String newCountry = list.get(0);
+ log.warn("Invalid country found: {}, will be replaced with: {}", code, newCountry);
+ code = newCountry;
+ }
+ return code;
+ }
+}
Added: openmeetings/application/branches/3.1.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java?rev=1771070&view=auto
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java (added)
+++ openmeetings/application/branches/3.1.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java Thu Nov 24 03:30:38 2016
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util;
+
+import static org.apache.openmeetings.util.LocaleHelper.getCountries;
+import static org.apache.openmeetings.util.LocaleHelper.validateCountry;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class TestLocaleHelper {
+ private static final String COUNTRY_IT_LC = "it";
+ private static final String COUNTRY_IT = "IT";
+ private static final String COUNTRY_ITALY = "Italy";
+
+ @Test
+ public void testCountry() {
+ List<String> list = getCountries();
+ assertNotNull("Country list shouldn't be null", list);
+ assertFalse("Country list shouldn't be empty", list.isEmpty());
+ assertEquals("Check for valid", COUNTRY_IT, validateCountry(COUNTRY_IT));
+ assertEquals("Check for valid (lower case)", COUNTRY_IT, validateCountry(COUNTRY_IT_LC));
+ assertNotEquals("Check for invalid (null)", COUNTRY_IT, validateCountry(null));
+ assertNotEquals("Check for invalid", COUNTRY_IT, validateCountry(COUNTRY_ITALY));
+ }
+}
Modified: openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java (original)
+++ openmeetings/application/branches/3.1.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java Thu Nov 24 03:30:38 2016
@@ -18,9 +18,10 @@
*/
package org.apache.openmeetings.web.util;
-import java.util.Arrays;
+import static org.apache.openmeetings.util.LocaleHelper.getCountries;
+import static org.apache.openmeetings.util.LocaleHelper.getCountryName;
+
import java.util.List;
-import java.util.Locale;
import org.apache.openmeetings.web.app.WebSession;
import org.apache.wicket.markup.html.form.DropDownChoice;
@@ -33,13 +34,9 @@ public class CountryDropDown extends Dro
public CountryDropDown(String id) {
this(id, null);
}
-
- public static String getCountryName(String code) {
- return new Locale.Builder().setRegion(code).build().getDisplayCountry(WebSession.get().getLocale());
- }
-
+
public CountryDropDown(String id, IModel<String> model) {
- super(id, model, Arrays.asList(Locale.getISOCountries()));
+ super(id, model, getCountries());
setChoiceRenderer(new IChoiceRenderer<String>() {
private static final long serialVersionUID = 1L;
@@ -47,10 +44,10 @@ public class CountryDropDown extends Dro
public String getIdValue(String code, int index) {
return code;
}
-
+
@Override
public Object getDisplayValue(String code) {
- return getCountryName(code);
+ return getCountryName(code, WebSession.get().getLocale());
}
@Override
Modified: openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java (original)
+++ openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java Thu Nov 24 03:30:38 2016
@@ -19,6 +19,7 @@
package org.apache.openmeetings.core.ldap;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.openmeetings.util.LocaleHelper.validateCountry;
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DEFAULT_GROUP_ID;
import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
@@ -361,7 +362,7 @@ public class LdapLoginManagement {
u.getAddress().setAdditionalname(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_ADDITIONAL_NAME, LDAP_KEY_ADDITIONAL_NAME));
u.getAddress().setFax(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_FAX, LDAP_KEY_FAX));
u.getAddress().setZip(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_ZIP, LDAP_KEY_ZIP));
- u.getAddress().setCountry(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_COUNTRY, LDAP_KEY_COUNTRY));
+ u.getAddress().setCountry(validateCountry(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_COUNTRY, LDAP_KEY_COUNTRY)));
u.getAddress().setTown(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_TOWN, LDAP_KEY_TOWN));
u.getAddress().setPhone(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_PHONE, LDAP_KEY_PHONE));
String tz = getStringAttr(config, entry, LdapOptions.CONFIGKEY_LDAP_TIMEZONE_NAME, LDAP_KEY_TIMEZONE);
Modified: openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java (original)
+++ openmeetings/application/branches/3.2.x/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java Thu Nov 24 03:30:38 2016
@@ -23,6 +23,7 @@ import static org.apache.openmeetings.ut
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_OAUTH_REGISTER_KEY;
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_SOAP_REGISTER_KEY;
import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+import static org.apache.openmeetings.util.LocaleHelper.getCountryName;
import java.util.ArrayList;
import java.util.Arrays;
@@ -93,7 +94,7 @@ public class MobileService {
public Map<String, String> getStates() {
Map<String, String> result = new Hashtable<>();
for (String code : Locale.getISOCountries()) {
- result.put(code, new Locale.Builder().setRegion(code).build().getDisplayCountry());
+ result.put(code, getCountryName(code));
}
return result;
}
Added: openmeetings/application/branches/3.2.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java?rev=1771070&view=auto
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java (added)
+++ openmeetings/application/branches/3.2.x/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java Thu Nov 24 03:30:38 2016
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util;
+
+import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.red5.logging.Red5LoggerFactory;
+import org.slf4j.Logger;
+
+public class LocaleHelper {
+ private static final Logger log = Red5LoggerFactory.getLogger(LocaleHelper.class, webAppRootKey);
+ public static List<String> getCountries() {
+ return Arrays.asList(Locale.getISOCountries());
+ }
+
+ public static String getCountryName(String code, Locale l) {
+ return new Locale.Builder().setRegion(code).build().getDisplayCountry(l);
+ }
+
+ public static String getCountryName(String code) {
+ return new Locale.Builder().setRegion(code).build().getDisplayCountry();
+ }
+
+ public static String validateCountry(String code) {
+ List<String> list = getCountries();
+ Set<String> countries = new HashSet<>(list);
+ code = code == null ? "" : code.toUpperCase();
+ if (!countries.contains(code)) {
+ String newCountry = list.get(0);
+ log.warn("Invalid country found: {}, will be replaced with: {}", code, newCountry);
+ code = newCountry;
+ }
+ return code;
+ }
+}
Added: openmeetings/application/branches/3.2.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java?rev=1771070&view=auto
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java (added)
+++ openmeetings/application/branches/3.2.x/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java Thu Nov 24 03:30:38 2016
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util;
+
+import static org.apache.openmeetings.util.LocaleHelper.getCountries;
+import static org.apache.openmeetings.util.LocaleHelper.validateCountry;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class TestLocaleHelper {
+ private static final String COUNTRY_IT_LC = "it";
+ private static final String COUNTRY_IT = "IT";
+ private static final String COUNTRY_ITALY = "Italy";
+
+ @Test
+ public void testCountry() {
+ List<String> list = getCountries();
+ assertNotNull("Country list shouldn't be null", list);
+ assertFalse("Country list shouldn't be empty", list.isEmpty());
+ assertEquals("Check for valid", COUNTRY_IT, validateCountry(COUNTRY_IT));
+ assertEquals("Check for valid (lower case)", COUNTRY_IT, validateCountry(COUNTRY_IT_LC));
+ assertNotEquals("Check for invalid (null)", COUNTRY_IT, validateCountry(null));
+ assertNotEquals("Check for invalid", COUNTRY_IT, validateCountry(COUNTRY_ITALY));
+ }
+}
Modified: openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java
URL: http://svn.apache.org/viewvc/openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java (original)
+++ openmeetings/application/branches/3.2.x/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java Thu Nov 24 03:30:38 2016
@@ -18,9 +18,10 @@
*/
package org.apache.openmeetings.web.util;
-import java.util.Arrays;
+import static org.apache.openmeetings.util.LocaleHelper.getCountries;
+import static org.apache.openmeetings.util.LocaleHelper.getCountryName;
+
import java.util.List;
-import java.util.Locale;
import org.apache.openmeetings.web.app.WebSession;
import org.apache.wicket.markup.html.form.DropDownChoice;
@@ -33,13 +34,9 @@ public class CountryDropDown extends Dro
public CountryDropDown(String id) {
this(id, null);
}
-
- public static String getCountryName(String code) {
- return new Locale.Builder().setRegion(code).build().getDisplayCountry(WebSession.get().getLocale());
- }
-
+
public CountryDropDown(String id, IModel<String> model) {
- super(id, model, Arrays.asList(Locale.getISOCountries()));
+ super(id, model, getCountries());
setChoiceRenderer(new IChoiceRenderer<String>() {
private static final long serialVersionUID = 1L;
@@ -47,10 +44,10 @@ public class CountryDropDown extends Dro
public String getIdValue(String code, int index) {
return code;
}
-
+
@Override
public Object getDisplayValue(String code) {
- return getCountryName(code);
+ return getCountryName(code, WebSession.get().getLocale());
}
@Override
Modified: openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java (original)
+++ openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/ldap/LdapLoginManagement.java Thu Nov 24 03:30:38 2016
@@ -19,6 +19,7 @@
package org.apache.openmeetings.core.ldap;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.openmeetings.util.LocaleHelper.validateCountry;
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_DEFAULT_GROUP_ID;
import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
@@ -361,7 +362,7 @@ public class LdapLoginManagement {
u.getAddress().setAdditionalname(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_ADDITIONAL_NAME, LDAP_KEY_ADDITIONAL_NAME));
u.getAddress().setFax(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_FAX, LDAP_KEY_FAX));
u.getAddress().setZip(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_ZIP, LDAP_KEY_ZIP));
- u.getAddress().setCountry(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_COUNTRY, LDAP_KEY_COUNTRY));
+ u.getAddress().setCountry(validateCountry(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_COUNTRY, LDAP_KEY_COUNTRY)));
u.getAddress().setTown(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_TOWN, LDAP_KEY_TOWN));
u.getAddress().setPhone(getStringAttr(config, entry, CONFIGKEY_LDAP_KEY_PHONE, LDAP_KEY_PHONE));
String tz = getStringAttr(config, entry, LdapOptions.CONFIGKEY_LDAP_TIMEZONE_NAME, LDAP_KEY_TIMEZONE);
Modified: openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java (original)
+++ openmeetings/application/trunk/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/MobileService.java Thu Nov 24 03:30:38 2016
@@ -23,6 +23,7 @@ import static org.apache.openmeetings.ut
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_OAUTH_REGISTER_KEY;
import static org.apache.openmeetings.util.OpenmeetingsVariables.CONFIG_SOAP_REGISTER_KEY;
import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+import static org.apache.openmeetings.util.LocaleHelper.getCountryName;
import java.util.ArrayList;
import java.util.Arrays;
@@ -93,7 +94,7 @@ public class MobileService {
public Map<String, String> getStates() {
Map<String, String> result = new Hashtable<>();
for (String code : Locale.getISOCountries()) {
- result.put(code, new Locale.Builder().setRegion(code).build().getDisplayCountry());
+ result.put(code, getCountryName(code));
}
return result;
}
Added: openmeetings/application/trunk/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java?rev=1771070&view=auto
==============================================================================
--- openmeetings/application/trunk/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java (added)
+++ openmeetings/application/trunk/openmeetings-util/src/main/java/org/apache/openmeetings/util/LocaleHelper.java Thu Nov 24 03:30:38 2016
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util;
+
+import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.red5.logging.Red5LoggerFactory;
+import org.slf4j.Logger;
+
+public class LocaleHelper {
+ private static final Logger log = Red5LoggerFactory.getLogger(LocaleHelper.class, webAppRootKey);
+ public static List<String> getCountries() {
+ return Arrays.asList(Locale.getISOCountries());
+ }
+
+ public static String getCountryName(String code, Locale l) {
+ return new Locale.Builder().setRegion(code).build().getDisplayCountry(l);
+ }
+
+ public static String getCountryName(String code) {
+ return new Locale.Builder().setRegion(code).build().getDisplayCountry();
+ }
+
+ public static String validateCountry(String code) {
+ List<String> list = getCountries();
+ Set<String> countries = new HashSet<>(list);
+ code = code == null ? "" : code.toUpperCase();
+ if (!countries.contains(code)) {
+ String newCountry = list.get(0);
+ log.warn("Invalid country found: {}, will be replaced with: {}", code, newCountry);
+ code = newCountry;
+ }
+ return code;
+ }
+}
Added: openmeetings/application/trunk/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java?rev=1771070&view=auto
==============================================================================
--- openmeetings/application/trunk/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java (added)
+++ openmeetings/application/trunk/openmeetings-util/src/test/java/org/apache/openmeetings/util/TestLocaleHelper.java Thu Nov 24 03:30:38 2016
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util;
+
+import static org.apache.openmeetings.util.LocaleHelper.getCountries;
+import static org.apache.openmeetings.util.LocaleHelper.validateCountry;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class TestLocaleHelper {
+ private static final String COUNTRY_IT_LC = "it";
+ private static final String COUNTRY_IT = "IT";
+ private static final String COUNTRY_ITALY = "Italy";
+
+ @Test
+ public void testCountry() {
+ List<String> list = getCountries();
+ assertNotNull("Country list shouldn't be null", list);
+ assertFalse("Country list shouldn't be empty", list.isEmpty());
+ assertEquals("Check for valid", COUNTRY_IT, validateCountry(COUNTRY_IT));
+ assertEquals("Check for valid (lower case)", COUNTRY_IT, validateCountry(COUNTRY_IT_LC));
+ assertNotEquals("Check for invalid (null)", COUNTRY_IT, validateCountry(null));
+ assertNotEquals("Check for invalid", COUNTRY_IT, validateCountry(COUNTRY_ITALY));
+ }
+}
Modified: openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java
URL: http://svn.apache.org/viewvc/openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java?rev=1771070&r1=1771069&r2=1771070&view=diff
==============================================================================
--- openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java (original)
+++ openmeetings/application/trunk/openmeetings-web/src/main/java/org/apache/openmeetings/web/util/CountryDropDown.java Thu Nov 24 03:30:38 2016
@@ -18,9 +18,10 @@
*/
package org.apache.openmeetings.web.util;
-import java.util.Arrays;
+import static org.apache.openmeetings.util.LocaleHelper.getCountries;
+import static org.apache.openmeetings.util.LocaleHelper.getCountryName;
+
import java.util.List;
-import java.util.Locale;
import org.apache.openmeetings.web.app.WebSession;
import org.apache.wicket.markup.html.form.DropDownChoice;
@@ -33,13 +34,9 @@ public class CountryDropDown extends Dro
public CountryDropDown(String id) {
this(id, null);
}
-
- public static String getCountryName(String code) {
- return new Locale.Builder().setRegion(code).build().getDisplayCountry(WebSession.get().getLocale());
- }
-
+
public CountryDropDown(String id, IModel<String> model) {
- super(id, model, Arrays.asList(Locale.getISOCountries()));
+ super(id, model, getCountries());
setChoiceRenderer(new IChoiceRenderer<String>() {
private static final long serialVersionUID = 1L;
@@ -47,10 +44,10 @@ public class CountryDropDown extends Dro
public String getIdValue(String code, int index) {
return code;
}
-
+
@Override
public Object getDisplayValue(String code) {
- return getCountryName(code);
+ return getCountryName(code, WebSession.get().getLocale());
}
@Override