1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.impl;
17
18 import java.util.List;
19
20 import org.apache.commons.jelly.Script;
21
22
23 /***
24 * <p><code>CompositeTextScriptBlock</code> represents a text body of a
25 * a tag which contains expressions, so that whitespace trimming
26 * can be handled differently.</p>
27 *
28 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29 * @version $Revision: 155420 $
30 */
31 public class CompositeTextScriptBlock extends ScriptBlock {
32
33 /***
34 * Create an instance.
35 */
36 public CompositeTextScriptBlock() {
37 }
38
39
40 /***
41 * Trim the body of the script.
42 * In this case, trim the whitespace from the start of the first element
43 * and from the end of the last element.
44 */
45 public void trimWhitespace() {
46 List list = getScriptList();
47 int size = list.size();
48 if ( size > 0 ) {
49 Script script = (Script) list.get(0);
50 if ( script instanceof TextScript ) {
51 TextScript textScript = (TextScript) script;
52 textScript.trimStartWhitespace();
53 }
54 if ( size > 1 ) {
55 script = (Script) list.get(size - 1);
56 if ( script instanceof TextScript ) {
57 TextScript textScript = (TextScript) script;
58 textScript.trimEndWhitespace();
59 }
60 }
61 }
62 }
63
64
65 }