01: package org.objectweb.celtix.tools.generators;
02:
03: import java.io.BufferedWriter;
04: import java.io.IOException;
05: import java.io.Writer;
06:
07: public class VelocityWriter extends BufferedWriter {
08:
09: private final String newLine = System.getProperty("line.separator");
10:
11: public VelocityWriter(Writer out) {
12: super (out);
13: }
14:
15: public VelocityWriter(Writer out, int size) {
16: super (out, size);
17: }
18:
19: public void write(char[] chars) throws IOException {
20: String str = new String(chars);
21: if (str.indexOf("\r\n") >= 0 && newLine != null) {
22: super .write(str.replaceAll("\r\n", newLine));
23: return;
24: } else if (str.indexOf("\n") >= 0 && newLine != null) {
25: super .write(str.replaceAll("\n", newLine));
26: return;
27: } else {
28: super .write(str);
29: }
30:
31: }
32:
33: public void write(String str) throws IOException {
34: if (str.indexOf("\r\n") >= 0 && newLine != null) {
35: super .write(str.replaceAll("\r\n", newLine));
36: return;
37: } else if (str.indexOf("\n") >= 0 && newLine != null) {
38: super .write(str.replaceAll("\r\n", newLine));
39: return;
40: } else {
41: super.write(str);
42: }
43: }
44:
45: }
|