IndentPrinter.java
5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Decompiled with CFR 0_118.
*/
package com.day.jcr.vault.util.xml.serialize;
import com.day.jcr.vault.util.xml.serialize.OutputFormat;
import com.day.jcr.vault.util.xml.serialize.Printer;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
public class IndentPrinter
extends Printer {
private StringBuffer _line = new StringBuffer(80);
private StringBuffer _text = new StringBuffer(20);
private int _spaces = 0;
private int _thisIndent = 0;
private int _nextIndent = 0;
public IndentPrinter(Writer writer, OutputFormat format) {
super(writer, format);
}
public void enterDTD() {
if (this._dtdWriter == null) {
this._line.append(this._text);
this._text = new StringBuffer(20);
this.flushLine(false);
this._dtdWriter = new StringWriter();
this._docWriter = this._writer;
this._writer = this._dtdWriter;
}
}
public String leaveDTD() {
if (this._writer == this._dtdWriter) {
this._line.append(this._text);
this._text = new StringBuffer(20);
this.flushLine(false);
this._writer = this._docWriter;
return this._dtdWriter.toString();
}
return null;
}
public void printText(String text) {
this._text.append(text);
}
public void printText(StringBuffer text) {
this._text.append(text.toString());
}
public void printText(char ch) {
this._text.append(ch);
}
public void printText(char[] chars, int start, int length) {
this._text.append(chars, start, length);
}
public void printSpace() {
if (this._text.length() > 0) {
block5 : {
if (this._format.getLineWidth() > 0 && this._thisIndent + this._line.length() + this._spaces + this._text.length() > this._format.getLineWidth()) {
this.flushLine(false);
try {
this._writer.write(this._format.getLineSeparator());
}
catch (IOException except) {
if (this._exception != null) break block5;
this._exception = except;
}
}
}
while (this._spaces > 0) {
this._line.append(' ');
--this._spaces;
}
this._line.append(this._text);
this._text = new StringBuffer(20);
}
++this._spaces;
}
public void breakLine() {
this.breakLine(false);
}
public void breakLine(boolean preserveSpace) {
block4 : {
if (this._text.length() > 0) {
while (this._spaces > 0) {
this._line.append(' ');
--this._spaces;
}
this._line.append(this._text);
this._text = new StringBuffer(20);
}
this.flushLine(preserveSpace);
try {
this._writer.write(this._format.getLineSeparator());
}
catch (IOException except) {
if (this._exception != null) break block4;
this._exception = except;
}
}
}
public void flushLine(boolean preserveSpace) {
block6 : {
if (this._line.length() > 0) {
try {
if (this._format.getIndenting() && !preserveSpace) {
int indent = this._thisIndent;
if (2 * indent > this._format.getLineWidth() && this._format.getLineWidth() > 0) {
indent = this._format.getLineWidth() / 2;
}
while (indent > 0) {
this._writer.write(32);
--indent;
}
}
this._thisIndent = this._nextIndent;
this._spaces = 0;
this._writer.write(this._line.toString());
this._line = new StringBuffer(40);
}
catch (IOException except) {
if (this._exception != null) break block6;
this._exception = except;
}
}
}
}
public void flush() {
block3 : {
if (this._line.length() > 0 || this._text.length() > 0) {
this.breakLine();
}
try {
this._writer.flush();
}
catch (IOException except) {
if (this._exception != null) break block3;
this._exception = except;
}
}
}
public void indent() {
this._nextIndent += this._format.getIndent();
}
public void unindent() {
this._nextIndent -= this._format.getIndent();
if (this._nextIndent < 0) {
this._nextIndent = 0;
}
if (this._line.length() + this._spaces + this._text.length() == 0) {
this._thisIndent = this._nextIndent;
}
}
public int getNextIndent() {
return this._nextIndent;
}
public void setNextIndent(int indent) {
this._nextIndent = indent;
}
public void setThisIndent(int indent) {
this._thisIndent = indent;
}
}