Repository: wicket
Updated Branches:
  refs/heads/master 09fc316b7 -> 0f8a6d757


WICKET-5706 ResourceUtils.getLocaleFromFilename cannot handle filenames with 
classifiers


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/0f8a6d75
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/0f8a6d75
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/0f8a6d75

Branch: refs/heads/master
Commit: 0f8a6d757367e73eaadcb0dff1372d169bcefb76
Parents: 09fc316
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Tue Sep 23 13:48:14 2014 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Tue Sep 23 13:48:14 2014 +0200

----------------------------------------------------------------------
 .../wicket/util/resource/ResourceUtils.java     |  8 +--
 .../wicket/util/resource/ResourceUtilsTest.java | 61 ++++++++++++++++++++
 2 files changed, 65 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/0f8a6d75/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceUtils.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceUtils.java 
b/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceUtils.java
index e7ec95a..3216707 100644
--- 
a/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceUtils.java
+++ 
b/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceUtils.java
@@ -33,10 +33,10 @@ public class ResourceUtils
 {
        private static final Pattern LOCALE_PATTERN = 
Pattern.compile("_([a-z]{2})(_([A-Z]{2})(_([^_]+))?)?$");
 
-       private final static Set<String> isoCountries = new 
ConcurrentHashSet<String>(
+       private final static Set<String> isoCountries = new ConcurrentHashSet<>(
                Arrays.asList(Locale.getISOCountries()));
 
-       private final static Set<String> isoLanguages = new 
ConcurrentHashSet<String>(
+       private final static Set<String> isoLanguages = new ConcurrentHashSet<>(
                Arrays.asList(Locale.getISOLanguages()));
 
        /**
@@ -56,7 +56,7 @@ public class ResourceUtils
        public static PathLocale getLocaleFromFilename(String path)
        {
                String extension = "";
-               int pos = path.indexOf('.');
+               int pos = path.lastIndexOf('.');
                if (pos != -1)
                {
                        extension = path.substring(pos);
@@ -104,7 +104,7 @@ public class ResourceUtils
                        }
                } // else skip the whole thing... probably user specific 
underscores used
 
-               return new PathLocale(path, null);
+               return new PathLocale(path + extension, null);
        }
 
        /**

http://git-wip-us.apache.org/repos/asf/wicket/blob/0f8a6d75/wicket-util/src/test/java/org/apache/wicket/util/resource/ResourceUtilsTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/test/java/org/apache/wicket/util/resource/ResourceUtilsTest.java
 
b/wicket-util/src/test/java/org/apache/wicket/util/resource/ResourceUtilsTest.java
new file mode 100644
index 0000000..d1722a3
--- /dev/null
+++ 
b/wicket-util/src/test/java/org/apache/wicket/util/resource/ResourceUtilsTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.wicket.util.resource;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+
+import java.util.Locale;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ResourceUtilsTest extends Assert
+{
+       /**
+        * https://issues.apache.org/jira/browse/WICKET-5706
+        */
+       @Test
+       public void getLocaleFromFilename()
+       {
+               ResourceUtils.PathLocale pathLocale;
+
+               pathLocale = ResourceUtils.getLocaleFromFilename("some.ext");
+               assertThat(pathLocale.path, is(equalTo("some.ext")));
+               assertThat(pathLocale.locale, is(nullValue()));
+
+               pathLocale = 
ResourceUtils.getLocaleFromFilename("some.min.ext");
+               assertThat(pathLocale.path, is(equalTo("some.min.ext")));
+               assertThat(pathLocale.locale, is(nullValue()));
+
+               pathLocale = 
ResourceUtils.getLocaleFromFilename("some.min_en.ext");
+               assertThat(pathLocale.path, is(equalTo("some.min.ext")));
+               assertThat(pathLocale.locale, is(Locale.ENGLISH));
+
+               pathLocale = 
ResourceUtils.getLocaleFromFilename("some.min_fr_CA.ext");
+               assertThat(pathLocale.path, is(equalTo("some.min.ext")));
+               assertThat(pathLocale.locale, is(Locale.CANADA_FRENCH));
+
+               String localeVariant = "blah";
+               pathLocale = 
ResourceUtils.getLocaleFromFilename("some.min_fr_CA_"+localeVariant+".ext");
+               assertThat(pathLocale.path, is(equalTo("some.min.ext")));
+               assertThat(pathLocale.locale.getLanguage(), is("fr"));
+               assertThat(pathLocale.locale.getCountry(), is("CA"));
+               assertThat(pathLocale.locale.getVariant(), is(localeVariant));
+       }
+}

Reply via email to