Revision: 1488
http://stripes.svn.sourceforge.net/stripes/?rev=1488&view=rev
Author: bengunter
Date: 2012-05-17 17:03:59 +0000 (Thu, 17 May 2012)
Log Message:
-----------
Fixed STS-835: <stripes:options-enumeration>, inner class enums and
internationalized labels
Modified Paths:
--------------
branches/1.5.x/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
branches/1.5.x/tests/src/net/sourceforge/stripes/localization/LocalizationUtilityTest.java
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
2012-03-30 14:58:10 UTC (rev 1487)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/localization/LocalizationUtility.java
2012-05-17 17:03:59 UTC (rev 1488)
@@ -158,4 +158,26 @@
return null;
}
}
+
+ /**
+ * Gets the simple name of a class for use as a key to look up a resource.
This is usually the
+ * same as {@link Class#getSimpleName()}, but static inner classes are
handled such that the
+ * simple name is {@code OuterClass.InnerClass}. Multiple layers of
nesting are supported.
+ *
+ * @param c The class whose simple name is requested.
+ * @return The simple name of the class.
+ */
+ public static String getSimpleName(Class<?> c) {
+ if (c.getEnclosingClass() == null)
+ return c.getSimpleName();
+ else
+ return prefixSimpleName(new StringBuilder(), c).toString();
+ }
+
+ /** A recursive method used by {@link #getSimpleName(Class)}. */
+ private static StringBuilder prefixSimpleName(StringBuilder s, Class<?> c)
{
+ if (c.getEnclosingClass() != null)
+ prefixSimpleName(s, c.getEnclosingClass()).append('.');
+ return s.append(c.getSimpleName());
+ }
}
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2012-03-30 14:58:10 UTC (rev 1487)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2012-05-17 17:03:59 UTC (rev 1488)
@@ -257,21 +257,22 @@
// Try to localize the label
String packageName = clazz.getPackage() == null ? "" :
clazz.getPackage().getName();
+ String simpleName = LocalizationUtility.getSimpleName(clazz);
String localizedLabel = null;
if (label != null) {
localizedLabel = LocalizationUtility.getLocalizedFieldName
- (clazz.getSimpleName() + "." + label, packageName,
null, locale);
+ (simpleName + "." + label, packageName, null, locale);
}
if (localizedLabel == null && value != null) {
localizedLabel = LocalizationUtility.getLocalizedFieldName
- (clazz.getSimpleName() + "." + value, packageName,
null, locale);
+ (simpleName + "." + value, packageName, null, locale);
}
if (localizedLabel != null) label = localizedLabel;
// Try to localize the group
if (group != null) {
String localizedGroup =
LocalizationUtility.getLocalizedFieldName(
- clazz.getSimpleName() + "." + group, packageName,
null, locale);
+ simpleName + "." + group, packageName, null,
locale);
if (localizedGroup != null) group = localizedGroup;
}
addEntry(item, label, value, group);
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
2012-03-30 14:58:10 UTC (rev 1487)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
2012-05-17 17:03:59 UTC (rev 1488)
@@ -118,9 +118,10 @@
for (Enum item : enums) {
Object label = null;
String packageName = clazz.getPackage() == null ? "" :
clazz.getPackage().getName();
+ String simpleName = LocalizationUtility.getSimpleName(clazz);
// Check for a localized label using class.ENUM_VALUE and
package.class.ENUM_VALUE
- label =
LocalizationUtility.getLocalizedFieldName(clazz.getSimpleName() + "." +
item.name(),
+ label = LocalizationUtility.getLocalizedFieldName(simpleName +
"." + item.name(),
packageName,
null,
locale);
Modified:
branches/1.5.x/tests/src/net/sourceforge/stripes/localization/LocalizationUtilityTest.java
===================================================================
---
branches/1.5.x/tests/src/net/sourceforge/stripes/localization/LocalizationUtilityTest.java
2012-03-30 14:58:10 UTC (rev 1487)
+++
branches/1.5.x/tests/src/net/sourceforge/stripes/localization/LocalizationUtilityTest.java
2012-05-17 17:03:59 UTC (rev 1488)
@@ -44,4 +44,24 @@
String output = LocalizationUtility.makePseudoFriendlyName(input);
Assert.assertEquals(output, "Bug Submitted By First Name");
}
+
+ public static enum TestEnum {
+ A, B, C;
+ }
+
+ public static class A {
+ public static class B {
+ public static class C {
+ }
+ }
+ }
+
+ @Test(groups = "fast")
+ public void testSimpleClassName() throws Exception {
+ String output = LocalizationUtility.getSimpleName(TestEnum.class);
+ Assert.assertEquals(output, "LocalizationUtilityTest.TestEnum");
+
+ output = LocalizationUtility.getSimpleName(A.B.C.class);
+ Assert.assertEquals(output, "LocalizationUtilityTest.A.B.C");
+ }
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development