1 /*
2 * Java HTML Tidy - JTidy
3 * HTML parser and pretty printer
4 *
5 * Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
6 * Institute of Technology, Institut National de Recherche en
7 * Informatique et en Automatique, Keio University). All Rights
8 * Reserved.
9 *
10 * Contributing Author(s):
11 *
12 * Dave Raggett <dsr@w3.org>
13 * Andy Quick <ac.quick@sympatico.ca> (translation to Java)
14 * Gary L Peskin <garyp@firstech.com> (Java development)
15 * Sami Lempinen <sami@lempinen.net> (release management)
16 * Fabrizio Giustina <fgiust at users.sourceforge.net>
17 *
18 * The contributing author(s) would like to thank all those who
19 * helped with testing, bug fixes, and patience. This wouldn't
20 * have been possible without all of you.
21 *
22 * COPYRIGHT NOTICE:
23 *
24 * This software and documentation is provided "as is," and
25 * the copyright holders and contributing author(s) make no
26 * representations or warranties, express or implied, including
27 * but not limited to, warranties of merchantability or fitness
28 * for any particular purpose or that the use of the software or
29 * documentation will not infringe any third party patents,
30 * copyrights, trademarks or other rights.
31 *
32 * The copyright holders and contributing author(s) will not be
33 * liable for any direct, indirect, special or consequential damages
34 * arising out of any use of the software or documentation, even if
35 * advised of the possibility of such damage.
36 *
37 * Permission is hereby granted to use, copy, modify, and distribute
38 * this source code, or portions hereof, documentation and executables,
39 * for any purpose, without fee, subject to the following restrictions:
40 *
41 * 1. The origin of this source code must not be misrepresented.
42 * 2. Altered versions must be plainly marked as such and must
43 * not be misrepresented as being the original source.
44 * 3. This Copyright notice may not be removed or altered from any
45 * source or altered source distribution.
46 *
47 * The copyright holders and contributing author(s) specifically
48 * permit, without fee, and encourage the use of this source code
49 * as a component for supporting the Hypertext Markup Language in
50 * commercial products. If you use this source code in a product,
51 * acknowledgment is not required but would be appreciated.
52 *
53 */
54 package org.w3c.tidy;
55
56 import java.io.IOException;
57 import java.io.OutputStream;
58 import java.io.OutputStreamWriter;
59 import java.io.UnsupportedEncodingException;
60 import java.io.Writer;
61
62
63 /**
64 * Output implementation using java writers.
65 * @author Fabrizio Giustina
66 * @version $Revision: 807 $ ($Author: fgiust $)
67 */
68 public class OutJavaImpl implements Out
69 {
70
71 /**
72 * Java input stream writer.
73 */
74 private Writer writer;
75
76 /**
77 * Newline string.
78 */
79 private char[] newline;
80
81 /**
82 * Constructor.
83 * @param configuration actual configuration instance (needed for newline configuration)
84 * @param encoding encoding name
85 * @param out output stream
86 * @throws UnsupportedEncodingException if the undelining OutputStreamWriter doesn't support the rquested encoding.
87 */
88 protected OutJavaImpl(Configuration configuration, String encoding, OutputStream out)
89 throws UnsupportedEncodingException
90 {
91 this.writer = new OutputStreamWriter(out, encoding);
92 this.newline = configuration.newline;
93 }
94
95 /**
96 * Constructor.
97 * @param configuration actual configuration instance (needed for newline configuration)
98 * @param out Writer
99 */
100 protected OutJavaImpl(Configuration configuration, Writer out)
101 {
102 this.writer = out;
103 this.newline = configuration.newline;
104 }
105
106 /**
107 * @see org.w3c.tidy.Out#outc(int)
108 */
109 public void outc(int c)
110 {
111 try
112 {
113 writer.write(c);
114 }
115 catch (IOException e)
116 {
117 // @todo throws exception
118 System.err.println("OutJavaImpl.outc: " + e.getMessage());
119 }
120 }
121
122 /**
123 * @see org.w3c.tidy.Out#outc(byte)
124 */
125 public void outc(byte c)
126 {
127 try
128 {
129 writer.write(c);
130 }
131 catch (IOException e)
132 {
133 // @todo throws exception
134 System.err.println("OutJavaImpl.outc: " + e.getMessage());
135 }
136 }
137
138 /**
139 * @see org.w3c.tidy.Out#newline()
140 */
141 public void newline()
142 {
143 try
144 {
145 writer.write(this.newline);
146 }
147 catch (IOException e)
148 {
149 // @todo throws exception
150 System.err.println("OutJavaImpl.newline: " + e.getMessage());
151 }
152 }
153
154 /**
155 * @see org.w3c.tidy.Out#flush()
156 */
157 public void flush()
158 {
159 try
160 {
161 writer.flush();
162 }
163 catch (IOException e)
164 {
165 System.err.println("OutJavaImpl.flush: " + e.getMessage());
166 }
167 }
168
169 }