01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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: * <p><code>CompositeTextScriptBlock</code> represents a text body of a
24: * a tag which contains expressions, so that whitespace trimming
25: * can be handled differently.</p>
26: *
27: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
28: * @version $Revision: 155420 $
29: */
30: public class CompositeTextScriptBlock extends ScriptBlock {
31:
32: /**
33: * Create an instance.
34: */
35: public CompositeTextScriptBlock() {
36: }
37:
38: /**
39: * Trim the body of the script.
40: * In this case, trim the whitespace from the start of the first element
41: * and from the end of the last element.
42: */
43: public void trimWhitespace() {
44: List list = getScriptList();
45: int size = list.size();
46: if (size > 0) {
47: Script script = (Script) list.get(0);
48: if (script instanceof TextScript) {
49: TextScript textScript = (TextScript) script;
50: textScript.trimStartWhitespace();
51: }
52: if (size > 1) {
53: script = (Script) list.get(size - 1);
54: if (script instanceof TextScript) {
55: TextScript textScript = (TextScript) script;
56: textScript.trimEndWhitespace();
57: }
58: }
59: }
60: }
61:
62: }
|