You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2012/02/09 07:43:24 UTC
git commit: simply use locale.toString(), added testcase to prove it
Updated Branches:
refs/heads/master d88d78e1c -> 831b11ccc
simply use locale.toString(), added testcase to prove it
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/831b11cc
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/831b11cc
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/831b11cc
Branch: refs/heads/master
Commit: 831b11ccc0c0990bdb50661077341008a28eefa4
Parents: d88d78e
Author: svenmeier <sv...@apache.org>
Authored: Thu Feb 9 07:42:37 2012 +0100
Committer: svenmeier <sv...@apache.org>
Committed: Thu Feb 9 07:42:37 2012 +0100
----------------------------------------------------------------------
.../markup/DefaultMarkupCacheKeyProvider.java | 25 +---
.../markup/DefaultMarkupCacheKeyProviderTest.java | 104 +++++++++++++++
2 files changed, 111 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/831b11cc/wicket-core/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java b/wicket-core/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java
index e15edc5..1446f79 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProvider.java
@@ -54,33 +54,22 @@ public class DefaultMarkupCacheKeyProvider implements IMarkupCacheKeyProvider
final StringBuilder buffer = new StringBuilder(classname.length() + 64);
buffer.append(classname);
- if (container.getVariation() != null)
+ final String variation = container.getVariation();
+ if (variation != null)
{
- buffer.append('_').append(container.getVariation());
+ buffer.append('_').append(variation);
}
- if (container.getStyle() != null)
+ final String style = container.getStyle();
+ if (style != null)
{
- buffer.append('_').append(container.getStyle());
+ buffer.append('_').append(style);
}
final Locale locale = container.getLocale();
if (locale != null)
{
- buffer.append('_').append(locale.getLanguage());
-
- final boolean hasLocale = locale.getLanguage().length() != 0;
- final boolean hasCountry = locale.getCountry().length() != 0;
- final boolean hasVariant = locale.getVariant().length() != 0;
-
- if (hasCountry || (hasLocale && hasVariant))
- {
- buffer.append('_').append(locale.getCountry());
- }
- if (hasVariant && (hasLocale || hasCountry))
- {
- buffer.append('_').append(locale.getVariant());
- }
+ buffer.append('_').append(locale.toString());
}
buffer.append('.').append(container.getMarkupType().getExtension());
http://git-wip-us.apache.org/repos/asf/wicket/blob/831b11cc/wicket-core/src/test/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProviderTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProviderTest.java
new file mode 100644
index 0000000..f02852d
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/DefaultMarkupCacheKeyProviderTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.markup;
+
+import java.util.Locale;
+
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.junit.Test;
+
+/**
+ * Test for {@link DefaultMarkupCacheKeyProvider}.
+ */
+public class DefaultMarkupCacheKeyProviderTest extends WicketTestCase
+{
+
+ /**
+ */
+ @Test
+ public void localeLanguageCountryVariant()
+ {
+ DefaultMarkupCacheKeyProvider provider = new DefaultMarkupCacheKeyProvider();
+
+ Foo foo = new Foo("foo");
+ assertEquals("org.apache.wicket.markup.Foo.html", provider.getCacheKey(foo, foo.getClass()));
+
+ foo.locale = new Locale("");
+ assertEquals("org.apache.wicket.markup.Foo_.html",
+ provider.getCacheKey(foo, foo.getClass()));
+
+ foo.locale = new Locale("language");
+ assertEquals("org.apache.wicket.markup.Foo_language.html", provider.getCacheKey(foo,
+ foo.getClass()));
+
+ foo.locale = new Locale("", "COUNTRY");
+ assertEquals("org.apache.wicket.markup.Foo__COUNTRY.html", provider.getCacheKey(foo,
+ foo.getClass()));
+
+ // variant only is ignored
+ foo.locale = new Locale("", "", "variant");
+ assertEquals("org.apache.wicket.markup.Foo_.html",
+ provider.getCacheKey(foo, foo.getClass()));
+
+ foo.locale = new Locale("language", "COUNTRY");
+ assertEquals("org.apache.wicket.markup.Foo_language_COUNTRY.html", provider.getCacheKey(
+ foo, foo.getClass()));
+
+ foo.locale = new Locale("language", "", "variant");
+ assertEquals("org.apache.wicket.markup.Foo_language__variant.html", provider.getCacheKey(
+ foo, foo.getClass()));
+
+ foo.locale = new Locale("", "COUNTRY", "variant");
+ assertEquals("org.apache.wicket.markup.Foo__COUNTRY_variant.html", provider.getCacheKey(
+ foo, foo.getClass()));
+
+ foo.locale = new Locale("language", "COUNTRY", "variant");
+ assertEquals("org.apache.wicket.markup.Foo_language_COUNTRY_variant.html",
+ provider.getCacheKey(foo, foo.getClass()));
+ }
+}
+
+class Foo extends WebMarkupContainer
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public Locale locale;
+
+ public Foo(String id)
+ {
+ super(id);
+ }
+
+ @Override
+ protected void onRender()
+ {
+ }
+
+ @Override
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ @Override
+ public MarkupType getMarkupType()
+ {
+ return MarkupType.HTML_MARKUP_TYPE;
+ }
+}
\ No newline at end of file