import java.io.Writer;
import java.util.regex.Pattern;
import com.thoughtworks.xstream.core.util.QuickWriter;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
public class MyPrettyPrintWriter extends PrettyPrintWriter {
private static final char[] AMP = "&".toCharArray();
private static final char[] LT = "<".toCharArray();
private static final char[] GT = ">".toCharArray();
private static final char[] SLASH_R = " ".toCharArray();
private static final char[] QUOT = """.toCharArray();
private static final char[] APOS = "'".toCharArray();
public LocalPrettyPrintWriter(Writer writer) {
super(writer);
}
protected void writeText(QuickWriter writer, String text) {
String CDATAPrefix = "<![CDATA[";
String CDATASuffix = "]]>";
if (!text.startsWith(CDATAPrefix) && !Pattern.matches("[^[0-9]]+", text)) {
text = CDATAPrefix+text+CDATASuffix;
}
int length = text.length();
if (!text.startsWith(CDATAPrefix)) {
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
switch (c) {
case '&':
writer.write(AMP);
break;
case '<':
writer.write(LT);
break;
case '>':
writer.write(GT);
break;
case '"':
writer.write(QUOT);
break;
case '\'':
writer.write(APOS);
break;
case '\r':
writer.write(SLASH_R);
break;
default:
writer.write(c);
}
}
} else {
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
writer.write(c);
}
}
}
}
import java.util.regex.Pattern;
import com.thoughtworks.xstream.core.util.QuickWriter;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
public class MyPrettyPrintWriter extends PrettyPrintWriter {
private static final char[] AMP = "&".toCharArray();
private static final char[] LT = "<".toCharArray();
private static final char[] GT = ">".toCharArray();
private static final char[] SLASH_R = " ".toCharArray();
private static final char[] QUOT = """.toCharArray();
private static final char[] APOS = "'".toCharArray();
public LocalPrettyPrintWriter(Writer writer) {
super(writer);
}
protected void writeText(QuickWriter writer, String text) {
String CDATAPrefix = "<![CDATA[";
String CDATASuffix = "]]>";
if (!text.startsWith(CDATAPrefix) && !Pattern.matches("[^[0-9]]+", text)) {
text = CDATAPrefix+text+CDATASuffix;
}
int length = text.length();
if (!text.startsWith(CDATAPrefix)) {
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
switch (c) {
case '&':
writer.write(AMP);
break;
case '<':
writer.write(LT);
break;
case '>':
writer.write(GT);
break;
case '"':
writer.write(QUOT);
break;
case '\'':
writer.write(APOS);
break;
case '\r':
writer.write(SLASH_R);
break;
default:
writer.write(c);
}
}
} else {
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
writer.write(c);
}
}
}
}
import java.io.Writer;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.XppDriver;
public class MyXppDriver extends XppDriver {
public HierarchicalStreamWriter createWriter(Writer out) {
return new MyPrettyPrintWriter(out);
}
}
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.XppDriver;
public class MyXppDriver extends XppDriver {
public HierarchicalStreamWriter createWriter(Writer out) {
return new MyPrettyPrintWriter(out);
}
}
'자바' 카테고리의 다른 글
[메모] jdk 1.4에서 로그 메시지 막기. (0) | 2008.06.28 |
---|---|
[framework] Spring XML설정파일을 위한 12가지 가장 좋은 선택 (0) | 2008.06.28 |
[개발툴] eclipse ganymede 릴리즈 임박.. (0) | 2008.06.25 |
[개발툴] Eclipse Ganymede 릴리즈 소식 (0) | 2008.06.18 |
[DB] 가벼운 SQL 인터페이스.. (0) | 2008.06.14 |