Author: jdonnerstag
Date: Thu Mar 24 19:40:52 2011
New Revision: 1085095

URL: http://svn.apache.org/viewvc?rev=1085095&view=rev
Log:
Allow to easily create Markup from String. Changed an example to use 
Component.getMarkup() to see if it works.

Removed "counter" from AbstractMarkupFilter. It's no longer needed.

Removed:
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_3.html
Modified:
    wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_3.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/SimplePanel.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/TestHomePage.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java?rev=1085095&r1=1085094&r2=1085095&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java 
(original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java 
Thu Mar 24 19:40:52 2011
@@ -16,13 +16,14 @@
  */
 package org.apache.wicket.markup;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.resource.StringResourceStream;
+import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
 import org.apache.wicket.util.string.AppendingStringBuffer;
 import org.apache.wicket.util.string.Strings;
 import org.slf4j.Logger;
@@ -53,22 +54,32 @@ public class Markup implements IMarkupFr
        private final MarkupResourceStream markupResourceStream;
 
        /**
-        * Private Constructor for NO_MARKUP only
+        * Take the markup string, parse it and return the Markup (list of 
MarkupElements).
+        * @param markup
+        * @return Markup
         */
-       private Markup()
+       public static Markup get(final String markup)
        {
-               markupResourceStream = null;
+               try
+               {
+                       return new MarkupParser(markup).parse();
+               }
+               catch (IOException ex)
+               {
+                       throw new RuntimeException(ex);
+               }
+               catch (ResourceStreamNotFoundException ex)
+               {
+                       throw new RuntimeException(ex);
+               }
        }
 
        /**
-        * Constructor
-        * 
-        * @param markup
-        *            The associated Markup
+        * Private Constructor for NO_MARKUP only
         */
-       public Markup(final CharSequence markup)
+       private Markup()
        {
-               this(new MarkupResourceStream(new 
StringResourceStream(markup)));
+               markupResourceStream = null;
        }
 
        /**

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java?rev=1085095&r1=1085094&r2=1085095&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
 Thu Mar 24 19:40:52 2011
@@ -40,9 +40,6 @@ public abstract class AbstractMarkupFilt
        /** The next MarkupFilter in the chain */
        private IMarkupFilter parent;
 
-       /** TODO Not sure this counter is sufficiently safe, since filters are 
created per markup file. */
-       private int count;
-
        /**
         * Construct.
         */
@@ -128,27 +125,18 @@ public abstract class AbstractMarkupFilt
                return tag;
        }
 
-       /**
-        * Invoked if current element is raw markup
-        * 
-        * @param rawMarkup
-        * @return Usually the same as the tag attribute
-        */
+// /**
+// * Invoked if current element is raw markup
+// *
+// * @param rawMarkup
+// * @return Usually the same as the tag attribute
+// */
 // Not yet used
 // protected MarkupElement onRawMarkup(final MarkupElement rawMarkup)
 // {
 // return rawMarkup;
 // }
 
-       /**
-        * 
-        * @return A unique count per instance
-        */
-       protected int getCount()
-       {
-               return count++;
-       }
-
        public void postProcess(final Markup markup)
        {
        }

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java?rev=1085095&r1=1085094&r2=1085095&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/WicketTagIdentifier.java
 Thu Mar 24 19:40:52 2011
@@ -87,7 +87,7 @@ public final class WicketTagIdentifier e
                        if (Strings.isEmpty(wicketIdValue))
                        {
                                // Make it a Wicket component. Otherwise it 
would be RawMarkup
-                               tag.setId("_" + tag.getName() + getCount());
+                               tag.setId("_wicket_" + tag.getName());
                                tag.setAutoComponentTag(true);
                                tag.setModified(true);
                        }

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_3.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_3.java?rev=1085095&r1=1085094&r2=1085095&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_3.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePage_3.java
 Thu Mar 24 19:40:52 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.wicket.markup.html.basic;
 
+import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.Markup;
+
 
 /**
  * Mock page for testing.
@@ -37,4 +40,18 @@ public class SimplePage_3 extends Simple
                get("myBorder").setVisible(false);
                get("myBorder2").setVisible(false);
        }
+
+       /**
+        * @see org.apache.wicket.Page#getMarkup()
+        */
+       @Override
+       public IMarkupFragment getMarkup()
+       {
+               return Markup.get("<html xmlns:wicket><body>" //
+                       + "<span wicket:id='myLabel'>mein Label</span>" //
+                       + "<span wicket:id='test'>body</span>" //
+                       + "<span wicket:id='myPanel'>panel</span>" //
+                       + "<span wicket:id='myBorder'>border</span>" //
+                       + "</body></html>");
+       }
 }

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/SimplePanel.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/SimplePanel.java?rev=1085095&r1=1085094&r2=1085095&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/SimplePanel.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/SimplePanel.java
 Thu Mar 24 19:40:52 2011
@@ -16,18 +16,34 @@
  */
 package org.apache.wicket.markup.html.page;
 
+import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.Markup;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.panel.Panel;
 import org.apache.wicket.model.Model;
 
+/**
+ * 
+ */
 public class SimplePanel extends Panel
 {
        private static final long serialVersionUID = 1L;
 
+       /**
+        * Construct.
+        * 
+        * @param id
+        */
        public SimplePanel(String id)
        {
                super(id);
 
                add(new Label("label", Model.of("Label")));
        }
+
+       @Override
+       public IMarkupFragment getMarkup()
+       {
+               return Markup.get("<wicket:panel><span 
wicket:id='label'></span></wicket:panel>");
+       }
 }

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/TestHomePage.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/TestHomePage.java?rev=1085095&r1=1085094&r2=1085095&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/TestHomePage.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/page/TestHomePage.java
 Thu Mar 24 19:40:52 2011
@@ -23,7 +23,9 @@ import org.apache.wicket.WicketTestCase;
  */
 public class TestHomePage extends WicketTestCase
 {
-
+       /**
+        * 
+        */
        public void testRenderMyPage()
        {
                // no exception should occur


Reply via email to