ResXmlSerializer: normal value serializing if attr is undefined.

This commit is contained in:
Ryszard Wiśniewski 2010-03-13 12:51:13 +01:00
parent 8c0a1a0c98
commit 2d9580eb86

View File

@ -18,11 +18,11 @@
package brut.androlib.res.decoder; package brut.androlib.res.decoder;
import brut.androlib.*; import brut.androlib.*;
import brut.androlib.err.UndefinedResObject;
import brut.androlib.res.AndrolibResources; import brut.androlib.res.AndrolibResources;
import brut.androlib.res.data.ResPackage; import brut.androlib.res.data.ResPackage;
import brut.androlib.res.data.value.ResAttr; import brut.androlib.res.data.value.ResAttr;
import brut.androlib.res.data.value.ResScalarValue; import brut.androlib.res.data.value.ResScalarValue;
import brut.androlib.res.data.value.ResValue;
import java.io.IOException; import java.io.IOException;
import org.xmlpull.mxp1_serializer.MXSerializer; import org.xmlpull.mxp1_serializer.MXSerializer;
import org.xmlpull.v1.XmlSerializer; import org.xmlpull.v1.XmlSerializer;
@ -44,24 +44,35 @@ public class ResXmlSerializer extends MXSerializer {
if (! mDecodingEnabled) { if (! mDecodingEnabled) {
return super.attribute(namespace, name, value); return super.attribute(namespace, name, value);
} }
String origVal = value;
try { try {
ResScalarValue resValue = ResScalarValue resValue =
mCurrentPackage.getValueFactory().factory(value); mCurrentPackage.getValueFactory().factory(value);
value = null;
if (namespace == null || namespace.isEmpty()) { if (namespace != null && ! namespace.isEmpty()) {
value = resValue.toResXmlFormat();
} else {
String pkgName = RES_NAMESPACE.equals(namespace) ? String pkgName = RES_NAMESPACE.equals(namespace) ?
"android" : mCurrentPackage.getName(); "android" : mCurrentPackage.getName();
ResAttr attr = (ResAttr) mCurrentPackage.getResTable() try {
.getValue(pkgName, "attr", name); ResAttr attr = (ResAttr) mCurrentPackage.getResTable()
value = attr.convertToResXmlFormat(resValue); .getValue(pkgName, "attr", name);
value = attr.convertToResXmlFormat(resValue);
} catch (UndefinedResObject ex) {
System.err.println(String.format(
"warning: udefined attr when decoding: " +
"ns=%s, name=%s, value=%s",
namespace, name, origVal));
}
}
if (value == null) {
value = resValue.toResXmlFormat();
} }
} catch (AndrolibException ex) { } catch (AndrolibException ex) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"could not decode attribute: ns=%s, name=%s, value=%s", "could not decode attribute: ns=%s, name=%s, value=%s",
namespace, name, value), ex); namespace, name, origVal), ex);
} }
if (value == null) { if (value == null) {