Author: hlship
Date: Tue Nov 4 17:57:27 2008
New Revision: 711489
URL: http://svn.apache.org/viewvc?rev=711489&view=rev
Log:
TAP5-326: Class org.apache.tapestry5.internal.structure.BlockImpl should
implement toString()
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageElementFactoryImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/BlockImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/RenderableAsBlock.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/StringRenderable.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlockDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/BlockImplTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageElementFactoryImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageElementFactoryImpl.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageElementFactoryImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageElementFactoryImpl.java
Tue Nov 4 17:57:27 2008
@@ -74,7 +74,7 @@
this.pageResourcesSource = pageResourcesSource;
}
- public PageElement newAttributeElement(ComponentResources
componentResources, AttributeToken token)
+ public PageElement newAttributeElement(ComponentResources
componentResources, final AttributeToken token)
{
final StringProvider provider =
parseAttributeExpansionExpression(token.getValue(), componentResources,
token.getLocation());
@@ -88,6 +88,12 @@
{
writer.attributeNS(namespace, name, provider.provideString());
}
+
+ @Override
+ public String toString()
+ {
+ return String.format("AttributeNS[%s %s \"%s\"]", namespace,
name, token.getValue());
+ }
};
}
@@ -168,7 +174,6 @@
return builder.toString();
}
};
-
}
public PageElement newExpansionElement(ComponentResources
componentResources, ExpansionToken token)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageLoaderProcessor.java
Tue Nov 4 17:57:27 2008
@@ -591,14 +591,17 @@
private void parameter(ParameterToken token)
{
- BlockImpl block = new BlockImpl(token.getLocation());
+ ComponentPageElement element = activeElementStack.peek();
String name = token.getName();
+ BlockImpl block = new BlockImpl(token.getLocation(),
+ String.format("Parmeter %s of %s",
name, element.getCompleteId()));
+
Binding binding = new LiteralBinding("block parameter " + name, block,
token.getLocation());
// TODO: Check that the t:parameter doesn't appear outside of an
embedded component.
- activeElementStack.peek().bindParameter(name, binding);
+ element.bindParameter(name, binding);
setupBlock(block);
}
@@ -620,12 +623,16 @@
private void block(BlockToken token)
{
+
+ String id = token.getId();
// Don't use the page element factory here becauses we need something
that is both Block and
// BodyPageElement and don't want to use casts.
- BlockImpl block = new BlockImpl(token.getLocation());
+ String description = id == null
+ ? String.format("Anonymous within %s",
loadingElement.getCompleteId())
+ : String.format("%s within %s", id,
loadingElement.getCompleteId());
- String id = token.getId();
+ BlockImpl block = new BlockImpl(token.getLocation(), description);
if (id != null) loadingElement.addBlock(id, block);
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/BlockImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/BlockImpl.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/BlockImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/BlockImpl.java
Tue Nov 4 17:57:27 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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,9 +31,13 @@
private final List<PageElement> elements = CollectionFactory.newList();
- public BlockImpl(Location location)
+ private final String description;
+
+ public BlockImpl(Location location, String description)
{
super(location);
+
+ this.description = description;
}
public void addToBody(PageElement element)
@@ -51,4 +55,9 @@
queue.push(elements.get(i));
}
+ @Override
+ public String toString()
+ {
+ return String.format("Block[%s, at %s]", description, getLocation());
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
Tue Nov 4 17:57:27 2008
@@ -57,11 +57,16 @@
public void render(MarkupWriter writer)
{
}
+
+ @Override
+ public String toString()
+ {
+ return "<PlaceholderBlock>";
+ }
}
private static final Block PLACEHOLDER_BLOCK = new PlaceholderBlock();
-
/**
* @see #render(org.apache.tapestry5.MarkupWriter,
org.apache.tapestry5.runtime.RenderQueue)
*/
@@ -692,7 +697,7 @@
public void addToBody(PageElement element)
{
- if (bodyBlock == null) bodyBlock = new BlockImpl(getLocation());
+ if (bodyBlock == null) bodyBlock = new BlockImpl(getLocation(), "Body
of " + getCompleteId());
bodyBlock.addToBody(element);
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/RenderableAsBlock.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/RenderableAsBlock.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/RenderableAsBlock.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/RenderableAsBlock.java
Tue Nov 4 17:57:27 2008
@@ -41,4 +41,10 @@
{
renderable.render(writer);
}
+
+ @Override
+ public String toString()
+ {
+ return String.format("Block[%s]", renderable);
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/StringRenderable.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/StringRenderable.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/StringRenderable.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/StringRenderable.java
Tue Nov 4 17:57:27 2008
@@ -33,4 +33,10 @@
{
writer.write(text);
}
+
+ @Override
+ public String toString()
+ {
+ return String.format("Renderable[%s]", text);
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlockDemo.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlockDemo.tml?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlockDemo.tml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlockDemo.tml Tue Nov
4 17:57:27 2008
@@ -1,24 +1,30 @@
<html t:type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <h1>Block Demo</h1>
+ <h1>Block Demo</h1>
- <p> This page demonstrates how blocks may be used to contain text and other
elements and control
- when and if they are rendered. </p>
+ <p>This page demonstrates how blocks may be used to contain text and other
elements and control
+ when and if they are rendered.
+ </p>
- <t:form>
- <t:select t:id="blockName" model="',fred,barney'"
onchange="this.form.submit();"/>
- <t:label for="blockName">Block to display</t:label>
- </t:form>
+ <t:form>
+ <t:select t:id="blockName" model="',fred,barney'"
onchange="this.form.submit();"/>
+ <t:label for="blockName">Block to display</t:label>
+ </t:form>
- <p>The block: [<t:render value="blockToRender"/>]</p>
+ <p>The block: [<t:render value="blockToRender"/>]
+ </p>
+ <p>
+ The block (as string):
+ <span id="blockAsString">${blockToRender}</span>
+ </p>
- <t:block id="fred">Block fred.</t:block>
- <t:block id="barney">Block barney.</t:block>
+ <t:block id="fred">Block fred.</t:block>
+ <t:block id="barney">Block barney.</t:block>
-<hr/>
+ <hr/>
- You can also render a block before it is defined: [<t:delegate
to="block:wilma"/>].
-
- <t:block id="wilma">Block wilma</t:block>
+ You can also render a block before it is defined: [<t:delegate
to="block:wilma"/>].
+
+ <t:block id="wilma">Block wilma</t:block>
</html>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/BlockImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/BlockImplTest.java?rev=711489&r1=711488&r2=711489&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/BlockImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/BlockImplTest.java
Tue Nov 4 17:57:27 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -16,6 +16,10 @@
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
+import org.apache.tapestry5.ioc.Location;
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
+import org.apache.tapestry5.ioc.internal.util.LocationImpl;
import org.apache.tapestry5.runtime.RenderQueue;
import org.testng.annotations.Test;
@@ -24,7 +28,7 @@
@Test
public void empty_block()
{
- BlockImpl block = new BlockImpl(null);
+ BlockImpl block = new BlockImpl(null, null);
RenderQueue queue = mockRenderQueue();
MarkupWriter writer = mockMarkupWriter();
@@ -38,7 +42,7 @@
@Test
public void body_pushed_to_queue_backwards()
{
- BlockImpl block = new BlockImpl(null);
+ BlockImpl block = new BlockImpl(null, null);
RenderQueue queue = mockRenderQueue();
MarkupWriter writer = mockMarkupWriter();
PageElement element1 = mockPageElement();
@@ -58,4 +62,15 @@
verify();
}
+
+ @Test
+ public void to_string()
+ {
+ Resource r = new ClasspathResource("foo/pages/MyPage.tml");
+ Location l = new LocationImpl(r, 23);
+
+ BlockImpl block = new BlockImpl(l, "test block");
+
+ assertEquals(block.toString(), "Block[test block, at
classpath:foo/pages/MyPage.tml, line 23]");
+ }
}