You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/05/07 18:29:39 UTC

svn commit: r535918 - in /incubator/wicket/trunk/jdk-1.4/wicket-velocity/src: main/java/org/apache/wicket/velocity/markup/html/VelocityPanel.java test/java/wicket/contrib/markup/html/velocity/VelocityWithMarkupParsingPage.java

Author: ehillenius
Date: Mon May  7 09:29:36 2007
New Revision: 535918

URL: http://svn.apache.org/viewvc?view=rev&rev=535918
Log:
Changed properties to methods. This saves a bit of state, and it is unlikely people use many of instances of VelocityPanel in their pages (in which case trimming down verbosity makes sense, though they could simply subclass it then as well).

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/main/java/org/apache/wicket/velocity/markup/html/VelocityPanel.java
    incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/test/java/wicket/contrib/markup/html/velocity/VelocityWithMarkupParsingPage.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/main/java/org/apache/wicket/velocity/markup/html/VelocityPanel.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/main/java/org/apache/wicket/velocity/markup/html/VelocityPanel.java?view=diff&rev=535918&r1=535917&r2=535918
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/main/java/org/apache/wicket/velocity/markup/html/VelocityPanel.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/main/java/org/apache/wicket/velocity/markup/html/VelocityPanel.java Mon May  7 09:29:36 2007
@@ -56,33 +56,12 @@
  * <code>VelocityPanel</code>.
  * </p>
  */
-public final class VelocityPanel extends Panel
+public class VelocityPanel extends Panel
 {
-	/** Whether to escape HTML characters. The default value is false. */
-	private boolean escapeHtml = false;
-
-	/** Whether to parse the resulting Wicket markup */
-	private boolean parseGeneratedMarkup = false;
-
 	/** Velocity template resource */
 	private final IStringResourceStream templateResource;
 
 	/**
-	 * Whether any velocity exception should be trapped and displayed on the
-	 * panel (false) or thrown up to be handled by the exception mechanism of
-	 * Wicket (true). The default is false, which traps and displays any
-	 * exception without having consequences for the other components on the
-	 * page.
-	 * <p>
-	 * Trapping these exceptions without disturbing the other components is
-	 * especially usefull in CMS like applications, where 'normal' users are
-	 * allowed to do basic scripting. On errors, you want them to be able to
-	 * have them correct them while the rest of the application keeps on
-	 * working.
-	 */
-	private boolean throwVelocityExceptions = false;
-
-	/**
 	 * Construct.
 	 * 
 	 * @param name
@@ -100,82 +79,6 @@
 	}
 
 	/**
-	 * Gets whether to escape HTML characters.
-	 * 
-	 * @return whether to escape HTML characters
-	 */
-	public final boolean getEscapeHtml()
-	{
-		return escapeHtml;
-	}
-
-	/**
-	 * Gets whether to parse the resulting Wicket markup
-	 * 
-	 * @return whether to parse the resulting Wicket markup
-	 */
-	public boolean getParseGeneratedMarkup()
-	{
-		return parseGeneratedMarkup;
-	}
-
-	/**
-	 * Gets whether any velocity exception should be trapped and displayed on
-	 * the panel (false) or thrown up to be handled by the exception mechanism
-	 * of Wicket (true). The default is true, which traps and displays any
-	 * exception without having consequences for the other components on the
-	 * page.
-	 * 
-	 * @return Whether any velocity exceptions should be thrown or trapped.
-	 */
-	public final boolean getThrowVelocityExceptions()
-	{
-		return throwVelocityExceptions;
-	}
-
-	/**
-	 * Sets whether to escape HTML characters. The default value is false.
-	 * 
-	 * @param escapeHtml
-	 *            whether to escape HTML characters
-	 * @return This
-	 */
-	public final VelocityPanel setEscapeHtml(boolean escapeHtml)
-	{
-		this.escapeHtml = escapeHtml;
-		return this;
-	}
-
-	/**
-	 * Sets whether to parse the resulting Wicket markup. The default value is
-	 * false.
-	 * 
-	 * @param parseGeneratedMarkup
-	 *            whether to parse the resulting Wicket markup
-	 * @return This
-	 */
-	public final VelocityPanel setParseGeneratedMarkup(boolean parseGeneratedMarkup)
-	{
-		this.parseGeneratedMarkup = parseGeneratedMarkup;
-		return this;
-	}
-
-	/**
-	 * Gets whether any velocity exception should be trapped and displayed on
-	 * the panel (true) or thrown up to be handled by the exception mechanism of
-	 * Wicket (false).
-	 * 
-	 * @param throwVelocityExceptions
-	 *            whether any exception should be trapped or rethrown
-	 * @return This
-	 */
-	public final VelocityPanel setThrowVelocityExceptions(boolean throwVelocityExceptions)
-	{
-		this.throwVelocityExceptions = throwVelocityExceptions;
-		return this;
-	}
-
-	/**
 	 * Gets a reader for the velocity template.
 	 * 
 	 * @return reader for the velocity template
@@ -203,7 +106,7 @@
 	private void onException(final Exception exception, final MarkupStream markupStream,
 			final ComponentTag openTag)
 	{
-		if (!throwVelocityExceptions)
+		if (!throwVelocityExceptions())
 		{
 			// print the exception on the panel
 			String stackTraceAsString = Strings.toString(exception);
@@ -217,6 +120,16 @@
 	}
 
 	/**
+	 * Gets whether to escape HTML characters.
+	 * 
+	 * @return whether to escape HTML characters. The default value is false.
+	 */
+	protected boolean escapeHtml()
+	{
+		return false;
+	}
+
+	/**
 	 * @see org.apache.wicket.markup.html.panel.Panel#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
 	 *      org.apache.wicket.markup.ComponentTag)
 	 */
@@ -246,14 +159,14 @@
 				// replace the tag's body the Velocity output
 				String result = writer.toString();
 
-				if (escapeHtml)
+				if (escapeHtml())
 				{
 					// encode the result in order to get valid html output that
 					// does not break the rest of the page
 					result = Strings.escapeMarkup(result).toString();
 				}
 
-				if (!getParseGeneratedMarkup())
+				if (!parseGeneratedMarkup())
 				{
 					// now replace the body of the tag with the velocity merge
 					// result
@@ -301,5 +214,38 @@
 		{
 			replaceComponentTagBody(markupStream, openTag, ""); // just empty it
 		}
+	}
+
+	/**
+	 * Gets whether to parse the resulting Wicket markup.
+	 * 
+	 * @return whether to parse the resulting Wicket markup. The default is
+	 *         false.
+	 */
+	protected boolean parseGeneratedMarkup()
+	{
+		return false;
+	}
+
+	/**
+	 * Whether any velocity exception should be trapped and displayed on the
+	 * panel (false) or thrown up to be handled by the exception mechanism of
+	 * Wicket (true). The default is false, which traps and displays any
+	 * exception without having consequences for the other components on the
+	 * page.
+	 * <p>
+	 * Trapping these exceptions without disturbing the other components is
+	 * especially usefull in CMS like applications, where 'normal' users are
+	 * allowed to do basic scripting. On errors, you want them to be able to
+	 * have them correct them while the rest of the application keeps on
+	 * working.
+	 * </p>
+	 * 
+	 * @return Whether any velocity exceptions should be thrown or trapped. The
+	 *         default is false.
+	 */
+	protected boolean throwVelocityExceptions()
+	{
+		return false;
 	}
 }

Modified: incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/test/java/wicket/contrib/markup/html/velocity/VelocityWithMarkupParsingPage.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/test/java/wicket/contrib/markup/html/velocity/VelocityWithMarkupParsingPage.java?view=diff&rev=535918&r1=535917&r2=535918
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/test/java/wicket/contrib/markup/html/velocity/VelocityWithMarkupParsingPage.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-velocity/src/test/java/wicket/contrib/markup/html/velocity/VelocityWithMarkupParsingPage.java Mon May  7 09:29:36 2007
@@ -38,9 +38,16 @@
 	{
 		HashMap values = new HashMap();
 		values.put("labelId", "message");
-		VelocityPanel velocityPanel = new VelocityPanel("velocityPanel",
-				new UrlResourceStream(this.getClass().getResource("testWithMarkup.html")), new Model(values));
-		velocityPanel.setParseGeneratedMarkup(true);
+		VelocityPanel velocityPanel = new VelocityPanel(
+				"velocityPanel",
+				new UrlResourceStream(this.getClass().getResource("testWithMarkup.html")),
+				new Model(values))
+		{
+			public boolean parseGeneratedMarkup()
+			{
+				return true;
+			}
+		};
 		velocityPanel.add(new Label("message", VelocityPage.TEST_STRING));
 		add(velocityPanel);
 	}