ExtMXSerializer: added possibility to set default encoding.

This commit is contained in:
Ryszard Wiśniewski 2010-03-25 21:15:44 +01:00
parent ac1bc7ca54
commit 64fe894062
2 changed files with 25 additions and 2 deletions

View File

@ -145,6 +145,7 @@ final public class AndrolibResources {
serial.setProperty(serial.PROPERTY_SERIALIZER_INDENTATION, " ");
serial.setProperty(serial.PROPERTY_SERIALIZER_LINE_SEPARATOR,
System.getProperty("line.separator"));
serial.setProperty(ExtMXSerializer.PROPERTY_DEFAULT_ENCODING, "UTF-8");
return serial;
}

View File

@ -28,12 +28,34 @@ public class ExtMXSerializer extends MXSerializer {
@Override
public void startDocument(String encoding, Boolean standalone) throws
IOException, IllegalArgumentException, IllegalStateException {
super.startDocument(encoding != null ? encoding : "UTF-8", standalone);
super.startDocument(encoding != null ? encoding : mDefaultEncoding,
standalone);
super.out.write(lineSeparator);
}
@Override
public void setOutput(OutputStream os, String encoding) throws IOException {
super.setOutput(os, encoding != null ? encoding : "UTF-8");
super.setOutput(os, encoding != null ? encoding : mDefaultEncoding);
}
@Override
public Object getProperty(String name) throws IllegalArgumentException {
if (PROPERTY_DEFAULT_ENCODING.equals(name)) {
return mDefaultEncoding;
}
return super.getProperty(name);
}
@Override
public void setProperty(String name, Object value)
throws IllegalArgumentException, IllegalStateException {
if (PROPERTY_DEFAULT_ENCODING.equals(name)) {
mDefaultEncoding = (String) value;
}
super.setProperty(name, value);
}
public final static String PROPERTY_DEFAULT_ENCODING = "DEFAULT_ENCODING";
private String mDefaultEncoding;
}