From 64fe894062e835882829fa4f9fe1d41c311971be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Thu, 25 Mar 2010 21:15:44 +0100 Subject: [PATCH] ExtMXSerializer: added possibility to set default encoding. --- src/brut/androlib/res/AndrolibResources.java | 1 + .../androlib/res/util/ExtMXSerializer.java | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/brut/androlib/res/AndrolibResources.java b/src/brut/androlib/res/AndrolibResources.java index 4a87459c..5fd23502 100644 --- a/src/brut/androlib/res/AndrolibResources.java +++ b/src/brut/androlib/res/AndrolibResources.java @@ -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; } diff --git a/src/brut/androlib/res/util/ExtMXSerializer.java b/src/brut/androlib/res/util/ExtMXSerializer.java index 72a7d1f6..0fdbb87e 100644 --- a/src/brut/androlib/res/util/ExtMXSerializer.java +++ b/src/brut/androlib/res/util/ExtMXSerializer.java @@ -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; }