You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2010/03/17 01:34:38 UTC

svn commit: r924074 [2/6] - in /wicket/trunk: testing/wicket-threadtest/src/main/java/org/apache/wicket/threadtest/ wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/filter/ wicket-guice/src/test/java/org/apac...

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/BooleanGroup.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/BooleanGroup.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/BooleanGroup.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/BooleanGroup.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,65 @@
+/*
+ * 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.util.parse.metapattern;
+
+import java.util.regex.Matcher;
+
+/**
+ * A Group that captures case-sensitive boolean values "true" or "false".
+ * 
+ * @author Jonathan Locke
+ */
+public final class BooleanGroup extends Group
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructs an IntegerGroup that parses Strings that match the INTEGER pattern in base 10.
+	 * 
+	 * @see MetaPattern#INTEGER
+	 */
+	public BooleanGroup()
+	{
+		super(new MetaPattern("true|false"));
+	}
+
+	/**
+	 * @param matcher
+	 *            The matcher
+	 * @return The value
+	 * @see BooleanGroup#getBoolean(java.util.regex.Matcher, boolean)
+	 */
+	public boolean getBoolean(final Matcher matcher)
+	{
+		return getBoolean(matcher, false);
+	}
+
+	/**
+	 * Gets a boolean by parsing the String matched by this capturing group.
+	 * 
+	 * @param matcher
+	 *            The matcher
+	 * @param defaultValue
+	 *            The default value to use if this group is omitted because it is optional
+	 * @return The parsed int value
+	 */
+	public boolean getBoolean(final Matcher matcher, final boolean defaultValue)
+	{
+		final String value = get(matcher);
+		return value == null ? defaultValue : value.equals("true");
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/FloatingPointGroup.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/FloatingPointGroup.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/FloatingPointGroup.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/FloatingPointGroup.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,90 @@
+/*
+ * 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.util.parse.metapattern;
+
+import java.util.regex.Matcher;
+
+/**
+ * A Group that captures floating point values (doubles and floats).
+ * 
+ * @author Jonathan Locke
+ */
+public final class FloatingPointGroup extends Group
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructs an FloatingPointGroup that parses Strings that match the FLOATING_POINT_NUMBER
+	 * pattern.
+	 * 
+	 * @see MetaPattern#FLOATING_POINT_NUMBER
+	 */
+	public FloatingPointGroup()
+	{
+		super(FLOATING_POINT_NUMBER);
+	}
+
+	/**
+	 * @param matcher
+	 *            The matcher
+	 * @return The value
+	 */
+	public float getFloat(final Matcher matcher)
+	{
+		return getFloat(matcher, -1);
+	}
+
+	/**
+	 * Gets float by parsing the String matched by this capturing group.
+	 * 
+	 * @param matcher
+	 *            The matcher
+	 * @param defaultValue
+	 *            The default value to use if this group is omitted because it is optional
+	 * @return The parsed value
+	 */
+	public float getFloat(final Matcher matcher, final float defaultValue)
+	{
+		final String value = get(matcher);
+		return value == null ? defaultValue : Float.parseFloat(value);
+	}
+
+	/**
+	 * @param matcher
+	 *            The matcher
+	 * @return The value
+	 */
+	public double getDouble(final Matcher matcher)
+	{
+		return getDouble(matcher, -1);
+	}
+
+	/**
+	 * Gets double by parsing the String matched by this capturing group.
+	 * 
+	 * @param matcher
+	 *            The matcher
+	 * @param defaultValue
+	 *            The default value to use if this group is omitted because it is optional
+	 * @return The parsed value
+	 */
+	public double getDouble(final Matcher matcher, final double defaultValue)
+	{
+		final String value = get(matcher);
+		return value == null ? defaultValue : Double.parseDouble(value);
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/Group.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/Group.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/Group.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/Group.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,92 @@
+/*
+ * 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.util.parse.metapattern;
+
+import java.util.regex.Matcher;
+
+/**
+ * A Group is a piece of a regular expression (referenced by some Java field or local variable) that
+ * forms a "capturing group" within the larger regular expression. A Group is bound to a regular
+ * expression MetaPattern when a matcher is retrieved for the pattern by calling one of the
+ * matcher() methods. Once bound, a Group cannot be rebound.
+ * 
+ * @author Jonathan Locke
+ */
+public class Group extends MetaPattern
+{
+	private static final long serialVersionUID = 1L;
+
+	/** The capturing group that this Group is bound to. */
+	private int group = -1;
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param pattern
+	 *            MetaPattern to capture
+	 */
+	public Group(final MetaPattern pattern)
+	{
+		super(pattern);
+	}
+
+	/**
+	 * Threadsafe method to retrieve contents of this captured group.
+	 * 
+	 * @param matcher
+	 *            The matcher from which to retrieve this Group's group
+	 * @return The captured characters
+	 */
+	public final String get(final Matcher matcher)
+	{
+		if (group == -1)
+		{
+			throw new GroupNotBoundException();
+		}
+
+		return matcher.group(group);
+	}
+
+	/**
+	 * @see java.lang.Object#toString()
+	 */
+	@Override
+	public String toString()
+	{
+		return "(" + super.toString() + ")";
+	}
+
+	/**
+	 * Binds this capture expression if not already bound.
+	 * 
+	 * @param bindTo
+	 *            The group to bind to
+	 * @throws GroupAlreadyBoundException
+	 *             Thrown if this Group is already bound
+	 */
+	final void bind(final int bindTo)
+	{
+		if (group == -1)
+		{
+			group = bindTo;
+		}
+		else
+		{
+			throw new GroupAlreadyBoundException();
+		}
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupAlreadyBoundException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupAlreadyBoundException.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupAlreadyBoundException.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupAlreadyBoundException.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.util.parse.metapattern;
+
+/**
+ * Thrown if an attempt is made to re-bind a Group to a second capturing group or MetaPattern.
+ * 
+ * @author Jonathan Locke
+ */
+public final class GroupAlreadyBoundException extends RuntimeException
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructor.
+	 */
+	public GroupAlreadyBoundException()
+	{
+		super();
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupNotBoundException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupNotBoundException.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupNotBoundException.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/GroupNotBoundException.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.util.parse.metapattern;
+
+/**
+ * Thrown if a group is not bound.
+ * 
+ * @author Jonathan Locke
+ */
+public final class GroupNotBoundException extends RuntimeException
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructor.
+	 */
+	public GroupNotBoundException()
+	{
+		super();
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/IntegerGroup.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/IntegerGroup.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/IntegerGroup.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/IntegerGroup.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,122 @@
+/*
+ * 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.util.parse.metapattern;
+
+import java.util.regex.Matcher;
+
+/**
+ * A Group that captures integer values (positive and negative whole numbers, not Java ints).
+ * 
+ * @author Jonathan Locke
+ */
+public final class IntegerGroup extends Group
+{
+	private static final long serialVersionUID = 1L;
+
+	/** The radix to use when converting Strings captured by this group. */
+	private final int radix;
+
+	/**
+	 * Constructs an IntegerGroup that parses Strings that match the INTEGER pattern in base 10.
+	 * 
+	 * @see MetaPattern#INTEGER
+	 */
+	public IntegerGroup()
+	{
+		this(INTEGER);
+	}
+
+	/**
+	 * Constructs an IntegerGroup that parses Strings that match the given pattern in base 10.
+	 * 
+	 * @param pattern
+	 *            The capturing pattern
+	 */
+	public IntegerGroup(final MetaPattern pattern)
+	{
+		this(pattern, 10);
+	}
+
+	/**
+	 * Constructs an IntegerGroup that parses Strings that match the given pattern in the given
+	 * radix.
+	 * 
+	 * @param pattern
+	 *            The capturing pattern
+	 * @param radix
+	 *            The radix to use when parsing captured Strings
+	 */
+	public IntegerGroup(final MetaPattern pattern, final int radix)
+	{
+		super(pattern);
+		this.radix = radix;
+	}
+
+	/**
+	 * @param matcher
+	 *            The matcher
+	 * @return The value
+	 * @see IntegerGroup#getInt(Matcher, int)
+	 */
+	public int getInt(final Matcher matcher)
+	{
+		return getInt(matcher, -1);
+	}
+
+	/**
+	 * Gets an int by parsing the String matched by this capturing group. The IntegerGroup's radix
+	 * is used in the conversion.
+	 * 
+	 * @param matcher
+	 *            The matcher
+	 * @param defaultValue
+	 *            The default value to use if this group is omitted because it is optional
+	 * @return The parsed int value
+	 */
+	public int getInt(final Matcher matcher, final int defaultValue)
+	{
+		final String value = get(matcher);
+		return value == null ? defaultValue : Integer.parseInt(value, radix);
+	}
+
+	/**
+	 * @param matcher
+	 *            The matcher
+	 * @return The value
+	 * @see IntegerGroup#getLong(Matcher)
+	 */
+	public long getLong(final Matcher matcher)
+	{
+		return getLong(matcher, -1L);
+	}
+
+	/**
+	 * Gets a long by parsing the String matched by this capturing group. The IntegerGroup's radix
+	 * is used in the conversion. parsing radix.
+	 * 
+	 * @param defaultValue
+	 *            The default value to use if this group is omitted because it is optional
+	 * @param matcher
+	 *            The matcher
+	 * @return The parsed long value
+	 */
+	public long getLong(final Matcher matcher, final long defaultValue)
+	{
+		final String value = get(matcher);
+		return value == null ? defaultValue : Long.parseLong(value, radix);
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/MetaPattern.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/MetaPattern.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/MetaPattern.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/MetaPattern.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,378 @@
+/*
+ * 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.util.parse.metapattern;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.IClusterable;
+
+
+/**
+ * Useful class for constructing readable and reusable regular expressions.
+ * <p>
+ * MetaPatterns can be constructed from a simple regular expression String, from other MetaPatterns
+ * (copy constructor), from a list of MetaPatterns or from an array of MetaPatterns. In this way, it
+ * is easy to build up larger patterns while transparently binding the capturing groups of each
+ * MetaPattern for easy object oriented access to capturing group matches.
+ * <p>
+ * A given MetaPattern can be converted to a Matcher or Pattern. Groups within the MetaPattern can
+ * be used to automatically reference capturing group values when a match is made with a Matcher
+ * object.
+ * <p>
+ * A variety of static constants are provided for use in constructing compound MetaPatterns. Also, a
+ * number of simple parsers have been constructed using MetaPatterns in the parsers subpackage.
+ * 
+ * @author Jonathan Locke
+ */
+public class MetaPattern implements IClusterable
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Compiled regular expression pattern, or null if patterns variable is valid instead
+	 */
+	private Pattern pattern;
+
+	/** List of patterns, or null if pattern variable is valid instead */
+	private List<MetaPattern> patterns;
+
+	/** The compiled MetaPattern */
+	private Pattern compiledPattern;
+
+	// Regexps that are used multiple times in defining meta patterns
+	private static final String _DOUBLE_QUOTED_STRING = "\"[^\"]*?\"";
+	private static final String _SINGLE_QUOTED_STRING = "'[^']*?\'";
+	private static final String _STRING = "(?:[\\w\\-\\.]+|" + _DOUBLE_QUOTED_STRING + "|" +
+		_SINGLE_QUOTED_STRING + ")";
+	private static final String _OPTIONAL_STRING = _STRING + "?";
+	private static final String _VARIABLE_NAME = "[A-Za-z_][A-Za-z0-9_]*";
+	private static final String _XML_NAME = "[A-Za-z_][A-Za-z0-9_.-]*";
+
+	// Delimiters and punctuation
+	/** Constant for whitespace. */
+	public static final MetaPattern WHITESPACE = new MetaPattern("\\s+");
+
+	/** Constant for optional whitespace. */
+	public static final MetaPattern OPTIONAL_WHITESPACE = new MetaPattern("\\s*");
+
+	/** Constant for non-word. */
+	public static final MetaPattern NON_WORD = new MetaPattern("\\W+");
+
+	/** Constant for comma. */
+	public static final MetaPattern COMMA = new MetaPattern(",");
+
+	/** Constant for colon. */
+	public static final MetaPattern COLON = new MetaPattern(":");
+
+	/** Constant for semicolon. */
+	public static final MetaPattern SEMICOLON = new MetaPattern(";");
+
+	/** Constant for slash. */
+	public static final MetaPattern SLASH = new MetaPattern("/");
+
+	/** Constant for backslash. */
+	public static final MetaPattern BACKSLASH = new MetaPattern("\\\\");
+
+	/** Constant for dot. */
+	public static final MetaPattern DOT = new MetaPattern("\\.");
+
+	/** Constant for plus. */
+	public static final MetaPattern PLUS = new MetaPattern("\\+");
+
+	/** Constant for minus. */
+	public static final MetaPattern MINUS = new MetaPattern("-");
+
+	/** Constant for dash. */
+	public static final MetaPattern DASH = new MetaPattern("-");
+
+	/** Constant for underscore. */
+	public static final MetaPattern UNDERSCORE = new MetaPattern("_");
+
+	/** Constant for ampersand. */
+	public static final MetaPattern AMPERSAND = new MetaPattern("&");
+
+	/** Constant for percent. */
+	public static final MetaPattern PERCENT = new MetaPattern("%");
+
+	/** Constant for dollar. */
+	public static final MetaPattern DOLLAR_SIGN = new MetaPattern("$");
+
+	/** Constant for pound. */
+	public static final MetaPattern POUND_SIGN = new MetaPattern("#");
+
+	/** Constant for at. */
+	public static final MetaPattern AT_SIGN = new MetaPattern("@");
+
+	/** Constant for excl. */
+	public static final MetaPattern EXCLAMATION_POINT = new MetaPattern("!");
+
+	/** Constant for tilde. */
+	public static final MetaPattern TILDE = new MetaPattern("~");
+
+	/** Constant for equals. */
+	public static final MetaPattern EQUALS = new MetaPattern("=");
+
+	/** Constant for star. */
+	public static final MetaPattern STAR = new MetaPattern("\\*");
+
+	/** Constant for pipe. */
+	public static final MetaPattern PIPE = new MetaPattern("\\|");
+
+	/** Constant for left paren. */
+	public static final MetaPattern LEFT_PAREN = new MetaPattern("\\(");
+
+	/** Constant for right paren. */
+	public static final MetaPattern RIGHT_PAREN = new MetaPattern("\\)");
+
+	/** Constant for left curly braces. */
+	public static final MetaPattern LEFT_CURLY = new MetaPattern("\\{");
+
+	/** Constant for right curly braces. */
+	public static final MetaPattern RIGHT_CURLY = new MetaPattern("\\}");
+
+	/** Constant for left square bracket. */
+	public static final MetaPattern LEFT_SQUARE = new MetaPattern("\\[");
+
+	/** Constant for right square bracket. */
+	public static final MetaPattern RIGHT_SQUARE = new MetaPattern("\\]");
+
+	/** Constant for digit. */
+	public static final MetaPattern DIGIT = new MetaPattern("\\d");
+
+	/** Constant for digits. */
+	public static final MetaPattern DIGITS = new MetaPattern("\\d+");
+
+	/** Constant for an integer (of any size). */
+	public static final MetaPattern INTEGER = new MetaPattern("-?\\d+");
+
+	/** Constant for a floating point number. */
+	public static final MetaPattern FLOATING_POINT_NUMBER = new MetaPattern(
+		"-?\\d+\\.?\\d*|-?\\.\\d+");
+
+	/** Constant for a positive integer. */
+	public static final MetaPattern POSITIVE_INTEGER = new MetaPattern("\\d+");
+
+	/** Constant for hex digit. */
+	public static final MetaPattern HEXADECIMAL_DIGIT = new MetaPattern("[0-9a-fA-F]");
+
+	/** Constant for hex digits. */
+	public static final MetaPattern HEXADECIMAL_DIGITS = new MetaPattern("[0-9a-fA-F]+");
+
+	/** Constant for anything (string). */
+	public static final MetaPattern ANYTHING = new MetaPattern(".*");
+
+	/** Constant for anything non-empty (string). */
+	public static final MetaPattern ANYTHING_NON_EMPTY = new MetaPattern(".+");
+
+	/** Constant for a word. */
+	public static final MetaPattern WORD = new MetaPattern("\\w+");
+
+	/** Constant for an optional word. */
+	public static final MetaPattern OPTIONAL_WORD = new MetaPattern("\\w*");
+
+	/** Constant for a variable name. */
+	public static final MetaPattern VARIABLE_NAME = new MetaPattern(_VARIABLE_NAME);
+
+	/** Constant for an XML element name. */
+	public static final MetaPattern XML_ELEMENT_NAME = new MetaPattern(_XML_NAME);
+
+	/** Constant for an XML attribute name. */
+	public static final MetaPattern XML_ATTRIBUTE_NAME = new MetaPattern(_XML_NAME);
+
+	/** Constant for perl interpolation. */
+	public static final MetaPattern PERL_INTERPOLATION = new MetaPattern("$\\{" + _VARIABLE_NAME +
+		"\\}");
+
+	/** Constant for a double quoted string. */
+	public static final MetaPattern DOUBLE_QUOTED_STRING = new MetaPattern(_DOUBLE_QUOTED_STRING);
+
+	/** Constant for a string. */
+	public static final MetaPattern STRING = new MetaPattern(_STRING);
+
+	/** Constant for an optional string. */
+	public static final MetaPattern OPTIONAL_STRING = new MetaPattern(_OPTIONAL_STRING);
+
+	/**
+	 * Constructor for a simple pattern.
+	 * 
+	 * @param pattern
+	 *            The regular expression pattern to compile
+	 */
+	public MetaPattern(final String pattern)
+	{
+		this.pattern = Pattern.compile(pattern);
+	}
+
+	/**
+	 * Copy constructor.
+	 * 
+	 * @param pattern
+	 *            The meta pattern to copy
+	 */
+	public MetaPattern(final MetaPattern pattern)
+	{
+		this.pattern = pattern.pattern;
+		patterns = pattern.patterns;
+		compiledPattern = pattern.compiledPattern;
+	}
+
+	/**
+	 * Constructs from an array of MetaPatterns.
+	 * 
+	 * @param patterns
+	 *            Array of MetaPatterns
+	 */
+	public MetaPattern(final MetaPattern... patterns)
+	{
+		this(Arrays.asList(patterns));
+	}
+
+	/**
+	 * Constructs from a list of MetaPatterns
+	 * 
+	 * @param patterns
+	 *            List of MetaPatterns
+	 */
+	public MetaPattern(final List<MetaPattern> patterns)
+	{
+		this.patterns = patterns;
+	}
+
+	/**
+	 * Creates a matcher against a given input character sequence.
+	 * 
+	 * @param input
+	 *            The input to match against
+	 * @return The matcher
+	 */
+	public final Matcher matcher(final CharSequence input)
+	{
+		return matcher(input, 0);
+	}
+
+	/**
+	 * Creates a matcher with the given regexp compile flags. Once you call this method with a given
+	 * regexp compile flag value, the pattern will be compiled. Calling it again with a different
+	 * value for flags will not recompile the pattern.
+	 * 
+	 * @param input
+	 *            The input to match
+	 * @param flags
+	 *            One or more of the standard Java regular expression compile flags (see
+	 *            {@link Pattern#compile(String, int)})
+	 * @return The matcher
+	 */
+	public final Matcher matcher(final CharSequence input, final int flags)
+	{
+		compile(flags);
+		return compiledPattern.matcher(input);
+	}
+
+	/**
+	 * Gets the regular expression Pattern for this MetaPattern by compiling it.
+	 * 
+	 * @return Pattern compiled with default Java regular expression compile flags
+	 */
+	public final Pattern pattern()
+	{
+		return pattern(0);
+	}
+
+	/**
+	 * Gets the regular expression Pattern for this MetaPattern by compiling it using the given
+	 * flags.
+	 * 
+	 * @param flags
+	 *            One or more of the standard Java regular expression compile flags (see
+	 *            {@link Pattern#compile(String, int)})
+	 * @return Equivalent Java regular expression Pattern compiled with the given flags
+	 */
+	public final Pattern pattern(final int flags)
+	{
+		compile(flags);
+		return compiledPattern;
+	}
+
+	/**
+	 * Converts this MetaPattern to a String.
+	 * 
+	 * @return A String representing this MetaPattern
+	 * @see java.lang.Object#toString()
+	 */
+	@Override
+	public String toString()
+	{
+		if (pattern != null)
+		{
+			return pattern.pattern();
+		}
+		else
+		{
+			final StringBuffer buffer = new StringBuffer();
+			for (int i = 0; i < patterns.size(); i++)
+			{
+				buffer.append(patterns.get(i));
+			}
+			return buffer.toString();
+		}
+	}
+
+	/**
+	 * Compiles this MetaPattern with the given Java regular expression flags.
+	 * 
+	 * @param flags
+	 *            One or more of the standard Java regular expression compile flags (see
+	 *            {@link Pattern#compile(String, int)})
+	 */
+	private synchronized void compile(final int flags)
+	{
+		if (compiledPattern == null)
+		{
+			bind(1);
+			compiledPattern = Pattern.compile(toString(), flags);
+		}
+	}
+
+	/**
+	 * Binds this MetaPattern to one or more capturing groups. Since MetaPatterns can nest, the
+	 * binding process can recurse.
+	 * 
+	 * @param group
+	 *            The initial capturing group number
+	 * @return The final capturing group (for use in recursion)
+	 */
+	private int bind(int group)
+	{
+		if (this instanceof Group)
+		{
+			((Group)this).bind(group++);
+		}
+
+		if (patterns != null)
+		{
+			for (int i = 0; i < patterns.size(); i++)
+			{
+				group = (patterns.get(i)).bind(group);
+			}
+		}
+
+		return group;
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/OptionalMetaPattern.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/OptionalMetaPattern.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/OptionalMetaPattern.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/OptionalMetaPattern.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.util.parse.metapattern;
+
+import java.util.List;
+
+/**
+ * Makes any MetaPattern optional by enclosing the pattern in an optionality expression. The
+ * expression will be something equivalent to "(?:&lt;pattern&gt;)?".
+ * 
+ * @author Jonathan Locke
+ */
+public final class OptionalMetaPattern extends MetaPattern
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param pattern
+	 */
+	public OptionalMetaPattern(final String pattern)
+	{
+		super(pattern);
+	}
+
+	/**
+	 * Constructor
+	 * 
+	 * @param pattern
+	 *            MetaPattern to make optional
+	 */
+	public OptionalMetaPattern(final MetaPattern pattern)
+	{
+		super(pattern);
+	}
+
+	/**
+	 * Constructor
+	 * 
+	 * @param patterns
+	 */
+	public OptionalMetaPattern(final List<MetaPattern> patterns)
+	{
+		super(patterns);
+	}
+
+	/**
+	 * Constructor
+	 * 
+	 * @param patterns
+	 */
+	public OptionalMetaPattern(final MetaPattern[] patterns)
+	{
+		super(patterns);
+	}
+
+	/**
+	 * @return String representation of this pattern
+	 */
+	@Override
+	public String toString()
+	{
+		return "(?:" + super.toString() + ")?";
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/package.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/package.html?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/package.html (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/package.html Wed Mar 17 00:34:34 2010
@@ -0,0 +1,27 @@
+<!--
+   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 HTML PUBLIC "-//W3C/DTD HTML 3.2 Final//NL">
+<html>
+<head>
+<title>wicket.util.parse.metapattern package</title>
+</head>
+<body>
+<p>
+Regular Expressions meta pattern support.
+</p>
+</body>
+</html>
\ No newline at end of file

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/CommaSeparatedVariableParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/CommaSeparatedVariableParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/CommaSeparatedVariableParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/CommaSeparatedVariableParser.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.util.parse.metapattern.parsers;
+
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+
+/**
+ * Parses out strings separated by commas.
+ * <p>
+ * Notes:
+ * <p>
+ * <ul>
+ * <li>It'll not trim the elements (it'll not remove whitespace)</li>
+ * <li>It is able to handle quotes like "a", 'b', "b,c" etc..</li>
+ * <li>But no escapes like "c\"d"</li>
+ * <li>Empty list elements like "a,," are not supported. It'll return the "a" only.</li>
+ * </ul>
+ * 
+ * @author Jonathan Locke
+ */
+public final class CommaSeparatedVariableParser extends ListParser
+{
+	/** Pattern to use. */
+	private static final MetaPattern patternEntry = new MetaPattern(new MetaPattern[] {
+			MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.STRING, MetaPattern.OPTIONAL_WHITESPACE });
+
+	/**
+	 * Construct a new parser with parameter 'input' to be parsed. Base classes provide the method
+	 * to access the elements of the input parsed.
+	 * 
+	 * @param input
+	 *            to parse
+	 */
+	public CommaSeparatedVariableParser(final CharSequence input)
+	{
+		super(patternEntry, MetaPattern.COMMA, input);
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/IntegerVariableAssignmentParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/IntegerVariableAssignmentParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/IntegerVariableAssignmentParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/IntegerVariableAssignmentParser.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,81 @@
+/*
+ * 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.util.parse.metapattern.parsers;
+
+import org.apache.wicket.util.parse.metapattern.Group;
+import org.apache.wicket.util.parse.metapattern.IntegerGroup;
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+
+/**
+ * Parses integer variable assignments, such as "x = 9" or "x=9".
+ * 
+ * @author Jonathan Locke
+ */
+public final class IntegerVariableAssignmentParser extends MetaPatternParser
+{
+	/** Parse "variable = &lt;number&gt;". */
+	private static final Group variable = new Group(MetaPattern.VARIABLE_NAME);
+
+	/** Group value. */
+	private static final IntegerGroup value = new IntegerGroup();
+
+	/** Meta pattern. */
+	private static final MetaPattern pattern = new MetaPattern(new MetaPattern[] { variable,
+			MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS, MetaPattern.OPTIONAL_WHITESPACE,
+			value });
+
+	/**
+	 * Construct.
+	 * 
+	 * @param input
+	 *            to parse
+	 */
+	public IntegerVariableAssignmentParser(final CharSequence input)
+	{
+		super(pattern, input);
+	}
+
+	/**
+	 * Gets the variable part (eg the 'x' from 'x = 9').
+	 * 
+	 * @return the variable part
+	 */
+	public String getVariable()
+	{
+		return variable.get(matcher());
+	}
+
+	/**
+	 * Gets the int part (eg the '9' from 'x = 9').
+	 * 
+	 * @return the int part.
+	 */
+	public int getIntValue()
+	{
+		return value.getInt(matcher());
+	}
+
+	/**
+	 * Gets the int part as a long.
+	 * 
+	 * @return the int part as a long
+	 */
+	public long getLongValue()
+	{
+		return value.getLong(matcher());
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/ListParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/ListParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/ListParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/ListParser.java Wed Mar 17 00:34:34 2010
@@ -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.util.parse.metapattern.parsers;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.util.parse.metapattern.Group;
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+
+
+/**
+ * Parses an arbitrary list format with a pattern for list entries and a pattern for list
+ * separators.
+ * 
+ * @author Jonathan Locke
+ */
+public class ListParser extends MetaPatternParser
+{
+	/** The pattern in between the separators */
+	private final Group entryGroup;
+
+	/** The separator */
+	private final MetaPattern separatorPattern;
+
+	/** The list elements parsed */
+	private final List<String> values = new ArrayList<String>();
+
+	/**
+	 * Constructs a list parser from an entry MetaPattern, a separator MetaPattern and an input
+	 * character sequence.
+	 * 
+	 * @param entryPattern
+	 *            The pattern in between the separators
+	 * @param separatorPattern
+	 *            The separator pattern
+	 * @param input
+	 *            The input to parse
+	 */
+	public ListParser(final MetaPattern entryPattern, final MetaPattern separatorPattern,
+		final CharSequence input)
+	{
+		super(input);
+		entryGroup = new Group(entryPattern);
+		this.separatorPattern = separatorPattern;
+	}
+
+	/**
+	 * Parse the input and add the elements to an internal list to be accessed by
+	 * 
+	 * @see #getValues()
+	 * @see org.apache.wicket.util.parse.metapattern.parsers.MetaPatternParser#matches()
+	 */
+	@Override
+	public final boolean matches()
+	{
+		// Are there any more elements
+		if (advance(entryGroup))
+		{
+			// Add the first element
+			final String value = entryGroup.get(matcher());
+			values.add(value);
+
+			// All remaining elements must be preceded by the separator pattern
+			while (advance(separatorPattern) && advance(entryGroup))
+			{
+				// Add the value not including the separator
+				values.add(entryGroup.get(matcher()));
+			}
+
+			// Yes, we found at least on element
+			return true;
+		}
+
+		// Nothing found, not even one element without separator
+		return false;
+	}
+
+	/**
+	 * Gets the parsed values. It depends on the elements pattern, whether empty elements, double or
+	 * single quotes or escape characters are supported.
+	 * 
+	 * @return the parsed values
+	 */
+	public final List<String> getValues()
+	{
+		return values;
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/MetaPatternParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/MetaPatternParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/MetaPatternParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/MetaPatternParser.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,140 @@
+/*
+ * 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.util.parse.metapattern.parsers;
+
+import java.util.regex.Matcher;
+
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+
+
+/**
+ * Base class for various MetaPattern based parsers.
+ * 
+ * @author Jonathan Locke
+ */
+public abstract class MetaPatternParser
+{
+	/** The input to parse */
+	private final CharSequence input;
+
+	/** The length of the input; no. of characters */
+	private final int length;
+
+	/**
+	 * The position (index) behind the last pattern group matched while advancing from one pattern
+	 * group to the next one.
+	 */
+	private int pos;
+
+	/** The object maintaining all the regex match details */
+	private Matcher matcher;
+
+	/**
+	 * Construct the parser. You must call
+	 * 
+	 * @see #advance(MetaPattern) to initialize the matcher with the pattern.
+	 * @param input
+	 *            to parse
+	 */
+	public MetaPatternParser(final CharSequence input)
+	{
+		this.input = input;
+		length = input.length();
+	}
+
+	/**
+	 * Construct the parser and initialize the matcher with the pattern given.
+	 * 
+	 * @param pattern
+	 *            Meta pattern
+	 * @param input
+	 *            Input to parse
+	 */
+	public MetaPatternParser(final MetaPattern pattern, final CharSequence input)
+	{
+		this(input);
+		setPattern(pattern);
+	}
+
+	/**
+	 * @param pattern
+	 *            Pattern
+	 */
+	public void setPattern(final MetaPattern pattern)
+	{
+		matcher = pattern.matcher(input);
+	}
+
+	/**
+	 * Advance parsing to the next element. The internal cursor will be moved to end of the string
+	 * matched.
+	 * 
+	 * @param pattern
+	 *            Meta pattern
+	 * @return True if found, false otherwise
+	 */
+	protected final boolean advance(final MetaPattern pattern)
+	{
+		// get the remaining part of the input
+		final CharSequence s = input.subSequence(pos, length);
+
+		// does the pattern match?
+		matcher = pattern.matcher(s);
+		if (matcher.lookingAt())
+		{
+			// Yes, it does. Move the cursor to the end of the
+			// char sequence matched.
+			pos += matcher.end();
+
+			// Found the pattern
+			return true;
+		}
+
+		// Did not find the pattern.
+		return false;
+	}
+
+	/**
+	 * Whether the matcher matches the pattern.
+	 * 
+	 * @return whether the matcher matches
+	 */
+	public boolean matches()
+	{
+		return matcher.matches();
+	}
+
+	/**
+	 * Gets the matcher.
+	 * 
+	 * @return the matcher
+	 */
+	public final Matcher matcher()
+	{
+		return matcher;
+	}
+
+	/**
+	 * Whether the internal cursor has advanced to the end of the input.
+	 * 
+	 * @return whether the input is parsed
+	 */
+	public final boolean atEnd()
+	{
+		return pos == length;
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/TagNameParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/TagNameParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/TagNameParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/TagNameParser.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,79 @@
+/*
+ * 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.util.parse.metapattern.parsers;
+
+import org.apache.wicket.util.parse.metapattern.Group;
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+import org.apache.wicket.util.parse.metapattern.OptionalMetaPattern;
+
+/**
+ * Parses XML tag names and attribute names which may include optional namespaces like
+ * "namespace:name" or "name". Both ":name" and "namespace:" are not allowed. Both, the namespace
+ * and the name have to follow naming rules for variable names (identifier).
+ * 
+ * @author Jonathan Locke
+ * @author Juergen Donnerstag
+ */
+public final class TagNameParser extends MetaPatternParser
+{
+	/** Namespaces must comply with variable name guidelines */
+	private static final Group namespaceGroup = new Group(MetaPattern.VARIABLE_NAME);
+
+	/** Tag names must comply with XML NCName guidelines */
+	private static final Group nameGroup = new Group(MetaPattern.XML_ELEMENT_NAME);
+
+	/** Pattern for tag names with optional namespace: (namespace:)?name */
+	private static final MetaPattern pattern = new MetaPattern(new MetaPattern[] {
+			new OptionalMetaPattern(new MetaPattern[] { namespaceGroup, MetaPattern.COLON }),
+			nameGroup });
+
+	/**
+	 * Constructs a tag name parser for a given input character sequence.
+	 * 
+	 * @param input
+	 *            The input to parse
+	 */
+	public TagNameParser(final CharSequence input)
+	{
+		super(pattern, input);
+	}
+
+	/**
+	 * Get the namespace part (eg 'html' in 'html:form') converted to all lower case characters.
+	 * 
+	 * @return the namespace part. Will be null, if optional namespace was not found
+	 */
+	public String getNamespace()
+	{
+		final String namespace = namespaceGroup.get(matcher());
+		if (namespace != null)
+		{
+			return namespace.toLowerCase();
+		}
+		return namespace;
+	}
+
+	/**
+	 * Gets the tag name part (eg 'form' in 'html:form' or 'form')
+	 * 
+	 * @return the name part
+	 */
+	public String getName()
+	{
+		return nameGroup.get(matcher());
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/VariableAssignmentParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/VariableAssignmentParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/VariableAssignmentParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/VariableAssignmentParser.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,99 @@
+/*
+ * 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.util.parse.metapattern.parsers;
+
+import org.apache.wicket.util.parse.metapattern.Group;
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+import org.apache.wicket.util.parse.metapattern.OptionalMetaPattern;
+
+/**
+ * Parses key value assignment statements like "foo=bar" but also supporting namespaces like
+ * "wicket:foo=bar". However the 'key' value returned will contain "wicket:foo". It does not
+ * separate namespace and name.
+ * 
+ * @author Jonathan Locke
+ */
+public final class VariableAssignmentParser extends MetaPatternParser
+{
+	/** The optional namespace like "namespace:*" */
+	private static final MetaPattern namespace = new OptionalMetaPattern(new MetaPattern[] {
+			MetaPattern.VARIABLE_NAME, MetaPattern.COLON });
+
+	/** The key (lvalue) like "name" or "namespace:name" */
+	private final Group key = new Group(new MetaPattern(new MetaPattern[] { namespace,
+			MetaPattern.XML_ATTRIBUTE_NAME }));
+
+	/** The rvalue of the assignment */
+	private final Group value;
+
+	/**
+	 * Construct a variable assignment parser against a given input character sequence
+	 * 
+	 * @param input
+	 *            The input to parse
+	 */
+	public VariableAssignmentParser(final CharSequence input)
+	{
+		this(input, MetaPattern.STRING);
+	}
+
+	/**
+	 * Construct a variable assignment parser against a given input character sequence
+	 * 
+	 * @param input
+	 *            The input to parse
+	 * @param valuePattern
+	 *            Value pattern
+	 */
+	public VariableAssignmentParser(final CharSequence input, final MetaPattern valuePattern)
+	{
+		super(input);
+
+		// Create group for value pattern
+		value = new Group(valuePattern);
+
+		// Pattern for =<value>
+		final MetaPattern variableAssignment = new MetaPattern(new MetaPattern[] {
+				MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.EQUALS,
+				MetaPattern.OPTIONAL_WHITESPACE, value });
+
+		// Set parse pattern to <key>=<value>?
+		setPattern(new MetaPattern(new MetaPattern[] { MetaPattern.OPTIONAL_WHITESPACE, key,
+				new OptionalMetaPattern(variableAssignment), MetaPattern.OPTIONAL_WHITESPACE }));
+	}
+
+	/**
+	 * Gets the key part (eg 'foo' in 'foo=bar'). The key will include the optional namespace (eg
+	 * 'html:foo' in 'html:foo=bar').
+	 * 
+	 * @return The key part
+	 */
+	public String getKey()
+	{
+		return key.get(matcher());
+	}
+
+	/**
+	 * Gets the value part (eg 'bar' in 'foo=bar').
+	 * 
+	 * @return The value part
+	 */
+	public String getValue()
+	{
+		return value.get(matcher());
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/WordParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/WordParser.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/WordParser.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/WordParser.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.util.parse.metapattern.parsers;
+
+import org.apache.wicket.util.parse.metapattern.Group;
+import org.apache.wicket.util.parse.metapattern.MetaPattern;
+
+/**
+ * Matches a 'word' surrounded by whitespace. See <a
+ * href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html"
+ * >java.util.regex.Pattern </a> for more details on what 'word' means.
+ * 
+ * @author Jonathan Locke
+ */
+public final class WordParser extends MetaPatternParser
+{
+	/**
+	 * Make it a group to be able to access the word without surrounding whitespace
+	 */
+	private static final Group word = new Group(MetaPattern.WORD);
+
+	/** Parse word surrounded by whitespace */
+	private static final MetaPattern wordPattern = new MetaPattern(new MetaPattern[] {
+			MetaPattern.OPTIONAL_WHITESPACE, word, MetaPattern.OPTIONAL_WHITESPACE });
+
+	/**
+	 * Construct.
+	 * 
+	 * @param input
+	 *            to parse
+	 */
+	public WordParser(final CharSequence input)
+	{
+		super(wordPattern, input);
+	}
+
+	/**
+	 * Gets the word including the optional whitespace surrounding the word.
+	 * 
+	 * @return the word surrounded by whitespace
+	 */
+	public String getWord()
+	{
+		return word.get(matcher());
+	}
+}

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/package.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/package.html?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/package.html (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/parse/metapattern/parsers/package.html Wed Mar 17 00:34:34 2010
@@ -0,0 +1,27 @@
+<!--
+   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 HTML PUBLIC "-//W3C/DTD HTML 3.2 Final//NL">
+<html>
+<head>
+<title>wicket.util.parse.metapattern.parsers package</title>
+</head>
+<body>
+<p>
+Regular Expressions meta pattern parsers.
+</p>
+</body>
+</html>
\ No newline at end of file

Added: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/string/AbstractStringList.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/string/AbstractStringList.java?rev=924074&view=auto
==============================================================================
--- wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/string/AbstractStringList.java (added)
+++ wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/string/AbstractStringList.java Wed Mar 17 00:34:34 2010
@@ -0,0 +1,198 @@
+/*
+ * 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.util.string;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An abstract base class for string list implementations. Besides having an implementation for
+ * IStringSequence (iterator(), get(int index) and size()), an AbstractStringList can be converted
+ * to a String array or a List of Strings.
+ * <p>
+ * The total length of all Strings in the list can be determined by calling totalLength().
+ * <p>
+ * Strings or a subset of Strings in the list can be formatted using three join() methods:
+ * <p>
+ * <ul>
+ * <li>join(String) Joins strings together using a given separator
+ * <li>join() Joins Strings using comma as a separator
+ * <li>join(int first, int last, String) Joins a sublist of strings using a given separator
+ * </ul>
+ * 
+ * @author Jonathan Locke
+ */
+public abstract class AbstractStringList implements IStringSequence, Serializable
+{
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * @return String iterator
+	 * @see org.apache.wicket.util.string.IStringSequence#iterator()
+	 */
+	public abstract IStringIterator iterator();
+
+	/**
+	 * @return Number of strings in this string list
+	 * @see org.apache.wicket.util.string.IStringSequence#size()
+	 */
+	public abstract int size();
+
+	/**
+	 * @param index
+	 *            The index into this string list
+	 * @return The string at the given index
+	 * @see org.apache.wicket.util.string.IStringSequence#get(int)
+	 */
+	public abstract String get(int index);
+
+	/**
+	 * Returns this String sequence as an array of Strings. Subclasses may provide a more efficient
+	 * implementation than the one provided here.
+	 * 
+	 * @return An array containing exactly this sequence of Strings
+	 */
+	public String[] toArray()
+	{
+		// Get number of Strings
+		final int size = size();
+
+		// Allocate array
+		final String[] strings = new String[size];
+
+		// Copy string references
+		for (int i = 0; i < size; i++)
+		{
+			strings[i] = get(i);
+		}
+
+		return strings;
+	}
+
+	/**
+	 * Returns this String sequence as an array of Strings. Subclasses may provide a more efficient
+	 * implementation than the one provided here.
+	 * 
+	 * @return An array containing exactly this sequence of Strings
+	 */
+	public final List<String> toList()
+	{
+		// Get number of Strings
+		final int size = size();
+
+		// Allocate list of exactly the right size
+		final List<String> strings = new ArrayList<String>(size);
+
+		// Add strings to list
+		for (int i = 0; i < size; i++)
+		{
+			strings.add(get(i));
+		}
+
+		return strings;
+	}
+
+	/**
+	 * @return The total length of all Strings in this sequence.
+	 */
+	public int totalLength()
+	{
+		// Get number of Strings
+		final int size = size();
+
+		// Add strings to list
+		int totalLength = 0;
+
+		for (int i = 0; i < size; i++)
+		{
+			totalLength += get(i).length();
+		}
+
+		return totalLength;
+	}
+
+	/**
+	 * Joins this sequence of strings using a comma separator. For example, if this sequence
+	 * contains [1 2 3], the result of calling this method will be "1, 2, 3".
+	 * 
+	 * @return The joined String
+	 */
+	public final String join()
+	{
+		return join(", ");
+	}
+
+	/**
+	 * Joins this sequence of strings using a separator
+	 * 
+	 * @param separator
+	 *            The separator to use
+	 * @return The joined String
+	 */
+	public final String join(final String separator)
+	{
+		return join(0, size(), separator);
+	}
+
+	/**
+	 * Joins this sequence of strings from first index to last using a separator
+	 * 
+	 * @param first
+	 *            The first index to use, inclusive
+	 * @param last
+	 *            The last index to use, exclusive
+	 * @param separator
+	 *            The separator to use
+	 * @return The joined String
+	 */
+	public final String join(final int first, final int last, final String separator)
+	{
+		// Allocate buffer of exactly the right length
+		final int length = totalLength() + (separator.length() * (Math.max(0, last - first - 1)));
+		final AppendingStringBuffer buf = new AppendingStringBuffer(length);
+
+		// Loop through indexes requested
+		for (int i = first; i < last; i++)
+		{
+			// Add next string
+			buf.append(get(i));
+
+			// Add separator?
+			if (i != (last - 1))
+			{
+				buf.append(separator);
+			}
+		}
+
+		return buf.toString();
+	}
+
+	/**
+	 * Converts this object to a string representation
+	 * 
+	 * @return String version of this object
+	 */
+	@Override
+	public String toString()
+	{
+		return "[" + join() + "]";
+	}
+}

Propchange: wicket/trunk/wicket-util/src/main/java/org/apache/wicket/util/string/AbstractStringList.java
------------------------------------------------------------------------------
    svn:executable = *