View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-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.render;
23  
24  import org.millscript.commons.vfs.VFile;
25  import org.millscript.millscript.conf.Configuration;
26  import org.millscript.millscript.datatypes.XmlElement;
27  import org.millscript.millscript.tools.FormatPrint;
28  
29  import java.io.PrintWriter;
30  
31  /**
32   * This class implements MillScripts TXT renderer. It renders to a plain text
33   * file.
34   */
35  public final class TXTRenderer extends AbstractRenderer {
36  
37      /**
38       * The writer we are rendering into.
39       */
40      protected final PrintWriter outputPrintWriter;
41  
42      /**
43       * Constructs a new TXT renderer, to render to the specified virtual file
44       * using the given confguration.
45       *
46       * @param conf  the configuration to get rendering parameters from
47       * @param file  the virtual output file
48       */
49      public TXTRenderer( final Configuration conf, final VFile file ) {
50          super( conf, file );
51          // Make a new print writer over the basic buffered writer
52          this.outputPrintWriter = new PrintWriter( this.outputWriter );
53      }
54  
55      /**
56       * @see org.millscript.millscript.render.Renderer#append(char)
57       */
58      public void append( final char ch ) {
59          this.appendNoEscape( ch );
60      }
61  
62      /**
63       * @see org.millscript.millscript.render.Renderer#append(java.lang.CharSequence)
64       */
65      @Override
66      public void append( final CharSequence cs ) {
67          this.appendNoEscape( cs );
68      }
69  
70      /**
71       * @see org.millscript.millscript.render.Renderer#appendEscapeFor(char)
72       */
73      public void appendEscapeFor( final char ch ) {
74          this.appendNoEscape( ch );
75      }
76  
77      /**
78       * @see org.millscript.millscript.render.Renderer#appendNoEscape(char)
79       */
80      public void appendNoEscape( final char ch ) {
81          FormatPrint.print1( this.outputPrintWriter, new Character( ch ) );
82      }
83  
84      /**
85       * @see org.millscript.millscript.render.Renderer#appendNoEscape(java.lang.CharSequence)
86       */
87      @Override
88      public void appendNoEscape( final CharSequence cs ) {
89          FormatPrint.print1( this.outputPrintWriter, cs );
90      }
91  
92      /**
93       * @see org.millscript.millscript.render.Renderer#render(java.lang.Object)
94       */
95      @Override
96      public void render( final Object o ) {
97          FormatPrint.print1( this.outputPrintWriter, o );
98      }
99  
100     /**
101      * @see org.millscript.millscript.render.Renderer#renderDocumentFooter()
102      */
103     public void renderDocumentFooter() {
104         // There is no footer for a text file
105     }
106 
107     /**
108      * @see org.millscript.millscript.render.Renderer#renderDocumentHeader()
109      */
110     public void renderDocumentHeader() {
111         // There is no header for a text file
112     }
113 
114     /**
115      * @see org.millscript.millscript.render.Renderer#renderObject(java.lang.Object)
116      */
117     public void renderObject( final Object o ) {
118         FormatPrint.print1( this.outputPrintWriter, o );
119     }
120 
121     /**
122      * @see org.millscript.millscript.render.Renderer#renderXMLElement(org.millscript.millscript.datatypes.XmlElement)
123      */
124     public void renderXMLElement( final XmlElement e ) {
125         FormatPrint.print1( this.outputPrintWriter, e );
126     }
127 
128 }