You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2009/02/06 01:17:07 UTC
svn commit: r741352 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
test/java/org/apache/tapestry5/internal/services/MarkupWriterImplTest.java
Author: hlship
Date: Fri Feb 6 00:17:07 2009
New Revision: 741352
URL: http://svn.apache.org/viewvc?rev=741352&view=rev
Log:
TAP5-349: Tapestry silently allows a MarkupWriter to set a series of root elements, ignoring all but the last. A document should only have a single root element and this situation should be an immediate exception.
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MarkupWriterImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java?rev=741352&r1=741351&r2=741352&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterImpl.java Fri Feb 6 00:17:07 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -135,8 +135,21 @@
public Element element(String name, Object... namesAndValues)
{
- if (current == null) current = document.newRootElement(name);
- else current = current.element(name);
+ if (current == null)
+ {
+ Element existingRootElement = document.getRootElement();
+
+ if (existingRootElement != null)
+ throw new IllegalStateException(String.format(
+ "A document must have exactly one root element. Element <%s> is already the root element.",
+ existingRootElement.getName()));
+
+ current = document.newRootElement(name);
+ }
+ else
+ {
+ current = current.element(name);
+ }
attributes(namesAndValues);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MarkupWriterImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MarkupWriterImplTest.java?rev=741352&r1=741351&r2=741352&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MarkupWriterImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MarkupWriterImplTest.java Fri Feb 6 00:17:07 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -31,6 +31,29 @@
w.write("fail!");
}
+ /**
+ * TAP5-349
+ */
+ @Test
+ public void single_root_element_only()
+ {
+ MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
+
+ w.element("root1");
+ w.end();
+
+ try
+ {
+ w.element("root2");
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertEquals(ex.getMessage(),
+ "A document must have exactly one root element. Element <root1> is already the root element.");
+ }
+ }
+
@Test
public void write_whitespace_before_start_of_root_element_is_ignored()
{