You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/10/22 16:07:14 UTC

svn commit: r828704 - in /wicket/trunk/wicket/src: main/java/org/apache/wicket/markup/ main/java/org/apache/wicket/markup/parser/ main/java/org/apache/wicket/markup/parser/filter/ test/java/org/apache/wicket/markup/ test/java/org/apache/wicket/markup/h...

Author: jdonnerstag
Date: Thu Oct 22 14:07:13 2009
New Revision: 828704

URL: http://svn.apache.org/viewvc?rev=828704&view=rev
Log:
fixed Improve consistency of ParseException error messages
Issue: WICKET-2535

Added:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/WicketParseException.java
Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlPullParser.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlTag.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlProblemFinder.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketRemoveTagHandler.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupParserTest.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/WicketParseException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/WicketParseException.java?rev=828704&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/WicketParseException.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/WicketParseException.java Thu Oct 22 14:07:13 2009
@@ -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.markup;
+
+import java.text.ParseException;
+
+import org.apache.wicket.markup.parser.XmlTag;
+
+/**
+ * 
+ * @author Juergen Donnerstag
+ */
+public class WicketParseException extends ParseException
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param message
+	 * @param tag
+	 */
+	public WicketParseException(final String message, final XmlTag tag)
+	{
+		super(message + tag.toUserDebugString(), tag.getPos());
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param message
+	 * @param tag
+	 */
+	public WicketParseException(final String message, final ComponentTag tag)
+	{
+		this(message, tag.xmlTag);
+	}
+}

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlPullParser.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlPullParser.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlPullParser.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlPullParser.java Thu Oct 22 14:07:13 2009
@@ -151,8 +151,8 @@
 			pos = input.find("</", pos + 1);
 			if ((pos == -1) || ((pos + (tagNameLen + 2)) >= input.size()))
 			{
-				throw new ParseException(skipUntilText + " tag not closed (line " +
-					input.getLineNumber() + ", column " + input.getColumnNumber() + ")", startIndex);
+				throw new ParseException(
+					skipUntilText + " tag not closed" + getLineAndColumnText(), startIndex);
 			}
 
 			lastPos = pos + 2;
@@ -167,8 +167,7 @@
 		lastPos = input.find('>', lastPos + tagNameLen);
 		if (lastPos == -1)
 		{
-			throw new ParseException("Script tag not closed (line " + input.getLineNumber() +
-				", column " + input.getColumnNumber() + ")", startIndex);
+			throw new ParseException("Script tag not closed" + getLineAndColumnText(), startIndex);
 		}
 
 		// Reset the state variable
@@ -176,6 +175,15 @@
 	}
 
 	/**
+	 * 
+	 * @return line and column number
+	 */
+	private String getLineAndColumnText()
+	{
+		return " (line " + input.getLineNumber() + ", column " + input.getColumnNumber() + ")";
+	}
+
+	/**
 	 * @return XXX
 	 * @throws ParseException
 	 */
@@ -221,7 +229,7 @@
 		int closeBracketIndex = input.find('>', openBracketIndex + 1);
 		if (closeBracketIndex == -1)
 		{
-			throw new ParseException("No matching close bracket at position " + openBracketIndex,
+			throw new ParseException("No matching close bracket at" + getLineAndColumnText(),
 				input.getPosition());
 		}
 
@@ -232,7 +240,7 @@
 		String tagText = lastText.subSequence(1, lastText.length() - 1).toString();
 		if (tagText.length() == 0)
 		{
-			throw new ParseException("Found empty tag: '<>' at position " + openBracketIndex,
+			throw new ParseException("Found empty tag: '<>' at" + getLineAndColumnText(),
 				input.getPosition());
 		}
 
@@ -303,8 +311,7 @@
 		}
 		else
 		{
-			throw new ParseException("Malformed tag (line " + input.getLineNumber() + ", column " +
-				input.getColumnNumber() + ")", openBracketIndex);
+			throw new ParseException("Malformed tag" + getLineAndColumnText(), openBracketIndex);
 		}
 	}
 
@@ -329,8 +336,8 @@
 			int pos = input.find("-->", openBracketIndex + 1);
 			if (pos == -1)
 			{
-				throw new ParseException("Unclosed comment beginning at line:" +
-					input.getLineNumber() + " column:" + input.getColumnNumber(), openBracketIndex);
+				throw new ParseException("Unclosed comment beginning at" + getLineAndColumnText(),
+					openBracketIndex);
 			}
 
 			pos += 3;
@@ -378,9 +385,8 @@
 
 					if (closeBracketIndex == -1)
 					{
-						throw new ParseException("No matching close bracket at line:" +
-							input.getLineNumber() + " column:" + input.getColumnNumber(),
-							input.getPosition());
+						throw new ParseException("No matching close bracket at" +
+							getLineAndColumnText(), input.getPosition());
 					}
 
 					// Get the tagtext between open and close brackets
@@ -654,8 +660,8 @@
 				// Put the attribute in the attributes hash
 				if (null != ((TagAttributes)tag.getAttributes()).putInternal(key, value))
 				{
-					throw new ParseException("Same attribute found twice: " + key,
-						input.getPosition());
+					throw new ParseException("Same attribute found twice: " + key +
+						getLineAndColumnText(), input.getPosition());
 				}
 
 				// The input has to match exactly (no left over junk after

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlTag.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlTag.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlTag.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/XmlTag.java Thu Oct 22 14:07:13 2009
@@ -616,7 +616,7 @@
 	@Override
 	public String toUserDebugString()
 	{
-		return "'" + toString() + "' (line " + lineNumber + ", column " + columnNumber + ")";
+		return " '" + toString() + "' (line " + lineNumber + ", column " + columnNumber + ")";
 	}
 
 	/**

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/EnclosureHandler.java Thu Oct 22 14:07:13 2009
@@ -23,6 +23,7 @@
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupElement;
 import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.WicketParseException;
 import org.apache.wicket.markup.WicketTag;
 import org.apache.wicket.markup.html.internal.Enclosure;
 import org.apache.wicket.markup.resolver.IComponentResolver;
@@ -96,8 +97,7 @@
 			{
 				if (stack == null)
 				{
-					throw new ParseException("Missing open tag for Enclosure: " + tag.toString(),
-						tag.getPos());
+					throw new WicketParseException("Missing open tag for Enclosure:", tag);
 				}
 
 				// Remove the open tag from the stack
@@ -119,8 +119,7 @@
 			}
 			else
 			{
-				throw new ParseException("Open-close tag not allowed for Enclosure: " +
-					tag.toString(), tag.getPos());
+				throw new WicketParseException("Open-close tag not allowed for Enclosure:", tag);
 			}
 		}
 		// Are we inside a wicket:enclosure tag?
@@ -137,9 +136,8 @@
 				// isVisible() to => Exception
 				if (childId != null)
 				{
-					throw new ParseException(
-						"Use <wicket:enclosure child='xxx'> to name the child component",
-						tag.getPos());
+					throw new WicketParseException(
+						"Use <wicket:enclosure child='xxx'> to name the child component:", tag);
 				}
 				// Remember the child id. The open tag will be updated
 				// once the close tag is found. See above.

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java Thu Oct 22 14:07:13 2009
@@ -22,6 +22,7 @@
 
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.WicketParseException;
 import org.apache.wicket.markup.parser.AbstractMarkupFilter;
 import org.apache.wicket.util.collections.ArrayListStack;
 import org.slf4j.Logger;
@@ -85,8 +86,7 @@
 				}
 				else
 				{
-					throw new ParseException("Tag " + top + " at " + top.getPos() +
-						" did not have a close tag", top.getPos());
+					throw new WicketParseException("Tag does not have a close tag:", top);
 				}
 			}
 
@@ -151,8 +151,7 @@
 			}
 			else
 			{
-				throw new ParseException("Tag " + tag.toUserDebugString() +
-					" does not have a matching open tag", tag.getPos());
+				throw new WicketParseException("Tag does not have a matching open tag:", tag);
 			}
 		}
 		else if (tag.isOpenClose())

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlProblemFinder.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlProblemFinder.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlProblemFinder.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/HtmlProblemFinder.java Thu Oct 22 14:07:13 2009
@@ -21,6 +21,7 @@
 
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.WicketParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -123,9 +124,10 @@
 	 *            The message
 	 * @param tag
 	 *            The current tag
-	 * @throws ParseException
+	 * @throws WicketParseException
 	 */
-	private void escalateWarning(final String msg, final ComponentTag tag) throws ParseException
+	private void escalateWarning(final String msg, final ComponentTag tag)
+		throws WicketParseException
 	{
 		if (problemEscalation == ERR_LOG_WARN)
 		{
@@ -142,7 +144,7 @@
 		else
 		// if (problemEscalation == ERR_THROW_EXCEPTION)
 		{
-			throw new ParseException(msg + tag.toUserDebugString(), tag.getPos());
+			throw new WicketParseException(msg, tag);
 		}
 	}
 }

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketRemoveTagHandler.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketRemoveTagHandler.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketRemoveTagHandler.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketRemoveTagHandler.java Thu Oct 22 14:07:13 2009
@@ -20,6 +20,7 @@
 
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupElement;
+import org.apache.wicket.markup.WicketParseException;
 import org.apache.wicket.markup.WicketTag;
 
 
@@ -60,8 +61,7 @@
 		// remove tag must not be open-close tags
 		if (tag.isOpenClose())
 		{
-			throw new ParseException("Wicket remove tag must not be an open-close tag: " +
-				tag.toUserDebugString(), tag.getPos());
+			throw new WicketParseException("Wicket remove tag must not be an open-close tag:", tag);
 		}
 
 		// Find the corresponding close tag and remove all tags in between
@@ -85,12 +85,11 @@
 				return tag;
 			}
 
-			throw new ParseException(
-				"Markup remove regions must not contain Wicket component tags. tag: " +
-					closeTag.toUserDebugString(), closeTag.getPos());
+			throw new WicketParseException(
+				"Markup remove regions must not contain Wicket component tags:", closeTag);
 		}
 
-		throw new ParseException("Did not find close tag for markup remove region. Open tag: " +
-			tag.toUserDebugString(), tag.getPos());
+		throw new WicketParseException(
+			"Did not find close tag for markup remove region. Open tag:", tag);
 	}
 }

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java Thu Oct 22 14:07:13 2009
@@ -24,6 +24,7 @@
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupElement;
 import org.apache.wicket.markup.MarkupResourceStream;
+import org.apache.wicket.markup.WicketParseException;
 import org.apache.wicket.markup.WicketTag;
 import org.apache.wicket.markup.parser.AbstractMarkupFilter;
 import org.apache.wicket.markup.parser.XmlTag;
@@ -98,9 +99,9 @@
 			if (!isWellKnown(xmlTag))
 			{
 				// give up
-				throw new ParseException("Unknown tag name with Wicket namespace: '" +
+				throw new WicketParseException("Unknown tag name with Wicket namespace: '" +
 					xmlTag.getName() +
-					"'. Might be you haven't installed the appropriate resolver?", tag.getPos());
+					"'. Might be you haven't installed the appropriate resolver?", tag);
 			}
 		}
 		else
@@ -115,9 +116,9 @@
 		{
 			if (value.trim().length() == 0)
 			{
-				throw new ParseException(
+				throw new WicketParseException(
 					"The wicket:id attribute value must not be empty. May be unmatched quotes?!?",
-					tag.getPos());
+					tag);
 			}
 			// Make it a wicket component. Otherwise it would be RawMarkup
 			tag.setId(value);

Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupParserTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupParserTest.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupParserTest.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupParserTest.java Thu Oct 22 14:07:13 2009
@@ -304,7 +304,9 @@
 		}
 		catch (MarkupException ex)
 		{
-			// ignore
+			assertTrue(ex.getMessage()
+				.startsWith(
+					"Wicket remove tag must not be an open-close tag: '<wicket:remove/>' (line 1, column 1)"));
 		}
 
 		IMarkupFragment markup = new MarkupParser("<wicket:remove>  </wicket:remove>").parse();
@@ -327,7 +329,9 @@
 		}
 		catch (MarkupException ex)
 		{
-			// ignore
+			assertTrue(ex.getMessage()
+				.startsWith(
+					"Markup remove regions must not contain Wicket component tags: '<wicket:remove>' (line 1, column 17)"));
 		}
 
 		new MarkupParser(

Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java?rev=828704&r1=828703&r2=828704&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/panel/PanelTest.java Thu Oct 22 14:07:13 2009
@@ -56,7 +56,7 @@
 			hit = true;
 
 			assertNotNull(mex.getMarkupStream());
-			assertTrue(mex.getMessage().indexOf("did not have a close tag") != -1);
+			assertTrue(mex.getMessage().indexOf("does not have a close tag") != -1);
 			assertTrue(mex.getMessage().indexOf("SimplePanel_1.html") != -1);
 		}
 		assertTrue("Did expect a MarkupException", hit);