You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/02/27 10:44:24 UTC
[1/2] git commit: WICKET-5048 Inline enclosures don't work with
different namespace
WICKET-5048 Inline enclosures don't work with different namespace
Make it possible to pass wicketNamespace to Markup.of()
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/01f32fa3
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/01f32fa3
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/01f32fa3
Branch: refs/heads/master
Commit: 01f32fa39a7e95d548076619f6e0e38bad3c1f22
Parents: 8d774ae
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Feb 27 11:41:43 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Feb 27 11:41:43 2013 +0200
----------------------------------------------------------------------
.../main/java/org/apache/wicket/markup/Markup.java | 25 +++-
.../markup/html/internal/InlineEnclosure.java | 26 ++++-
...eEnclosureDifferentNamespaceExpectedResult.html | 106 +++++++++++++++
.../InlineEnclosureDifferentNamespacePage.html | 106 +++++++++++++++
.../InlineEnclosureDifferentNamespacePage.java | 83 +++++++++++
5 files changed, 343 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/01f32fa3/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java b/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java
index 06fb75a..3bc2f39 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/Markup.java
@@ -60,13 +60,34 @@ public class Markup implements IMarkupFragment
* not applied, which you might have registered with MarkupFactory.
*
* @param markup
- * @return Markup
+ * the string to use as markup
+ * @return Markup The parsed markup
*/
public static Markup of(final String markup)
{
+ return of(markup, MarkupParser.WICKET);
+ }
+
+ /**
+ * Take the markup string, parse it and return the Markup (list of MarkupElements).
+ * <p>
+ * Limitation: Please note that MarkupFactory is NOT used and thus no caching is used (which
+ * doesn't matter for Strings anyway), but what might matter is that your own MarkupFilters are
+ * not applied, which you might have registered with MarkupFactory.
+ *
+ * @param markup
+ * the string to use as markup
+ * @param wicketNamespace
+ * the namespace for Wicket elements and attributes
+ * @return Markup The parsed markup
+ */
+ public static Markup of(final String markup, String wicketNamespace)
+ {
try
{
- return new MarkupParser(markup).parse();
+ MarkupParser markupParser = new MarkupParser(markup);
+ markupParser.setWicketNamespace(wicketNamespace);
+ return markupParser.parse();
}
catch (IOException ex)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/01f32fa3/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
index f62604e..6ce1edc 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/InlineEnclosure.java
@@ -16,10 +16,14 @@
*/
package org.apache.wicket.markup.html.internal;
+import org.apache.wicket.Page;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.IMarkupFragment;
import org.apache.wicket.markup.Markup;
+import org.apache.wicket.markup.MarkupParser;
+import org.apache.wicket.markup.MarkupResourceStream;
import org.apache.wicket.markup.parser.filter.InlineEnclosureHandler;
+import org.apache.wicket.util.string.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -105,9 +109,29 @@ public class InlineEnclosure extends Enclosure
}
else
{
- enclosureMarkup = Markup.of(enclosureMarkupAsString);
+ enclosureMarkup = Markup.of(enclosureMarkupAsString, getWicketNamespace());
}
return enclosureMarkup;
}
+
+ /**
+ * @return the markup namespace for Wicket elements and attributes.
+ */
+ private String getWicketNamespace()
+ {
+ String markupNamespace = MarkupParser.WICKET;
+ Page page = findPage();
+ if (page != null)
+ {
+ IMarkupFragment markup = page.getMarkup();
+ MarkupResourceStream markupResourceStream = markup.getMarkupResourceStream();
+ String namespace = markupResourceStream.getWicketNamespace();
+ if (Strings.isEmpty(namespace) == false)
+ {
+ markupNamespace = namespace;
+ }
+ }
+ return markupNamespace;
+ }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/01f32fa3/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespaceExpectedResult.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespaceExpectedResult.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespaceExpectedResult.html
new file mode 100755
index 0000000..0bf49ad
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespaceExpectedResult.html
@@ -0,0 +1,106 @@
+<html>
+<body>
+
+<!-- nested inline enclosures with separate child depths. -->
+<div id="w_InlineEnclosure-1"><span>Test Label 1</span>
+ <div id="w_InlineEnclosure-2">
+ <table>
+ <tr>
+ <td><span>Test Label 2</span></td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+<!-- nested inline enclosures with same child depth. -->
+<div id="w_InlineEnclosure-3">
+ <div id="w_InlineEnclosure-4">
+ <span>Test Label 3</span>
+ <span>Test Label 4</span>
+ </div>
+</div>
+
+<!-- enclosure tag nested inside inline enclosure with separate child depths. -->
+<div id="w_InlineEnclosure-5"> <span>Test Label 5</span>
+
+ <table>
+ <tr>
+ <td>
+ <span>Test Label 6</span>
+ </td>
+ </tr>
+ </table>
+
+</div>
+
+<!-- enclosure tag nested inside inline enclosure with same child depth. -->
+<div id="w_InlineEnclosure-7">
+
+ <table>
+ <tr>
+ <td>
+ <span>Test Label 7</span>
+ <span>Test Label 8</span>
+ </td>
+ </tr>
+ </table>
+
+</div>
+
+<!-- inline enclosure nested inside enclosure tag with separate child depths. -->
+
+ <div id="w_InlineEnclosure-10"> <span>Test Label 9</span>
+ <table>
+ <tr>
+ <td><span>Test Label 10</span></td>
+ </tr>
+ </table>
+ </div>
+
+
+<!-- inline enclosure nested inside enclosure tag with same child depth. -->
+<div id="w_InlineEnclosure-11">
+
+ <table>
+ <tr>
+ <td>
+ <span>Test Label 11</span>
+ <span>Test Label 12</span>
+ </td>
+ </tr>
+ </table>
+
+</div>
+
+<!-- inline enclosure nested inside enclosure tag with same child depth inside a wicket container. -->
+
+ <div id="w_InlineEnclosure-14">
+ <div>
+ <table>
+ <tr>
+ <td>
+ <span>Test Label 13</span>
+ <span>Test Label 14</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+
+
+
+<!-- nested inline enclosures without explicitly determining children -->
+<div id="w_InlineEnclosure-15">
+ <div id="w_InlineEnclosure-16">
+ <table>
+ <tr>
+ <td>
+ <span>Test Label 15</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/01f32fa3/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.html
new file mode 100755
index 0000000..729aff4
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.html
@@ -0,0 +1,106 @@
+<html xmlns:w="http://wicket.apache.org/">
+<body>
+
+<!-- nested inline enclosures with separate child depths. -->
+<div w:enclosure="label1"><span w:id="label1">Test</span>
+ <div w:enclosure="label2">
+ <table>
+ <tr>
+ <td><span w:id="label2">Test</span></td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+<!-- nested inline enclosures with same child depth. -->
+<div w:enclosure="label3">
+ <div w:enclosure="label4">
+ <span w:id="label3">Test</span>
+ <span w:id="label4">Test</span>
+ </div>
+</div>
+
+<!-- enclosure tag nested inside inline enclosure with separate child depths. -->
+<div w:enclosure="label5"> <span w:id="label5">Test</span>
+ <w:enclosure child="label6">
+ <table>
+ <tr>
+ <td>
+ <span w:id="label6">Test</span>
+ </td>
+ </tr>
+ </table>
+ </w:enclosure>
+</div>
+
+<!-- enclosure tag nested inside inline enclosure with same child depth. -->
+<div w:enclosure="label7">
+ <w:enclosure child="label8">
+ <table>
+ <tr>
+ <td>
+ <span w:id="label7">Test</span>
+ <span w:id="label8">Test</span>
+ </td>
+ </tr>
+ </table>
+ </w:enclosure>
+</div>
+
+<!-- inline enclosure nested inside enclosure tag with separate child depths. -->
+<w:enclosure child="label9">
+ <div w:enclosure="label10"> <span w:id="label9">Test</span>
+ <table>
+ <tr>
+ <td><span w:id="label10">Test</span></td>
+ </tr>
+ </table>
+ </div>
+</w:enclosure>
+
+<!-- inline enclosure nested inside enclosure tag with same child depth. -->
+<div w:enclosure="label11">
+ <w:enclosure child="label12">
+ <table>
+ <tr>
+ <td>
+ <span w:id="label11">Test</span>
+ <span w:id="label12">Test</span>
+ </td>
+ </tr>
+ </table>
+ </w:enclosure>
+</div>
+
+<!-- inline enclosure nested inside enclosure tag with same child depth inside a wicket container. -->
+<w:enclosure child="container:label14">
+ <div w:enclosure="container:label13">
+ <div w:id="container">
+ <table>
+ <tr>
+ <td>
+ <span w:id="label13">Test</span>
+ <span w:id="label14">Test</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+</w:enclosure>
+
+
+<!-- nested inline enclosures without explicitly determining children -->
+<div w:enclosure="">
+ <div w:enclosure="">
+ <table>
+ <tr>
+ <td>
+ <span w:id="label15">Test</span>
+ </td>
+ </tr>
+ </table>
+ </div>
+</div>
+
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/01f32fa3/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.java
new file mode 100755
index 0000000..566e355
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureDifferentNamespacePage.java
@@ -0,0 +1,83 @@
+/*
+ * 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.html.internal;
+
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+
+/**
+ * Mock page for testing.
+ *
+ * @author Joonas Hamalainen
+ *
+ */
+public class InlineEnclosureDifferentNamespacePage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Label label1 = new Label("label1", "Test Label 1");
+ private final Label label2 = new Label("label2", "Test Label 2");
+ private final Label label3 = new Label("label3", "Test Label 3");
+ private final Label label4 = new Label("label4", "Test Label 4");
+ private final Label label5 = new Label("label5", "Test Label 5");
+ private final Label label6 = new Label("label6", "Test Label 6");
+ private final Label label7 = new Label("label7", "Test Label 7");
+ private final Label label8 = new Label("label8", "Test Label 8");
+ private final Label label9 = new Label("label9", "Test Label 9");
+ private final Label label10 = new Label("label10", "Test Label 10");
+ private final Label label11 = new Label("label11", "Test Label 11");
+ private final Label label12 = new Label("label12", "Test Label 12");
+ private final Label label13 = new Label("label13", "Test Label 13");
+ private final Label label14 = new Label("label14", "Test Label 14");
+ private final Label label15 = new Label("label15", "Test Label 15");
+
+ /**
+ * Construct.
+ */
+ public InlineEnclosureDifferentNamespacePage()
+ {
+ add(label1);
+ add(label2);
+ add(label3);
+ add(label4);
+ add(label5);
+ add(label6);
+ add(label7);
+ add(label8);
+ add(label9);
+ add(label10);
+ add(label11);
+ add(label12);
+
+ WebMarkupContainer container = new WebMarkupContainer("container");
+ add(container);
+ container.add(label13);
+ container.add(label14);
+
+ add(label15);
+ }
+
+ /**
+ * @return serialVersionUID
+ */
+ public static long getSerialversionuid()
+ {
+ return serialVersionUID;
+ }
+}