01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.pretty;
10:
11: import java.io.ByteArrayOutputStream;
12: import java.io.File;
13: import java.io.CharArrayWriter;
14: import java.io.Writer;
15: import java.io.BufferedWriter;
16: import net.sourceforge.jrefactory.factory.BufferParserFactory;
17:
18: /**
19: * Pretty prints the string
20: *
21: *@author Chris Seguin
22: */
23: public abstract class PrettyPrintString extends PrettyPrintFile {
24: // Instance Variables
25: private CharArrayWriter outputStream;
26: private Writer outputWriter;
27:
28: /**
29: * Create an PrettyPrintString object
30: */
31: public PrettyPrintString() {
32: outputStream = new CharArrayWriter();
33: outputWriter = new BufferedWriter(outputStream);
34: }
35:
36: /**
37: * Sets the input string to be pretty printed
38: *
39: *@param input the input buffer
40: */
41: protected void setInputString(String input) {
42: if (input == null) {
43: return;
44: }
45:
46: setParserFactory(new BufferParserFactory(input));
47: }
48:
49: /**
50: * Get the output buffer
51: *
52: *@return a string containing the results
53: */
54: protected String getOutputBuffer() {
55: return new String(outputStream.toCharArray());
56: }
57:
58: /**
59: * Create the output stream
60: *
61: *@param file the name of the file
62: *@return the output stream
63: */
64: protected Writer getWriter(File file) {
65: return outputWriter;
66: }
67:
68: /**
69: * Reset the output buffer
70: */
71: protected void resetOutputBuffer() {
72: outputStream.reset();
73: }
74: }
|