View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Open World Ltd
4   // Copyright (C) 2005 Kevin Rogers
5   //
6   // This file is part of MillScript.
7   //
8   // MillScript is free software; you can redistribute it and/or modify it under
9   // the terms of the GNU General Public License as published by the Free
10  // Software Foundation; either version 2 of the License, or (at your option)
11  // any later version.
12  //
13  // MillScript is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  // more details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA  02111-1307  USA
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  }