1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.millscript.millscript.datatypes;
23
24 import org.millscript.millscript.render.Renderable;
25 import org.millscript.millscript.render.Renderer;
26 import org.millscript.millscript.tools.StringTools;
27
28 import java.io.IOException;
29 import java.io.Serializable;
30
31 /**
32 * The class implements the CDATA type for MillScript. CDATA is
33 */
34 public final class CDATA implements Renderable, Serializable {
35
36 /**
37 * This is the ID from the release 10.2.0 for future compatibility.
38 */
39 private static final long serialVersionUID = 3977581381394445873L;
40
41 /**
42 * The backing array where the elements of this CDATA object are stored.
43 */
44 private Object[] store;
45
46 /**
47 * Constructs a new CDATA object using the specified array as it's backing
48 * array.
49 *
50 * @param x the array to use as a backing array for this CDATA object
51 */
52 public CDATA( final Object[] x ) {
53 store = x;
54 }
55
56 /**
57 * Returns the backing array used by this CDATA object.
58 *
59 * @return Returns the store for this CDATA object
60 */
61 public Object[] getStore() {
62 return store;
63 }
64
65 /**
66 * @see org.millscript.millscript.render.Renderable#render(org.millscript.millscript.render.Renderer)
67 */
68 public void render( final Renderer r ) throws IOException {
69 r.renderCDATA( this );
70 }
71
72 /**
73 * @see java.lang.Object#toString()
74 */
75 @Override
76 public String toString() {
77 final StringBuffer buf = new StringBuffer( "<![CDATA[" );
78 for ( int i = 0; i < store.length; i++ ) {
79 buf.append(
80 StringTools.substituteAll(
81 store[i].toString(),
82 "]]>",
83 "]]]]><![CDATA[>"
84 )
85 );
86 }
87 buf.append( "]]>" );
88 return buf.toString();
89 }
90
91 }