1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.util;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.Script;
20 import org.apache.commons.jelly.impl.CompositeTextScriptBlock;
21 import org.apache.commons.jelly.impl.ScriptBlock;
22 import org.apache.commons.jelly.impl.TextScript;
23 import org.apache.commons.jelly.impl.WeakReferenceWrapperScript;
24
25 /*** Contains static methods to help tag developers.
26 * @author Hans Gilde
27 *
28 */
29 public class TagUtils {
30 private TagUtils() {
31
32 }
33
34 /*** Trims the whitespace from a script and its children.
35 *
36 */
37 public static void trimScript(Script body) {
38 synchronized(body) {
39 if (body instanceof WeakReferenceWrapperScript) {
40 WeakReferenceWrapperScript wrrs = (WeakReferenceWrapperScript) body;
41 try {
42 wrrs.trimWhitespace();
43 } catch (JellyTagException e) {
44
45 return;
46 }
47 } else if ( body instanceof CompositeTextScriptBlock ) {
48 CompositeTextScriptBlock block = (CompositeTextScriptBlock) body;
49 block.trimWhitespace();
50 }
51 else
52 if ( body instanceof ScriptBlock ) {
53 ScriptBlock block = (ScriptBlock) body;
54 block.trimWhitespace();
55 }
56 else if ( body instanceof TextScript ) {
57 TextScript textScript = (TextScript) body;
58 textScript.trimWhitespace();
59 }
60 }
61 }
62
63 }