Author: pete
Date: Tue Sep 6 21:12:30 2011
New Revision: 1165852
URL: http://svn.apache.org/viewvc?rev=1165852&view=rev
Log:
WICKET-4032 ComponentStringResourceLoader must not include the index of
repeater items in resource lookup but still resolve properties to them
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java?rev=1165852&r1=1165851&r2=1165852&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java
Tue Sep 6 21:12:30 2011
@@ -225,32 +225,39 @@ public class ComponentStringResourceLoad
// current component on the top of the stack.
String prefix = getResourcePath(component);
- // The reason why we need to create that stack is because we
need to
- // walk it downwards starting with Page down to the Component
- List<Class<?>> searchStack = getComponentStack(component);
-
- // Walk the component hierarchy down from page to the component
- for (int i = searchStack.size() - 1; (i >= 0) && (string ==
null); i--)
+ // walk downwards starting with page going down to component
+ for (Component current : getComponentTrail(component))
{
- Class<?> clazz = searchStack.get(i);
-
- // First, try the fully qualified resource name
relative to the
+ // get current component class
+ final Class<?> clazz = current.getClass();
+
+ // first, try the fully qualified resource name
relative to the
// component on the path from page down.
- if ((prefix != null) && (prefix.length() > 0))
+ if (Strings.isEmpty(prefix) == false)
{
+ // lookup fully qualified path
string = loadStringResource(clazz, prefix + '.'
+ key, locale, style, variation);
- if (string == null)
+ // return string if we found it
+ if (string != null)
+ {
+ return string;
+ }
+
+ // shorten resource key prefix when going
downwards (skip for repeaters)
+ if ((current instanceof AbstractRepeater) ==
false)
{
prefix = Strings.afterFirst(prefix,
'.');
}
}
-
// If not found, than check if a property with the
'key' provided by
// the user can be found.
- if (string == null)
+ string = loadStringResource(clazz, key, locale, style,
variation);
+
+ // return string if we found it
+ if (string != null)
{
- string = loadStringResource(clazz, key, locale,
style, variation);
+ return string;
}
}
@@ -287,35 +294,22 @@ public class ComponentStringResourceLoad
}
/**
- * Traverse the component hierarchy up to the Page and add each
component class to the list
- * (stack) returned
+ * return the trail of components from page to specified component
*
* @param component
- * The component to evaluate
- * @return The stack of classes
+ * The component to retrieve path for
+ * @return The list of components starting from top going down to
component
*/
- private List<Class<?>> getComponentStack(final Component component)
+ private List<Component> getComponentTrail(Component component)
{
- // Build the search stack
- final List<Class<?>> searchStack = new ArrayList<Class<?>>();
- searchStack.add(component.getClass());
+ final List<Component> path = new ArrayList<Component>();
- if (!(component instanceof Page))
+ while (component != null)
{
- // Add all the component on the way to the Page
- MarkupContainer container = component.getParent();
- while (container != null)
- {
- searchStack.add(container.getClass());
- if (container instanceof Page)
- {
- break;
- }
-
- container = container.getParent();
- }
+ path.add(0, component);
+ component = component.getParent();
}
- return searchStack;
+ return path;
}
/**