You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/06/12 19:29:42 UTC
svn commit: r784209 - in /tiles/framework/trunk/tiles-core/src:
main/java/org/apache/tiles/definition/dao/
main/java/org/apache/tiles/definition/pattern/
test/java/org/apache/tiles/definition/dao/
Author: apetrelli
Date: Fri Jun 12 17:29:42 2009
New Revision: 784209
URL: http://svn.apache.org/viewvc?rev=784209&view=rev
Log:
TILES-420
Extracted PatternDefinitionResolver to manage wildcard matching and replacing.
Added:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java (with props)
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java (with props)
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java (with props)
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java (with props)
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAO.java
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java
Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAO.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAO.java?rev=784209&r1=784208&r2=784209&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAO.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAO.java Fri Jun 12 17:29:42 2009
@@ -23,20 +23,18 @@
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
-import org.apache.tiles.Attribute;
import org.apache.tiles.Definition;
import org.apache.tiles.definition.DefinitionsFactoryException;
import org.apache.tiles.definition.NoSuchDefinitionException;
import org.apache.tiles.definition.Refreshable;
+import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
+import org.apache.tiles.definition.pattern.PatternDefinitionResolverAware;
+import org.apache.tiles.definition.pattern.WildcardPatternDefinitionResolver;
import org.apache.tiles.util.LocaleUtil;
-import org.apache.tiles.util.WildcardHelper;
/**
* <p>
@@ -52,7 +50,7 @@
* @since 2.1.0
*/
public class CachingLocaleUrlDefinitionDAO extends BaseLocaleUrlDefinitionDAO
- implements Refreshable {
+ implements Refreshable, PatternDefinitionResolverAware<Locale> {
/**
* Initialization parameter to set whether we want to refresh URLs when they
@@ -79,19 +77,11 @@
protected boolean checkRefresh = false;
/**
- * An object that helps in resolving definitions with wildcards.
+ * Resolves definitions using patterns.
*
- * @since 2.1.0
- */
- protected WildcardHelper wildcardHelper = new WildcardHelper();
-
- /**
- * Stores patterns depending on the locale they refer to.
- *
- * @since 2.1.0
+ * @since 2.2.0
*/
- protected Map<Locale, List<WildcardMapping>> localePatternPaths =
- new HashMap<Locale, List<WildcardMapping>>();
+ protected PatternDefinitionResolver<Locale> definitionResolver;
/**
* Constructor.
@@ -109,6 +99,13 @@
String param = params.get(CHECK_REFRESH_INIT_PARAMETER);
checkRefresh = "true".equals(param);
+ definitionResolver = new WildcardPatternDefinitionResolver<Locale>();
+ }
+
+ /** {@inheritDoc} */
+ public void setPatternDefinitionResolver(
+ PatternDefinitionResolver<Locale> definitionResolver) {
+ this.definitionResolver = definitionResolver;
}
/** {@inheritDoc} */
@@ -121,10 +118,9 @@
if (definitions != null) {
retValue = definitions.get(name);
- if (retValue == null
- && localePatternPaths.containsKey(customizationKey)) {
- retValue = resolveWildcardDefinition(localePatternPaths
- .get(customizationKey), name);
+ if (retValue == null) {
+ retValue = definitionResolver.resolveDefinition(name,
+ customizationKey);
if (retValue != null) {
try {
@@ -132,7 +128,8 @@
definitions.put(name, retValue);
}
} catch (NoSuchDefinitionException ex) {
- throw new IllegalStateException("Unable to resolve wildcard mapping", ex);
+ throw new IllegalStateException(
+ "Unable to resolve wildcard mapping", ex);
}
}
}
@@ -282,173 +279,6 @@
protected void postDefinitionLoadOperations(
Map<String, Definition> localeDefsMap, Locale customizationKey) {
- List<WildcardMapping> lpaths = localePatternPaths
- .get(customizationKey);
- if (lpaths == null) {
- lpaths = new ArrayList<WildcardMapping>();
- localePatternPaths.put(customizationKey, lpaths);
- }
-
- addWildcardPaths(lpaths, localeDefsMap);
- }
-
- /**
- * Adds wildcard paths that are stored inside a normal definition map.
- *
- * @param paths The list containing the currently stored paths.
- * @param defsMap The definition map to parse.
- * @since 2.1.0
- */
- protected void addWildcardPaths(List<WildcardMapping> paths,
- Map<String, Definition> defsMap) {
- for (Map.Entry<String, Definition> de : defsMap.entrySet()) {
- if (de.getKey().
- indexOf('*') != -1) {
- paths.add(new WildcardMapping(de.getKey(), de.getValue()));
- }
- }
- }
-
- /**
- * Try to resolve a wildcard definition.
- *
- * @param paths The list containing the currently stored paths.
- * @param name The name of the definition to resolve.
- * @return A definition, if found, or <code>null</code> if not.
- * @since 2.1.0
- */
- protected Definition resolveWildcardDefinition(
- List<WildcardMapping> paths, String name) {
- Map<Integer, String> vars = new HashMap<Integer, String>();
- Definition d = null;
-
- for (WildcardMapping wm : paths) {
- if (wildcardHelper.match(vars, name, wm.getPattern())) {
- d = replaceDefinition(wm.getDefinition(), name, vars);
- break;
- }
- }
-
- return d;
- }
-
- /**
- * Creates a definition given its representation with wildcards.
- *
- * @param d The definition to replace.
- * @param name The name of the definition to be created.
- * @param vars The variables to be substituted.
- * @return The definition that can be rendered.
- * @since 2.1.0
- */
- protected Definition replaceDefinition(Definition d, String name,
- Map<Integer, String> vars) {
- Definition nudef = new Definition();
-
- nudef.setExtends(replace(d.getExtends(), vars));
- nudef.setName(name);
- nudef.setPreparer(replace(d.getPreparer(), vars));
- nudef.setTemplateAttribute(replaceVarsInAttribute(d
- .getTemplateAttribute(), vars));
-
- Set<String> localAttributeNames = d.getLocalAttributeNames();
- if (localAttributeNames != null && !localAttributeNames.isEmpty()) {
- for (String attributeName : localAttributeNames) {
- Attribute attr = d.getLocalAttribute(attributeName);
- Attribute nuattr = replaceVarsInAttribute(attr, vars);
-
- nudef.putAttribute(replace(attributeName, vars), nuattr);
- }
- }
-
- return nudef;
- }
-
- /**
- * Replaces variables into an attribute.
- *
- * @param attr The attribute to be used as a basis, containing placeholders
- * for variables.
- * @param vars The variables to replace.
- * @return A new instance of an attribute, whose properties have been
- * replaced with variables' values.
- */
- private Attribute replaceVarsInAttribute(Attribute attr,
- Map<Integer, String> vars) {
- Attribute nuattr = new Attribute();
-
- nuattr.setRole(replace(attr.getRole(), vars));
- nuattr.setRenderer(attr.getRenderer());
- nuattr.setExpression(attr.getExpression());
-
- Object value = attr.getValue();
- if (value instanceof String) {
- value = replace((String) value, vars);
- }
- nuattr.setValue(value);
- return nuattr;
- }
-
- /**
- * Replaces a string with placeholders using values of a variable map.
- *
- * @param st The string to replace.
- * @param vars The variables.
- * @return The replaced string.
- * @since 2.1.0
- */
- protected String replace(String st, Map<Integer, String> vars) {
- return org.apache.tiles.util.WildcardHelper.convertParam(st, vars);
- }
-
- /**
- * Maps a pattern with a definition in cache.
- *
- * @since 2.1.0
- */
- protected class WildcardMapping {
-
- /**
- * The compiled pattern.
- */
- private int[] pattern;
-
- /**
- * The definition that matches the pattern.
- */
- private Definition definition;
-
- /**
- * Constructor.
- *
- * @param pattern The compiled pattern.
- * @param definition A definition that matches the pattern.
- *
- * @since 2.1.0
- */
- public WildcardMapping(String pattern, Definition definition) {
- this.pattern = wildcardHelper.compilePattern(pattern);
- this.definition = definition;
- }
-
- /**
- * Returns the definition.
- *
- * @return The definition.
- * @since 2.1.0
- */
- public Definition getDefinition() {
- return definition;
- }
-
- /**
- * Returns the compiled pattern.
- *
- * @return The pattern.
- * @since 2.1.0
- */
- public int[] getPattern() {
- return pattern;
- }
+ definitionResolver.storeDefinitionPatterns(localeDefsMap, customizationKey);
}
}
Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java?rev=784209&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java Fri Jun 12 17:29:42 2009
@@ -0,0 +1,57 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.pattern;
+
+import java.util.Map;
+
+import org.apache.tiles.Definition;
+
+/**
+ * Resolves a definition starting from patterns stored in definition maps.
+ *
+ * @param <T> The type of the customization key.
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
+public interface PatternDefinitionResolver<T> {
+
+ /**
+ * Stores definition patterns.
+ *
+ * @param localeDefsMap The map of definitions that may contain also patterns.
+ * @param customizationKey The customization key.
+ * @since 2.2.0
+ */
+ void storeDefinitionPatterns(Map<String, Definition> localeDefsMap,
+ T customizationKey);
+
+ /**
+ * Resolves a definition searching in all patterns for the requested
+ * customization key.
+ *
+ * @param name The name of the definition.
+ * @param customizationKey The customization key.
+ * @return The resolved definition.
+ * @since 2.2.0
+ */
+ Definition resolveDefinition(String name, T customizationKey);
+}
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolver.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java?rev=784209&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java Fri Jun 12 17:29:42 2009
@@ -0,0 +1,41 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.pattern;
+
+/**
+ * It indicates an object that uses a {@link PatternDefinitionResolver}.
+ *
+ * @param <T> The type of the customization key.
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
+public interface PatternDefinitionResolverAware<T> {
+
+ /**
+ * Sets the pattern definition resolver to use. If not set, the
+ * {@link WildcardPatternDefinitionResolver} will be used.
+ *
+ * @param definitionResolver The pattern definition resolver.
+ * @since 2.2.0
+ */
+ void setPatternDefinitionResolver(PatternDefinitionResolver<T> definitionResolver);
+}
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternDefinitionResolverAware.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java?rev=784209&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java Fri Jun 12 17:29:42 2009
@@ -0,0 +1,118 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.pattern;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.Set;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.Definition;
+
+/**
+ * Utilities for pattern matching and substitution.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
+public final class PatternUtil {
+
+ /**
+ * Private constructor to avoid instantiation.
+ */
+ private PatternUtil() {
+ }
+
+ /**
+ * Creates a definition given its representation with wildcards.
+ *
+ * @param d The definition to replace.
+ * @param name The name of the definition to be created.
+ * @param vars The variables to be substituted.
+ * @return The definition that can be rendered.
+ * @since 2.2.0
+ */
+ public static Definition replaceDefinition(Definition d, String name,
+ Object... vars) {
+ Definition nudef = new Definition();
+
+ nudef.setExtends(replace(d.getExtends(), vars));
+ nudef.setName(name);
+ nudef.setPreparer(replace(d.getPreparer(), vars));
+ nudef.setTemplateAttribute(replaceVarsInAttribute(d
+ .getTemplateAttribute(), vars));
+
+ Set<String> localAttributeNames = d.getLocalAttributeNames();
+ if (localAttributeNames != null && !localAttributeNames.isEmpty()) {
+ for (String attributeName : localAttributeNames) {
+ Attribute attr = d.getLocalAttribute(attributeName);
+ Attribute nuattr = replaceVarsInAttribute(attr, vars);
+
+ nudef.putAttribute(replace(attributeName, vars), nuattr);
+ }
+ }
+
+ return nudef;
+ }
+
+ /**
+ * Replaces a string with placeholders using values of a variable map.
+ *
+ * @param st The string to replace.
+ * @param vars The variables.
+ * @return The replaced string.
+ * @since 2.2.0
+ */
+ public static String replace(String st, Object... vars) {
+ if (st != null && st.indexOf('{') >= 0) {
+ MessageFormat format = new MessageFormat(st, Locale.ROOT);
+ return format.format(vars, new StringBuffer(), null).toString();
+ }
+ return st;
+ }
+
+ /**
+ * Replaces variables into an attribute.
+ *
+ * @param attr The attribute to be used as a basis, containing placeholders
+ * for variables.
+ * @param vars The variables to replace.
+ * @return A new instance of an attribute, whose properties have been
+ * replaced with variables' values.
+ * @since 2.2.0
+ */
+ public static Attribute replaceVarsInAttribute(Attribute attr,
+ Object... vars) {
+ Attribute nuattr = new Attribute();
+
+ nuattr.setRole(replace(attr.getRole(), vars));
+ nuattr.setRenderer(attr.getRenderer());
+ nuattr.setExpression(attr.getExpression());
+
+ Object value = attr.getValue();
+ if (value instanceof String) {
+ value = replace((String) value, vars);
+ }
+ nuattr.setValue(value);
+ return nuattr;
+ }
+}
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java?rev=784209&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java Fri Jun 12 17:29:42 2009
@@ -0,0 +1,170 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.pattern;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tiles.Definition;
+import org.apache.tiles.util.WildcardHelper;
+
+/**
+ * Uses wildcards syntax to match definition names and its parameters.
+ *
+ * @param <T> The type of the customization key.
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
+public class WildcardPatternDefinitionResolver<T> implements
+ PatternDefinitionResolver<T> {
+
+ /**
+ * Stores patterns depending on the locale they refer to.
+ *
+ * @since 2.2.0
+ */
+ private Map<T, List<WildcardMapping>> localePatternPaths =
+ new HashMap<T, List<WildcardMapping>>();
+
+ /**
+ * An object that helps in resolving definitions with wildcards.
+ *
+ * @since 2.2.0
+ */
+ private WildcardHelper wildcardHelper = new WildcardHelper();
+
+ /** {@inheritDoc} */
+ public Definition resolveDefinition(String name, T customizationKey) {
+ Definition retValue = null;
+ if (localePatternPaths.containsKey(customizationKey)) {
+ retValue = resolveWildcardDefinition(localePatternPaths
+ .get(customizationKey), name);
+ }
+ return retValue;
+ }
+
+ /** {@inheritDoc} */
+ public void storeDefinitionPatterns(Map<String, Definition> localeDefsMap,
+ T customizationKey) {
+ List<WildcardMapping> lpaths = localePatternPaths
+ .get(customizationKey);
+ if (lpaths == null) {
+ lpaths = new ArrayList<WildcardMapping>();
+ localePatternPaths.put(customizationKey, lpaths);
+ }
+
+ addWildcardPaths(lpaths, localeDefsMap);
+ }
+
+ /**
+ * Adds wildcard paths that are stored inside a normal definition map.
+ *
+ * @param paths The list containing the currently stored paths.
+ * @param defsMap The definition map to parse.
+ */
+ private void addWildcardPaths(List<WildcardMapping> paths,
+ Map<String, Definition> defsMap) {
+ for (Map.Entry<String, Definition> de : defsMap.entrySet()) {
+ if (de.getKey().
+ indexOf('*') != -1) {
+ paths.add(new WildcardMapping(de.getKey(), de.getValue()));
+ }
+ }
+ }
+
+ /**
+ * Try to resolve a wildcard definition.
+ *
+ * @param paths The list containing the currently stored paths.
+ * @param name The name of the definition to resolve.
+ * @return A definition, if found, or <code>null</code> if not.
+ */
+ private Definition resolveWildcardDefinition(
+ List<WildcardMapping> paths, String name) {
+ List<String> vars = new ArrayList<String>();
+ Definition d = null;
+
+ for (WildcardMapping wm : paths) {
+ if (wildcardHelper.match(vars, name, wm.getPattern())) {
+ d = PatternUtil.replaceDefinition(wm.getDefinition(), name, vars.toArray());
+ break;
+ } else {
+ vars.clear();
+ }
+ }
+
+ return d;
+ }
+
+ /**
+ * Maps a pattern with a definition in cache.
+ *
+ * @since 2.2.0
+ */
+ private class WildcardMapping {
+
+ /**
+ * The compiled pattern.
+ */
+ private int[] pattern;
+
+ /**
+ * The definition that matches the pattern.
+ */
+ private Definition definition;
+
+ /**
+ * Constructor.
+ *
+ * @param pattern The compiled pattern.
+ * @param definition A definition that matches the pattern.
+ *
+ * @since 2.2.0
+ */
+ public WildcardMapping(String pattern, Definition definition) {
+ this.pattern = wildcardHelper.compilePattern(pattern);
+ this.definition = definition;
+ }
+
+ /**
+ * Returns the definition.
+ *
+ * @return The definition.
+ * @since 2.2.0
+ */
+ public Definition getDefinition() {
+ return definition;
+ }
+
+ /**
+ * Returns the compiled pattern.
+ *
+ * @return The pattern.
+ * @since 2.2.0
+ */
+ public int[] getPattern() {
+ return pattern;
+ }
+ }
+}
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/pattern/WildcardPatternDefinitionResolver.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java?rev=784209&r1=784208&r2=784209&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java (original)
+++ tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java Fri Jun 12 17:29:42 2009
@@ -48,6 +48,7 @@
import org.apache.tiles.definition.MockDefinitionsReader;
import org.apache.tiles.definition.RefreshMonitor;
import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
+import org.apache.tiles.definition.pattern.WildcardPatternDefinitionResolver;
import org.easymock.EasyMock;
/**
@@ -61,7 +62,7 @@
* The time (in milliseconds) to wait to be sure that the system updates the
* modify date of a file.
*/
- private static final int SLEEP_MILLIS = 30000;
+ private static final int SLEEP_MILLIS = 2000;
/**
* The object to test.
@@ -73,6 +74,7 @@
protected void setUp() throws Exception {
super.setUp();
definitionDao = new CachingLocaleUrlDefinitionDAO();
+ definitionDao.setPatternDefinitionResolver(new WildcardPatternDefinitionResolver<Locale>());
}
/**
Modified: tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java?rev=784209&r1=784208&r2=784209&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java (original)
+++ tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java Fri Jun 12 17:29:42 2009
@@ -48,6 +48,7 @@
import org.apache.tiles.definition.MockDefinitionsReader;
import org.apache.tiles.definition.RefreshMonitor;
import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
+import org.apache.tiles.definition.pattern.WildcardPatternDefinitionResolver;
import org.easymock.EasyMock;
import junit.framework.TestCase;
@@ -75,6 +76,7 @@
protected void setUp() throws Exception {
super.setUp();
definitionDao = new ResolvingLocaleUrlDefinitionDAO();
+ definitionDao.setPatternDefinitionResolver(new WildcardPatternDefinitionResolver<Locale>());
}
/**
@@ -675,7 +677,7 @@
.createMock(TilesApplicationContext.class);
definitionDao.setReader(new DigesterDefinitionsReader());
EasyMock.replay(applicationContext);
-
+
Definition definition = definitionDao.getDefinition(
"test.inherit.list", Locale.ITALIAN);
ListAttribute listAttribute = (ListAttribute) definition