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.render;
23
24 import org.millscript.commons.util.IList;
25 import org.millscript.commons.util.MapIterator;
26 import org.millscript.commons.vfs.VFile;
27 import org.millscript.millscript.conf.Configuration;
28 import org.millscript.millscript.datatypes.XmlElement;
29 import org.millscript.millscript.tools.CastLibrary;
30
31 import java.io.IOException;
32
33 /**
34 * This class implements MillScripts datafile renderer. It renders to a plain
35 * text separated file format.
36 */
37 public final class DatafileRenderer extends AbstractRenderer {
38
39 /**
40 * Constructs a new lines renderer, to render to the specified virtual file
41 * using the given confguration.
42 *
43 * @param conf the configuration to get rendering parameters from
44 * @param file the virtual output file
45 */
46 public DatafileRenderer( final Configuration conf, final VFile file ) {
47 super( conf, file );
48 }
49
50 /**
51 * @see org.millscript.millscript.render.Renderer#append(char)
52 */
53 public void append( final char ch ) throws IOException {
54 this.appendNoEscape( ch );
55 }
56
57 /**
58 * @see org.millscript.millscript.render.Renderer#append(java.lang.CharSequence)
59 */
60 @Override
61 public void append( final CharSequence cs ) throws IOException {
62 this.appendNoEscape( cs );
63 }
64
65 /**
66 * @see org.millscript.millscript.render.Renderer#appendEscapeFor(char)
67 */
68 public void appendEscapeFor( final char ch ) throws IOException {
69 this.appendNoEscape( ch );
70 }
71
72 /**
73 * @see org.millscript.millscript.render.Renderer#appendNoEscape(char)
74 */
75 public void appendNoEscape( final char ch ) throws IOException {
76 this.outputWriter.write( ch );
77 }
78
79 /**
80 * @see org.millscript.millscript.render.Renderer#appendNoEscape(java.lang.CharSequence)
81 */
82 @Override
83 public void appendNoEscape( final CharSequence cs ) throws IOException {
84 this.outputWriter.write( cs.toString() );
85 }
86
87 /**
88 * @see org.millscript.millscript.render.Renderer#render(java.lang.Object)
89 */
90 @Override
91 public void render( final Object o ) throws IOException {
92 if ( o == null ) {
93 return;
94 } else if ( o instanceof Renderable ) {
95 ((Renderable) o).render( this );
96 } else if ( o instanceof IList ) {
97 MapIterator lines = ((IList) o).iterator( true );
98 while ( lines.hasNext() ) {
99 IList line = CastLibrary.toIList( lines.nextValue() );
100 String gap = "";
101 MapIterator items = line.iterator( true );
102 while ( items.hasNext() ) {
103 this.appendNoEscape( gap );
104 gap = "|";
105 this.renderObject( items.nextValue() );
106 }
107 this.appendNoEscape( '\n' );
108 }
109 } else {
110 this.renderObject( o );
111 }
112 }
113
114 /**
115 * @see org.millscript.millscript.render.Renderer#renderDocumentFooter()
116 */
117 public void renderDocumentFooter() {
118
119 }
120
121 /**
122 * @see org.millscript.millscript.render.Renderer#renderDocumentHeader()
123 */
124 public void renderDocumentHeader() {
125
126 }
127
128 /**
129 * @see org.millscript.millscript.render.Renderer#renderObject(java.lang.Object)
130 */
131 public void renderObject( final Object o ) throws IOException {
132 this.outputWriter.write( o.toString() );
133 }
134
135 /**
136 * @see org.millscript.millscript.render.Renderer#renderXMLElement(org.millscript.millscript.datatypes.XmlElement)
137 */
138 public void renderXMLElement( final XmlElement e ) throws IOException {
139 this.outputWriter.write( e.toString() );
140 }
141
142 }