You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/11/20 23:19:54 UTC
svn commit: r477367 - in /tapestry/tapestry4/trunk:
src/site/xdoc/components/general/
tapestry-examples/TimeTracker/src/context/WEB-INF/
tapestry-framework/src/java/org/apache/tapestry/components/
tapestry-framework/src/java/org/apache/tapestry/html/ t...
Author: jkuhnert
Date: Mon Nov 20 14:19:53 2006
New Revision: 477367
URL: http://svn.apache.org/viewvc?view=rev&rev=477367
Log:
Fixes made for TAPESTRY-332. Merged functionality in InsertText with Insert component and deprecated InsertText.
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/InsertMode.java
Modified:
tapestry/tapestry4/trunk/src/site/xdoc/components/general/insert.xml
tapestry/tapestry4/trunk/src/site/xdoc/components/general/inserttext.xml
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentMessages.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentStrings.properties
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.jwc
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.jwc
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestInsert.java
Modified: tapestry/tapestry4/trunk/src/site/xdoc/components/general/insert.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/src/site/xdoc/components/general/insert.xml?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/src/site/xdoc/components/general/insert.xml (original)
+++ tapestry/tapestry4/trunk/src/site/xdoc/components/general/insert.xml Mon Nov 20 14:19:53 2006
@@ -23,10 +23,19 @@
<section name="Insert">
<p>
- Allows for the insertion of text (with a specified format) into the HTML response.
- The text itself can be filtered or not. When filtering is enabled (the default),
- certain characters (such as <code>< and ></code>) are escaped into HTML safe
- representations (such as <code>&lt; and &gt;</code>).
+ Allows for the insertion of text (with a specified format) into the HTML response. The text itself can
+ be filtered or not. When filtering is enabled (the default), certain characters (such as
+ <code>< and ></code>
+ ) are escaped into HTML safe representations (such as
+ <code>&lt; and &gt;</code>
+ ).
+ </p>
+
+ <p>
+ Also allows insertion of multi-line text, breaking it into individual lines according to a mode.
+ Commonly used to properly display the data provided by a user via the
+ <a href="../form/textarea.html">TextArea</a>
+ component.
</p>
<p>
@@ -36,8 +45,6 @@
</a>
<a href="renderblock.html">RenderBlock</a>
,
- <a href="inserttext.html">InsertText</a>
- ,
<a href="renderbody.html">RenderBody</a>
</p>
@@ -56,8 +63,8 @@
<td>no</td>
<td></td>
<td>
- The value to be inserted. If the binding is null, then nothing is
- inserted. Any object may be inserted, the
+ The value to be inserted. If the binding is null, then nothing is inserted. Any object may
+ be inserted, the
<code>toString()</code>
method is used to convert it to a printable value.
</td>
@@ -65,16 +72,13 @@
<tr>
<td>format</td>
<td>
- <a
- href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/Format.html">
- Format
- </a>
+ <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/Format.html">Format</a>
</td>
<td>no</td>
<td></td>
<td>
- An optional format object used to convert the value parameter for
- insertion into the HTML response.
+ An optional format object used to convert the value parameter for insertion into the HTML
+ response.
</td>
</tr>
<tr>
@@ -83,10 +87,33 @@
<td>no</td>
<td></td>
<td>
- If specified, then the output is wrapped in an HTML <code><span></code> tag,
- using the value specified as the CSS class.
+ If specified, then the output is wrapped in an HTML tag, using the value specified as the
+ CSS class. (the html tag being whatever you used to reference the component to begin with )
+ <br />
+ <br />
+ <span class="warn">
+ <strong>Warning:</strong>
+ <p>
+ Using class to force tag rendering is now deprecated, please use the renderTag
+ parameter to control tag rendering.
+ </p>
+ </span>
+ </td>
+ </tr>
+ <tr>
+ <td>renderTag</td>
+ <td>boolean</td>
+ <td>no</td>
+ <td>false</td>
+ <td>
+ If specified, then the output is wrapped in an HTML tag.
- <p>Informal parameters are only rendered if a class is specified.</p>
+ <p>Example:</p>
+ <source><![CDATA[
+<div jwcid="@Insert" value="literal:TestValue" class="myStyle" id="An Id" renderTag="true">
+Text
+</div>
+]]></source>
</td>
</tr>
<tr>
@@ -113,6 +140,30 @@
</td>
</tr>
+ <tr>
+ <td>mode</td>
+ <td>
+ <a
+ href="../../apidocs/org/apache/tapestry/components/InsertMode.html">
+ InsertMode
+ </a>
+ </td>
+ <td>no</td>
+ <td>@org.apache
+ .tapestry.
+ components.
+ InsertMode@BREAK</td>
+ <td>
+ Controls how each line is rendered.
+
+ <p>
+ The OGNL expression
+ <code>@org.apache.tapestry.components.InsertMode@PARAGRAPH</code> OR
+ <code>@org.apache.tapestry.components.InsertMode@BREAK</code>
+ can be used to specify paragraph or line break rendering mode.
+ </p>
+ </td>
+ </tr>
</table>
<p>
@@ -129,7 +180,19 @@
Reserved parameters:
<em>none</em>
</p>
-
+
+ <p>
+ The value parameter is split into multiple lines when specifying a "mode" paramater, and
+ each line is printed. The BREAK
+ <em>mode</em>
+ renders a
+ <code><br/></code>
+ tag between lines (that is, before each line after the first line output). The alternate mode
+ renders
+ <code><p> and </p></code>
+ tags around each line.
+ </p>
+
</section>
<section name="Examples">
Modified: tapestry/tapestry4/trunk/src/site/xdoc/components/general/inserttext.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/src/site/xdoc/components/general/inserttext.xml?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/src/site/xdoc/components/general/inserttext.xml (original)
+++ tapestry/tapestry4/trunk/src/site/xdoc/components/general/inserttext.xml Mon Nov 20 14:19:53 2006
@@ -23,12 +23,20 @@
<section name="InsertText">
<p>
- Inserts multi-line text, breaking it into individual lines according to a mode.
- Commonly used to properly display the data provided by a user via the
+ Inserts multi-line text, breaking it into individual lines according to a mode. Commonly used to
+ properly display the data provided by a user via the
<a href="../form/textarea.html">TextArea</a>
component.
</p>
+ <span class="warn">
+ <strong>Warning:</strong>
+ <p>
+ This component has now been deprecated in favor of the additional functionality
+ added to the <a href="insert.html">Insert</a> component.
+ </p>
+ </span>
+
<p>
<strong>
See also:
@@ -65,10 +73,7 @@
<tr>
<td>mode</td>
<td>
- <a
- href="../../apidocs/org/apache/tapestry/html/InsertTextMode.html">
- InsertTextMode
- </a>
+ <a href="../../apidocs/org/apache/tapestry/html/InsertTextMode.html">InsertTextMode</a>
</td>
<td>no</td>
<td>BREAK</td>
@@ -81,8 +86,8 @@
<td>no</td>
<td>false</td>
<td>
- If true, then output is not filtered for HTML entities. Used when the
- value parameter contains markup that should be rendered as-is.
+ If true, then output is not filtered for HTML entities. Used when the value parameter
+ contains markup that should be rendered as-is.
</td>
</tr>
@@ -104,12 +109,14 @@
</p>
<p>
- The value parameter is split into multiple lines, and each line is printed. The
- default
+ The value parameter is split into multiple lines, and each line is printed. The default
<em>mode</em>
- renders a <code><br/></code> tag between lines (that is, before each line after the
- first line output). The alternate mode renders <code><p> and </p></code> tags
- around each line.
+ renders a
+ <code><br/></code>
+ tag between lines (that is, before each line after the first line output). The alternate mode
+ renders
+ <code><p> and </p></code>
+ tags around each line.
</p>
</section>
Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html Mon Nov 20 14:19:53 2006
@@ -2,6 +2,7 @@
title="message:window.title"
browserLogLevel="DEBUG"
consoleEnabled="true"
+ debugEnabled="false"
>
<link jwcid="@Relation" href="favicon.ico" type="image/gif" rel="shortcut icon" />
<link jwcid="@Relation" href="css/timetracker.css" media="all" />
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentMessages.java?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentMessages.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentMessages.java Mon Nov 20 14:19:53 2006
@@ -37,4 +37,9 @@
{
return _formatter.getMessage("any-element-not-defined");
}
+
+ static String textConversionError(Throwable cause)
+ {
+ return _formatter.format("text-conversion-error", cause);
+ }
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentStrings.properties?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentStrings.properties (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ComponentStrings.properties Mon Nov 20 14:19:53 2006
@@ -14,3 +14,4 @@
unable-to-format={0} unable to format value ''{1}'': {2}
any-element-not-defined=The Any component is not used in a template and the 'element' property is not bound.
+text-conversion-error=Error converting text to lines (for Insert component): {0}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.java?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.java Mon Nov 20 14:19:53 2006
@@ -14,6 +14,10 @@
package org.apache.tapestry.components;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.io.StringReader;
import java.text.Format;
import org.apache.hivemind.ApplicationRuntimeException;
@@ -38,16 +42,18 @@
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
- if (cycle.isRewinding()) return;
-
+ if (cycle.isRewinding())
+ return;
+
Object value = getValue();
-
- if (value == null) return;
-
+
+ if (value == null)
+ return;
+
String insert = null;
-
+
Format format = getFormat();
-
+
if (format == null)
{
insert = value.toString();
@@ -65,28 +71,82 @@
"format").getLocation(), ex);
}
}
-
- String styleClass = getStyleClass();
-
- if (styleClass != null)
- {
- writer.begin("span");
- writer.attribute("class", styleClass);
-
+
+ boolean render = getRenderTag() || isParameterBound("class");
+
+ if (render) {
+ writer.begin(getTemplateTagName());
+
renderInformalParameters(writer, cycle);
}
-
- writer.print(insert, getRaw());
-
- if (styleClass != null) writer.end(); // <span>
+
+ printText(writer, cycle, insert);
+
+ if (render) {
+ writer.end();
+ }
}
+
+ protected void printText(IMarkupWriter writer, IRequestCycle cycle, String value)
+ {
+ if (getMode() == null) {
+
+ writer.print(value, getRaw());
+ return;
+ }
+
+ StringReader reader = null;
+ LineNumberReader lineReader = null;
+ InsertMode mode = getMode();
+ boolean raw = getRaw();
+
+ try {
+ reader = new StringReader(value);
+ lineReader = new LineNumberReader(reader);
+
+ int lineNumber = 0;
+
+ while(true) {
+ String line = lineReader.readLine();
+
+ // Exit loop at end of file.
+
+ if (line == null)
+ break;
+
+ mode.writeLine(lineNumber, line, writer, raw);
+
+ lineNumber++;
+ }
+
+ } catch (IOException ex) {
+
+ throw new ApplicationRuntimeException(ComponentMessages.textConversionError(ex), this, null, ex);
+ } finally {
+
+ close(lineReader);
+ close(reader);
+ }
+ }
+
+ private void close(Reader reader)
+ {
+ if (reader == null)
+ return;
+ try
+ {
+ reader.close();
+ } catch (IOException e){}
+ }
+
public abstract Object getValue();
public abstract Format getFormat();
-
- public abstract String getStyleClass();
-
+
public abstract boolean getRaw();
-
+
+ public abstract boolean getRenderTag();
+
+ public abstract InsertMode getMode();
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.jwc?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.jwc (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/Insert.jwc Mon Nov 20 14:19:53 2006
@@ -19,14 +19,13 @@
"-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">
-<component-specification class="org.apache.tapestry.components.Insert"
- allow-body="no">
+<component-specification class="org.apache.tapestry.components.Insert" allow-body="no">
<description>
Emits a value into the response page.
</description>
- <parameter name="value">
+ <parameter name="value" required="yes">
<description>
The value to be emitted. Non-strings are converted to strings.
</description>
@@ -45,9 +44,16 @@
</description>
</parameter>
- <parameter name="class" property="styleClass">
- <description>
- If specified, then any output is wrapped in an HTML span tag with the given CSS class.
- </description>
+ <parameter name="renderTag" default-value="false">
+ <description>If true, causes the tag used to define the insert to be used, as well as any informal
+ parameters bound.</description>
</parameter>
+
+ <parameter name="mode" default-value="@org.apache.tapestry.components.InsertMode@BREAK">
+ <description>
+ Determines which mode to use: breaks after each line, or wrap each line
+ as a paragraph.
+ </description>
+ </parameter>
+
</component-specification>
Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/InsertMode.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/InsertMode.java?view=auto&rev=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/InsertMode.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/InsertMode.java Mon Nov 20 14:19:53 2006
@@ -0,0 +1,117 @@
+// Copyright 2004, 2005 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.
+// 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.tapestry.components;
+
+import org.apache.tapestry.IMarkupWriter;
+
+/**
+ * Defines a number of ways to format multi-line text for proper renderring.
+ *
+ * <p>
+ * Implementation taken from the now deprecated InsertTextMode class.
+ * </p>
+ *
+ * @author jkuhnert
+ */
+public abstract class InsertMode
+{
+ /**
+ * Mode where each line (after the first) is preceded by a <br> tag.
+ */
+
+ public static final InsertMode BREAK = new BreakMode();
+
+ /**
+ * Mode where each line is wrapped with a <p> element.
+ */
+
+ public static final InsertMode PARAGRAPH = new ParagraphMode();
+
+ protected final String _name;
+
+ /**
+ * Creates a new instance with a name.
+ *
+ * @param name Textual description of the mode.
+ */
+ protected InsertMode(String name)
+ {
+ _name = name;
+ }
+
+ public String toString()
+ {
+ return "InsertMode[" + _name + "]";
+ }
+
+ /**
+ * Invoked by the {@link Insert} component to write the next line.
+ *
+ * @param lineNumber
+ * the line number of the line, starting with 0 for the first
+ * line.
+ * @param line
+ * the String for the current line.
+ * @param writer
+ * the {@link IMarkupWriter} to send output to.
+ * @param raw
+ * if true, then the output should be unfiltered
+ */
+
+ public abstract void writeLine(int lineNumber, String line, IMarkupWriter writer, boolean raw);
+
+ /**
+ *
+ * @author hls
+ */
+ private static final class BreakMode extends InsertMode
+ {
+ private BreakMode()
+ {
+ super("BREAK");
+ }
+
+ public void writeLine(int lineNumber, String line,
+ IMarkupWriter writer, boolean raw)
+ {
+ if (lineNumber > 0)
+ writer.beginEmpty("br");
+
+ writer.print(line, raw);
+ }
+ }
+
+ /**
+ *
+ * @author hls
+ */
+ private static final class ParagraphMode extends InsertMode
+ {
+
+ private ParagraphMode()
+ {
+ super("PARAGRAPH");
+ }
+
+ public void writeLine(int lineNumber, String line,
+ IMarkupWriter writer, boolean raw)
+ {
+ writer.begin("p");
+
+ writer.print(line, raw);
+
+ writer.end();
+ }
+ }
+}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.java?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.java Mon Nov 20 14:19:53 2006
@@ -69,10 +69,11 @@
// Exit loop at end of file.
- if (line == null) break;
+ if (line == null)
+ break;
mode.writeLine(lineNumber, line, writer, raw);
-
+
lineNumber++;
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.jwc?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.jwc (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/InsertText.jwc Mon Nov 20 14:19:53 2006
@@ -21,7 +21,7 @@
<component-specification class="org.apache.tapestry.html.InsertText"
allow-body="no"
- allow-informal-parameters="no">
+ allow-informal-parameters="no" deprecated="yes">
<description>
Inserts line-oriented text into the response HTML, inserting additional
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestInsert.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestInsert.java?view=diff&rev=477367&r1=477366&r2=477367
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestInsert.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestInsert.java Mon Nov 20 14:19:53 2006
@@ -53,7 +53,7 @@
return page;
}
- public void testRewinding()
+ public void test_Rewinding()
{
IRequestCycle cycle = newCycle(true);
@@ -70,7 +70,7 @@
verify();
}
- public void testNullValue()
+ public void test_Null_Value()
{
IRequestCycle cycle = newCycle(false);
@@ -88,7 +88,7 @@
verify();
}
- public void testNoFormat()
+ public void test_No_Format()
{
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle(false);
@@ -109,7 +109,7 @@
verify();
}
- public void testFormat()
+ public void test_Format()
{
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle(false);
@@ -134,7 +134,7 @@
verify();
}
- public void testUnableToFormat()
+ public void test_Unable_To_Format()
{
Object value = "xyzzyx";
Location l = fabricateLocation(87);
@@ -178,7 +178,7 @@
verify();
}
- public void testRaw()
+ public void test_Raw()
{
IRequestCycle cycle = newCycle(false);
IMarkupWriter writer = newWriter();
@@ -199,26 +199,32 @@
verify();
}
- public void testStyleClass()
+ public void test_Style_Class()
{
IBinding informal = newBinding("informal-value");
-
+ IBinding classBinding = newBinding("paisley");
+
IRequestCycle cycle = newCycle(false, false);
IMarkupWriter writer = newWriter();
+
IComponentSpecification spec = newSpec("informal", null);
Insert insert = newInstance(Insert.class,
new Object[] {
"value", "42",
- "specification", spec,
- "styleClass", "paisley"
+ "specification", spec,
+ "templateTagName", "span"
});
expect(cycle.renderStackPush(insert)).andReturn(insert);
writer.begin("span");
+
+ expect(spec.getParameter("class")).andReturn(null);
+
writer.attribute("class", "paisley");
writer.attribute("informal", "informal-value");
+
writer.print("42", false);
writer.end();
@@ -226,10 +232,125 @@
replay();
+ insert.setBinding("class", classBinding);
insert.setBinding("informal", informal);
insert.render(writer, cycle);
verify();
+ }
+
+ public void test_Render_Breaks()
+ {
+ IMarkupWriter writer = newWriter();
+ IRequestCycle cycle = newCycle(false);
+
+ Insert component = newInstance(Insert.class,
+ new Object[] {
+ "value",
+ "Now is the time\nfor all good men\nto come to the aid of their Tapestry.",
+ "mode", InsertMode.BREAK
+ }
+ );
+
+ expect(cycle.renderStackPush(component)).andReturn(component);
+
+ writer.print("Now is the time", false);
+ writer.beginEmpty("br");
+ writer.print("for all good men", false);
+ writer.beginEmpty("br");
+ writer.print("to come to the aid of their Tapestry.", false);
+
+ expect(cycle.renderStackPop()).andReturn(component);
+
+ replay();
+
+ component.render(writer, cycle);
+
+ verify();
+ }
+
+ public void test_Render_Paras()
+ {
+ IMarkupWriter writer = newWriter();
+ IRequestCycle cycle = newCycle(false);
+
+ Insert component = newInstance(Insert.class,
+ new Object[] { "mode", InsertMode.PARAGRAPH, "value",
+ "Now is the time\nfor all good men\nto come to the aid of their Tapestry." });
+
+ expect(cycle.renderStackPush(component)).andReturn(component);
+
+ writer.begin("p");
+ writer.print("Now is the time", false);
+ writer.end();
+
+ writer.begin("p");
+ writer.print("for all good men", false);
+ writer.end();
+
+ writer.begin("p");
+ writer.print("to come to the aid of their Tapestry.", false);
+ writer.end();
+
+ expect(cycle.renderStackPop()).andReturn(component);
+
+ replay();
+
+ component.render(writer, cycle);
+
+ verify();
+ }
+
+ public void test_Render_Raw()
+ {
+ IMarkupWriter writer = newWriter();
+ IRequestCycle cycle = newCycle(false);
+
+ Insert component = newInstance(Insert.class,
+ new Object[] { "value", "output\n<b>raw</b>",
+ "raw", Boolean.TRUE, "mode", InsertMode.BREAK });
+
+ expect(cycle.renderStackPush(component)).andReturn(component);
+
+ writer.print("output", true);
+ writer.beginEmpty("br");
+ writer.print("<b>raw</b>", true);
+
+ expect(cycle.renderStackPop()).andReturn(component);
+
+ replay();
+
+ component.finishLoad(cycle, null, null);
+ component.render(writer, cycle);
+
+ verify();
+ }
+
+ public void test_Render_Nested_Raw()
+ {
+ IMarkupWriter writer = newBufferWriter();
+ IRequestCycle cycle = newCycle(false);
+
+ Insert component = newInstance(Insert.class,
+ new Object[] { "value", "output\n<b>raw</b>",
+ "raw", Boolean.TRUE, "mode", InsertMode.BREAK });
+
+ expect(cycle.renderStackPush(component)).andReturn(component);
+
+ IMarkupWriter nested = writer.getNestedWriter();
+
+ expect(cycle.renderStackPop()).andReturn(component);
+
+ replay();
+
+ component.finishLoad(cycle, null, null);
+ component.render(nested, cycle);
+
+ verify();
+
+ nested.close();
+
+ assertBuffer("output<br/><b>raw</b>");
}
}