ResXmlEncodable: splitted toResXmlFormat() into 2 methods: encodeAsResXmlAttr() and encodeAsResXmlValue().

This commit is contained in:
Ryszard Wiśniewski 2011-05-09 11:17:50 +02:00
parent b3866d034d
commit 31274e73dc
14 changed files with 33 additions and 21 deletions

View File

@ -51,7 +51,7 @@ public class ResArrayValue extends ResBagValue implements ResValuesXmlSerializab
serializer.attribute(null, "name", res.getResSpec().getName());
for (int i = 0; i < mItems.length; i++) {
serializer.startTag(null, "item");
serializer.text(mItems[i].toResXmlFormat());
serializer.text(mItems[i].encodeAsResXmlValue());
serializer.endTag(null, "item");
}
serializer.endTag(null, type);

View File

@ -31,8 +31,7 @@ public class ResBoolValue extends ResScalarValue {
return mValue;
}
@Override
public String toResXmlFormat() {
protected String encodeAsResXml() {
return mValue ? "true" : "false";
}
}

View File

@ -25,7 +25,7 @@ public class ResColorValue extends ResIntValue {
}
@Override
public String toResXmlFormat() {
protected String encodeAsResXml() {
return String.format("#%08x", mValue);
}
}

View File

@ -28,7 +28,7 @@ public class ResDimenValue extends ResIntValue {
}
@Override
public String toResXmlFormat() throws AndrolibException {
protected String encodeAsResXml() throws AndrolibException {
return TypedValue.coerceToString(TypedValue.TYPE_DIMENSION, mValue);
}
}

View File

@ -31,8 +31,7 @@ public class ResFloatValue extends ResScalarValue {
return mValue;
}
@Override
public String toResXmlFormat() {
protected String encodeAsResXml() {
return String.valueOf(mValue);
}
}

View File

@ -28,7 +28,7 @@ public class ResFractionValue extends ResIntValue {
}
@Override
public String toResXmlFormat() throws AndrolibException {
protected String encodeAsResXml() throws AndrolibException {
return TypedValue.coerceToString(TypedValue.TYPE_FRACTION, mValue);
}
}

View File

@ -37,8 +37,7 @@ public class ResIntValue extends ResScalarValue {
return mValue;
}
@Override
public String toResXmlFormat() throws AndrolibException {
protected String encodeAsResXml() throws AndrolibException {
return String.valueOf(mValue);
}
}

View File

@ -33,7 +33,7 @@ public class ResPluralsValue extends ResBagValue implements ResValuesXmlSerializ
mItems = new String[6];
for (int i = 0; i < items.length; i++) {
mItems[items[i].m1 - BAG_KEY_PLURALS_START] =
((ResStringValue) items[i].m2).toResXmlFormat();
((ResStringValue) items[i].m2).encodeAsResXmlValue();
}
}

View File

@ -38,8 +38,7 @@ public class ResReferenceValue extends ResIntValue {
mTheme = theme;
}
@Override
public String toResXmlFormat() throws AndrolibException {
protected String encodeAsResXml() throws AndrolibException {
if (isNull()) {
return "@null";
}

View File

@ -35,7 +35,13 @@ public abstract class ResScalarValue extends ResValue
mRawValue = rawValue;
}
public abstract String toResXmlFormat() throws AndrolibException;
public String encodeAsResXmlAttr() throws AndrolibException {
return encodeAsResXml();
}
public String encodeAsResXmlValue() throws AndrolibException {
return encodeAsResXml();
}
public void serializeToResValuesXml(XmlSerializer serializer, ResResource res)
throws IOException, AndrolibException {
@ -49,7 +55,7 @@ public abstract class ResScalarValue extends ResValue
}
serializer.attribute(null, "name", res.getResSpec().getName());
String body = toResXmlFormat();
String body = encodeAsResXmlValue();
if (! body.isEmpty()) {
serializer.ignorableWhitespace(body);
}
@ -60,4 +66,6 @@ public abstract class ResScalarValue extends ResValue
public String getType() {
return mType;
}
protected abstract String encodeAsResXml() throws AndrolibException;
}

View File

@ -16,6 +16,7 @@
package brut.androlib.res.data.value;
import brut.androlib.AndrolibException;
/**
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
@ -30,12 +31,18 @@ public class ResStringValue extends ResScalarValue {
super(type, value);
}
public String getValue() {
@Override
public String encodeAsResXmlAttr() {
return mRawValue;
}
@Override
public String toResXmlFormat() {
public String encodeAsResXmlValue() {
return mRawValue;
}
@Override
protected String encodeAsResXml() throws AndrolibException {
throw new UnsupportedOperationException();
}
}

View File

@ -44,7 +44,7 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab
serializer.startTag(null, "style");
serializer.attribute(null, "name", res.getResSpec().getName());
if (! mParent.isNull()) {
serializer.attribute(null, "parent", mParent.toResXmlFormat());
serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr());
}
for (int i = 0; i < mItems.length; i++) {
ResResSpec spec = mItems[i].m1.getReferent();
@ -52,7 +52,7 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab
String value = attr.convertToResXmlFormat(mItems[i].m2);
if (value == null) {
value = mItems[i].m2.toResXmlFormat();
value = mItems[i].m2.encodeAsResXmlValue();
}
if (value == null) {

View File

@ -37,7 +37,7 @@ public class ResAttrDecoder {
decoded = attr.convertToResXmlFormat(resValue);
}
return decoded != null ? decoded : resValue.toResXmlFormat();
return decoded != null ? decoded : resValue.encodeAsResXmlAttr();
}
public ResPackage getCurrentPackage() throws AndrolibException {

View File

@ -22,5 +22,6 @@ import brut.androlib.AndrolibException;
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
*/
public interface ResXmlEncodable {
public String toResXmlFormat() throws AndrolibException;
public String encodeAsResXmlAttr() throws AndrolibException;
public String encodeAsResXmlValue() throws AndrolibException;
}