Repository: wicket Updated Branches: refs/heads/wicket-6.x 49aaea831 -> b59792898
WICKET-5706 ResourceUtils.getLocaleFromFilename cannot handle filenames with classifiers (cherry picked from commit 0f8a6d757367e73eaadcb0dff1372d169bcefb76) Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b5979289 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b5979289 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b5979289 Branch: refs/heads/wicket-6.x Commit: b5979289835a0eda988de2cb922d5ddd1914fa81 Parents: 49aaea8 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:53:47 2014 +0200 ---------------------------------------------------------------------- .../wicket/util/resource/ResourceUtils.java | 4 +- .../wicket/util/resource/ResourceUtilsTest.java | 61 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/b5979289/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..c62dfbd 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 @@ -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/b5979289/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)); + } +}
