Author: apetrelli
Date: Tue Jun 24 12:22:13 2008
New Revision: 671310
URL: http://svn.apache.org/viewvc?rev=671310&view=rev
Log:
TILES-220
Applied a modified version of the patch posted by Cserveny Tamás.
Thanks a lot Cserveny!
Added a test case, copied code from Apache Struts 1 for the implementation of
the wildcard recognition.
Added:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java
(with props)
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml
(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
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=671310&r1=671309&r2=671310&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
Tue Jun 24 12:22:13 2008
@@ -23,14 +23,19 @@
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 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.util.LocaleUtil;
+import org.apache.tiles.util.WildcardHelper;
/**
* <p>
@@ -73,6 +78,21 @@
private boolean checkRefresh = false;
/**
+ * An object that helps in resolving definitions with wildcards.
+ *
+ * @since 2.1.0
+ */
+ protected WildcardHelper wildcardHelper = new WildcardHelper();
+
+ /**
+ * Stores patterns depending on the locale they refer to.
+ *
+ * @since 2.1.0
+ */
+ private Map<Locale, List<WildcardMapping>> localePatternPaths =
+ new HashMap<Locale, List<WildcardMapping>>();
+
+ /**
* Constructor.
*
* @since 2.1.0
@@ -93,9 +113,28 @@
/** [EMAIL PROTECTED] */
public Definition getDefinition(String name, Locale customizationKey) {
Definition retValue = null;
+ if (customizationKey == null) {
+ customizationKey = LocaleUtil.NULL_LOCALE;
+ }
Map<String, Definition> definitions = getDefinitions(customizationKey);
if (definitions != null) {
retValue = definitions.get(name);
+
+ if (retValue == null
+ && localePatternPaths.containsKey(customizationKey)) {
+ retValue = resolveWildcardDefinition(localePatternPaths
+ .get(customizationKey), name);
+
+ if (retValue != null) {
+ try {
+ synchronized (definitions) {
+ definitions.put(name, retValue);
+ }
+ } catch (NoSuchDefinitionException ex) {
+ throw new IllegalStateException("Unable to resolve
wildcard mapping", ex);
+ }
+ }
+ }
}
return retValue;
@@ -127,6 +166,7 @@
*
* @param checkRefresh When <code>true</code>, enables automatic checking
* of URLs changing.
+ * @since 2.1.0
*/
public void setCheckRefresh(boolean checkRefresh) {
this.checkRefresh = checkRefresh;
@@ -188,6 +228,156 @@
}
}
locale2definitionMap.put(customizationKey, localeDefsMap);
+
+ List<WildcardMapping> lpaths = localePatternPaths
+ .get(customizationKey);
+ if (lpaths == null) {
+ lpaths = new ArrayList<WildcardMapping>();
+ localePatternPaths.put(customizationKey, lpaths);
+ }
+
+ addWildcardPaths(lpaths, localeDefsMap);
return 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.setRole(replace(d.getRole(), vars));
+ nudef.setTemplate(replace(d.getTemplate(), vars));
+
+ for (String attributeName : d.getLocalAttributeNames()) {
+ Attribute attr = d.getLocalAttribute(attributeName);
+ Attribute nuattr = new Attribute();
+
+ nuattr.setRole(replace(attr.getRole(), vars));
+ nuattr.setRenderer(attr.getRenderer());
+
+ Object value = attr.getValue();
+ if (value instanceof String) {
+ value = replace((String) value, vars);
+ }
+ nuattr.setValue(value);
+
+ 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.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;
+ }
+ }
}
Added:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java?rev=671310&view=auto
==============================================================================
---
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java
(added)
+++
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java
Tue Jun 24 12:22:13 2008
@@ -0,0 +1,515 @@
+/*
+ * $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.util;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This class is an utility class that perform wilcard-patterns matching and
+ * isolation taken from Apache Struts that is taken, in turn, from Apache
+ * Struts.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public class WildcardHelper {
+ /**
+ * The int representing '*' in the pattern <code>int []</code>.
+ *
+ * @since 2.1.0
+ */
+ protected static final int MATCH_FILE = -1;
+
+ /**
+ * The int representing '**' in the pattern <code>int []</code>.
+ *
+ * @since 2.1.0
+ */
+ protected static final int MATCH_PATH = -2;
+
+ /**
+ * The int representing begin in the pattern <code>int []</code>.
+ *
+ * @since 2.1.0
+ */
+ protected static final int MATCH_BEGIN = -4;
+
+ /**
+ * The int representing end in pattern <code>int []</code>.
+ *
+ * @since 2.1.0
+ */
+ protected static final int MATCH_THEEND = -5;
+
+ /**
+ * The int value that terminates the pattern <code>int []</code>.
+ *
+ * @since 2.1.0
+ */
+ protected static final int MATCH_END = -3;
+
+ /**
+ * The length of the placeholder.
+ *
+ * @since 2.1.0
+ */
+ private static final int PLACEHOLDER_LENGTH = 3;
+
+ /**
+ * <p>
+ * Translate the given <code>String</code> into a <code>int []</code>
+ * representing the pattern matchable by this class. <br>
+ * This function translates a <code>String</code> into an int array
+ * converting the special '*' and '\' characters. <br>
+ * Here is how the conversion algorithm works:
+ * </p>
+ *
+ * <ul>
+ *
+ * <li>The '*' character is converted to MATCH_FILE, meaning that zero or
+ * more characters (excluding the path separator '/') are to be
matched.</li>
+ *
+ * <li>The '**' sequence is converted to MATCH_PATH, meaning that zero or
+ * more characters (including the path separator '/') are to be
matched.</li>
+ *
+ * <li>The '\' character is used as an escape sequence ('\*' is translated
+ * in '*', not in MATCH_FILE). If an exact '\' character is to be matched
+ * the source string must contain a '\\'. sequence.</li>
+ *
+ * </ul>
+ *
+ * <p>
+ * When more than two '*' characters, not separated by another character,
+ * are found their value is considered as '**' (MATCH_PATH). <br>
+ * The array is always terminated by a special value (MATCH_END). <br>
+ * All MATCH* values are less than zero, while normal characters are equal
+ * or greater.
+ * </p>
+ *
+ * @param data The string to translate.
+ * @return The encoded string as an int array, terminated by the MATCH_END
+ * value (don't consider the array length).
+ * @throws NullPointerException If data is null.
+ * @since 2.1.0
+ */
+ public int[] compilePattern(String data) {
+ // Prepare the arrays
+ int[] expr = new int[data.length() + 2];
+ char[] buff = data.toCharArray();
+
+ // Prepare variables for the translation loop
+ int y = 0;
+ boolean slash = false;
+
+ // Must start from beginning
+ expr[y++] = MATCH_BEGIN;
+
+ if (buff.length > 0) {
+ if (buff[0] == '\\') {
+ slash = true;
+ } else if (buff[0] == '*') {
+ expr[y++] = MATCH_FILE;
+ } else {
+ expr[y++] = buff[0];
+ }
+
+ // Main translation loop
+ for (int x = 1; x < buff.length; x++) {
+ // If the previous char was '\' simply copy this char.
+ if (slash) {
+ expr[y++] = buff[x];
+ slash = false;
+
+ // If the previous char was not '\' we have to do a bunch
of
+ // checks
+ } else {
+ // If this char is '\' declare that and continue
+ if (buff[x] == '\\') {
+ slash = true;
+
+ // If this char is '*' check the previous one
+ } else if (buff[x] == '*') {
+ // If the previous character als was '*' match a path
+ if (expr[y - 1] <= MATCH_FILE) {
+ expr[y - 1] = MATCH_PATH;
+ } else {
+ expr[y++] = MATCH_FILE;
+ }
+ } else {
+ expr[y++] = buff[x];
+ }
+ }
+ }
+ }
+
+ // Must match end at the end
+ expr[y] = MATCH_THEEND;
+
+ return expr;
+ }
+
+ /**
+ * Match a pattern agains a string and isolates wildcard replacement into a
+ * <code>Stack</code>.
+ *
+ * @param map The map to store matched values
+ * @param data The string to match
+ * @param expr The compiled wildcard expression
+ * @return True if a match
+ * @throws NullPointerException If any parameters are null
+ * @since 2.1.0
+ */
+ public boolean match(Map<Integer, String> map, String data, int[] expr) {
+ if (map == null) {
+ throw new NullPointerException("No map provided");
+ }
+
+ if (data == null) {
+ throw new NullPointerException("No data provided");
+ }
+
+ if (expr == null) {
+ throw new NullPointerException("No pattern expression provided");
+ }
+
+ char[] buff = data.toCharArray();
+
+ // Allocate the result buffer
+ char[] rslt = new char[expr.length + buff.length];
+
+ // The previous and current position of the expression character
+ // (MATCH_*)
+ int charpos = 0;
+
+ // The position in the expression, input, translation and result arrays
+ int exprpos = 0;
+ int buffpos = 0;
+ int rsltpos = 0;
+ int offset = -1;
+
+ // The matching count
+ int mcount = 0;
+
+ // We want the complete data be in {0}
+ map.put(mcount, data);
+
+ // First check for MATCH_BEGIN
+ boolean matchBegin = false;
+
+ if (expr[charpos] == MATCH_BEGIN) {
+ matchBegin = true;
+ exprpos = ++charpos;
+ }
+
+ // Search the fist expression character (except MATCH_BEGIN - already
+ // skipped)
+ while (expr[charpos] >= 0) {
+ charpos++;
+ }
+
+ // The expression charater (MATCH_*)
+ int exprchr = expr[charpos];
+
+ while (true) {
+ // Check if the data in the expression array before the current
+ // expression character matches the data in the input buffer
+ if (matchBegin) {
+ if (!matchArray(expr, exprpos, charpos, buff, buffpos)) {
+ return (false);
+ }
+
+ matchBegin = false;
+ } else {
+ offset = indexOfArray(expr, exprpos, charpos, buff, buffpos);
+
+ if (offset < 0) {
+ return (false);
+ }
+ }
+
+ // Check for MATCH_BEGIN
+ if (matchBegin) {
+ if (offset != 0) {
+ return (false);
+ }
+
+ matchBegin = false;
+ }
+
+ // Advance buffpos
+ buffpos += (charpos - exprpos);
+
+ // Check for END's
+ if (exprchr == MATCH_END) {
+ if (rsltpos > 0) {
+ map.put(++mcount, new String(rslt, 0, rsltpos));
+ }
+
+ // Don't care about rest of input buffer
+ return (true);
+ } else if (exprchr == MATCH_THEEND) {
+ if (rsltpos > 0) {
+ map.put(++mcount, new String(rslt, 0, rsltpos));
+ }
+
+ // Check that we reach buffer's end
+ return (buffpos == buff.length);
+ }
+
+ // Search the next expression character
+ exprpos = ++charpos;
+
+ while (expr[charpos] >= 0) {
+ charpos++;
+ }
+
+ int prevchr = exprchr;
+
+ exprchr = expr[charpos];
+
+ // We have here prevchr == * or **.
+ offset = (prevchr == MATCH_FILE) ? indexOfArray(expr, exprpos,
+ charpos, buff, buffpos) : lastIndexOfArray(expr, exprpos,
+ charpos, buff, buffpos);
+
+ if (offset < 0) {
+ return (false);
+ }
+
+ // Copy the data from the source buffer into the result buffer
+ // to substitute the expression character
+ if (prevchr == MATCH_PATH) {
+ while (buffpos < offset) {
+ rslt[rsltpos++] = buff[buffpos++];
+ }
+ } else {
+ // Matching file, don't copy '/'
+ while (buffpos < offset) {
+ if (buff[buffpos] == '/') {
+ return (false);
+ }
+
+ rslt[rsltpos++] = buff[buffpos++];
+ }
+ }
+
+ map.put(++mcount, new String(rslt, 0, rsltpos));
+ rsltpos = 0;
+ }
+ }
+
+ /**
+ * Get the offset of a part of an int array within a char array. <br>
+ * This method return the index in d of the first occurrence after dpos of
+ * that part of array specified by r, starting at rpos and terminating at
+ * rend.
+ *
+ * @param r The array containing the data that need to be matched in d.
+ * @param rpos The index of the first character in r to look for.
+ * @param rend The index of the last character in r to look for plus 1.
+ * @param d The array of char that should contain a part of r.
+ * @param dpos The starting offset in d for the matching.
+ * @return The offset in d of the part of r matched in d or -1 if that was
+ * not found.
+ * @since 2.1.0
+ */
+ protected int indexOfArray(int[] r, int rpos, int rend, char[] d, int
dpos) {
+ // Check if pos and len are legal
+ if (rend < rpos) {
+ throw new IllegalArgumentException("rend < rpos");
+ }
+
+ // If we need to match a zero length string return current dpos
+ if (rend == rpos) {
+ return (d.length); // ?? dpos?
+ }
+
+ // If we need to match a 1 char length string do it simply
+ if ((rend - rpos) == 1) {
+ // Search for the specified character
+ for (int x = dpos; x < d.length; x++) {
+ if (r[rpos] == d[x]) {
+ return (x);
+ }
+ }
+ }
+
+ // Main string matching loop. It gets executed if the characters to
+ // match are less then the characters left in the d buffer
+ while (((dpos + rend) - rpos) <= d.length) {
+ // Set current startpoint in d
+ int y = dpos;
+
+ // Check every character in d for equity. If the string is matched
+ // return dpos
+ for (int x = rpos; x <= rend; x++) {
+ if (x == rend) {
+ return (dpos);
+ }
+
+ if (r[x] != d[y++]) {
+ break;
+ }
+ }
+
+ // Increase dpos to search for the same string at next offset
+ dpos++;
+ }
+
+ // The remaining chars in d buffer were not enough or the string
+ // wasn't matched
+ return (-1);
+ }
+
+ /**
+ * Get the offset of a last occurance of an int array within a char array.
+ * <br>
+ * This method return the index in d of the last occurrence after dpos of
+ * that part of array specified by r, starting at rpos and terminating at
+ * rend.
+ *
+ * @param r The array containing the data that need to be matched in d.
+ * @param rpos The index of the first character in r to look for.
+ * @param rend The index of the last character in r to look for plus 1.
+ * @param d The array of char that should contain a part of r.
+ * @param dpos The starting offset in d for the matching.
+ * @return The offset in d of the last part of r matched in d or -1 if that
+ * was not found.
+ * @since 2.1.0
+ */
+ protected int lastIndexOfArray(int[] r, int rpos, int rend, char[] d,
+ int dpos) {
+ // Check if pos and len are legal
+ if (rend < rpos) {
+ throw new IllegalArgumentException("rend < rpos");
+ }
+
+ // If we need to match a zero length string return current dpos
+ if (rend == rpos) {
+ return (d.length); // ?? dpos?
+ }
+
+ // If we need to match a 1 char length string do it simply
+ if ((rend - rpos) == 1) {
+ // Search for the specified character
+ for (int x = d.length - 1; x > dpos; x--) {
+ if (r[rpos] == d[x]) {
+ return (x);
+ }
+ }
+ }
+
+ // Main string matching loop. It gets executed if the characters to
+ // match are less then the characters left in the d buffer
+ int l = d.length - (rend - rpos);
+
+ while (l >= dpos) {
+ // Set current startpoint in d
+ int y = l;
+
+ // Check every character in d for equity. If the string is matched
+ // return dpos
+ for (int x = rpos; x <= rend; x++) {
+ if (x == rend) {
+ return (l);
+ }
+
+ if (r[x] != d[y++]) {
+ break;
+ }
+ }
+
+ // Decrease l to search for the same string at next offset
+ l--;
+ }
+
+ // The remaining chars in d buffer were not enough or the string
+ // wasn't matched
+ return (-1);
+ }
+
+ /**
+ * Matches elements of array r from rpos to rend with array d, starting
from
+ * dpos. <br>
+ * This method return true if elements of array r from rpos to rend equals
+ * elements of array d starting from dpos to dpos+(rend-rpos).
+ *
+ * @param r The array containing the data that need to be matched in d.
+ * @param rpos The index of the first character in r to look for.
+ * @param rend The index of the last character in r to look for.
+ * @param d The array of char that should start from a part of r.
+ * @param dpos The starting offset in d for the matching.
+ * @return true if array d starts from portion of array r.
+ * @since 2.1.0
+ */
+ protected boolean matchArray(int[] r, int rpos, int rend, char[] d, int
dpos) {
+ if ((d.length - dpos) < (rend - rpos)) {
+ return (false);
+ }
+
+ for (int i = rpos; i < rend; i++) {
+ if (r[i] != d[dpos++]) {
+ return (false);
+ }
+ }
+
+ return (true);
+ }
+
+ /**
+ * <p>
+ * Inserts into a value wildcard-matched strings where specified.
+ * </p>
+ *
+ * @param val The value to convert
+ * @param vars A Map of wildcard-matched strings
+ * @return The new value
+ * @since 2.1.0
+ */
+ public static String convertParam(String val, Map<Integer, String> vars) {
+ if (val == null) {
+ return null;
+ } else if (val.indexOf("{") == -1) {
+ return val;
+ }
+
+ Map.Entry<Integer, String> entry;
+ StringBuffer key = new StringBuffer("{0}");
+ StringBuffer ret = new StringBuffer(val);
+ String keyTmp;
+ int x;
+
+ for (Iterator<Map.Entry<Integer, String>> i = vars.entrySet()
+ .iterator(); i.hasNext();) {
+ entry = i.next();
+ key.setCharAt(1, entry.getKey().toString().charAt(0));
+ keyTmp = key.toString();
+
+ // Replace all instances of the placeholder
+ while ((x = ret.toString().indexOf(keyTmp)) > -1) {
+ ret.replace(x, x + PLACEHOLDER_LENGTH, entry.getValue());
+ }
+ }
+
+ return ret.toString();
+ }
+}
Propchange:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/WildcardHelper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml?rev=671310&view=auto
==============================================================================
---
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml
(added)
+++
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml
Tue Jun 24 12:22:13 2008
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+/*
+ * $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.
+ */
+-->
+
+ <!DOCTYPE tiles-definitions PUBLIC
+ "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
+ "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
+
+<!-- Definitions for Tiles documentation -->
+
+<tiles-definitions>
+ <definition name="test.def3" template="/test.jsp">
+ <put-attribute name="title" value="Tiles Library Documentation" />
+ <put-attribute name="header" value="/common/header.jsp" />
+ <put-attribute name="menu" value="doc.menu.main" />
+ <put-attribute name="footer" value="/common/footer.jsp" />
+ <put-attribute name="body" value="doc.portal.body" />
+ </definition>
+ <definition name="test.def*.sub*" template="/test{1}.jsp">
+ <put-attribute name="country" value="default"/>
+ <put-attribute name="title" value="Tiles Library Documentation" />
+ <put-attribute name="header" value="/common/header{2}.jsp" />
+ <put-attribute name="menu" value="doc.menu.main" />
+ <put-attribute name="footer" value="/common/footer.jsp" />
+ <put-attribute name="body" value="doc.portal.body" />
+ </definition>
+
+</tiles-definitions>
Propchange:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/config/defs-wildcard.xml
------------------------------------------------------------------------------
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=671310&r1=671309&r2=671310&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
Tue Jun 24 12:22:13 2008
@@ -583,4 +583,32 @@
assertEquals("Factory should be stale.", true, reloadable
.refreshRequired());
}
+
+ /**
+ * Tests wildcard mappings.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testWildcardMapping() throws IOException {
+ URL url = this.getClass().getClassLoader().getResource(
+ "org/apache/tiles/config/defs-wildcard.xml");
+ definitionDao.addSourceURL(url);
+ TilesApplicationContext applicationContext = EasyMock
+ .createMock(TilesApplicationContext.class);
+ EasyMock.expect(applicationContext
+ .getResource("org/apache/tiles/config/defs-wildcard.xml"))
+ .andReturn(url);
+ EasyMock.replay(applicationContext);
+ ((TilesApplicationContextAware) definitionDao)
+ .setApplicationContext(applicationContext);
+ definitionDao.setReader(new DigesterDefinitionsReader());
+
+ Definition definition =
definitionDao.getDefinition("test.defName.subLayered", null);
+ assertEquals("The template is not correct", "/testName.jsp",
definition.getTemplate());
+ assertEquals("The header attribute is not correct",
+ "/common/headerLayered.jsp", definition.getAttribute("header")
+ .getValue());
+ definition = definitionDao.getDefinition("test.def3", null);
+ assertNotNull("The simple definition is null", definition);
+ }
}