From 37bb440daf43eda2bc9588db32cd56f7e43a9a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Sat, 13 Mar 2010 02:25:11 +0100 Subject: [PATCH] ResXmlSerializer: parsing of attributes that aren't in android namespace. --- .../res/decoder/ResXmlSerializer.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/brut/androlib/res/decoder/ResXmlSerializer.java b/src/brut/androlib/res/decoder/ResXmlSerializer.java index 1dda556d..672a0c5f 100644 --- a/src/brut/androlib/res/decoder/ResXmlSerializer.java +++ b/src/brut/androlib/res/decoder/ResXmlSerializer.java @@ -21,6 +21,8 @@ import brut.androlib.*; import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResPackage; import brut.androlib.res.data.value.ResAttr; +import brut.androlib.res.data.value.ResScalarValue; +import brut.androlib.res.data.value.ResValue; import java.io.IOException; import org.xmlpull.mxp1_serializer.MXSerializer; import org.xmlpull.v1.XmlSerializer; @@ -42,19 +44,20 @@ public class ResXmlSerializer extends MXSerializer { if (! mDecodingEnabled) { return super.attribute(namespace, name, value); } - if (namespace == null || namespace.isEmpty()) { - return super.attribute(namespace, name, - AndrolibResources.escapeForResXml(value) - ); - } - String pkgName = RES_NAMESPACE.equals(namespace) ? - "android" : mCurrentPackage.getName(); - + try { - ResAttr attr = (ResAttr) mCurrentPackage.getResTable() - .getValue(pkgName, "attr", name); - value = attr.convertToResXmlFormat( - mCurrentPackage.getValueFactory().factory(value)); + ResScalarValue resValue = + mCurrentPackage.getValueFactory().factory(value); + + if (namespace == null || namespace.isEmpty()) { + value = resValue.toResXmlFormat(); + } else { + String pkgName = RES_NAMESPACE.equals(namespace) ? + "android" : mCurrentPackage.getName(); + ResAttr attr = (ResAttr) mCurrentPackage.getResTable() + .getValue(pkgName, "attr", name); + value = attr.convertToResXmlFormat(resValue); + } } catch (AndrolibException ex) { throw new IllegalArgumentException(String.format( "could not decode attribute: ns=%s, name=%s, value=%s",