xml export/import of null objects fixed

This commit is contained in:
honfika@gmail.com
2015-01-18 15:11:10 +01:00
parent 19256260d0
commit b52fff07a9
4 changed files with 38 additions and 18 deletions

View File

@@ -95,13 +95,8 @@ public class SwfXmlExporter {
generateXml(doc, node, "swf", swf, false, 0);
}
private static void generateXml(Document doc, Node node, String name, Object obj, boolean addAsChildNode, int level){
if (obj == null) {
return;
}
Class cls = obj.getClass();
Object value = null;
private static void generateXml(Document doc, Node node, String name, Object obj, boolean isListItem, int level){
Class cls = obj != null ? obj.getClass() : null;
if (cls == Byte.class || cls == byte.class ||
cls == Short.class || cls == short.class ||
@@ -112,19 +107,19 @@ public class SwfXmlExporter {
cls == Boolean.class || cls == boolean.class ||
cls == Character.class || cls == char.class ||
cls == String.class) {
value = obj;
Object value = obj;
if (value instanceof String) {
value = Helper.escapeXML((String) value);
value = Helper.removeInvalidXMLCharacters((String) value);
}
if (addAsChildNode) {
if (isListItem) {
Element childNode = doc.createElement(name);
childNode.setTextContent(value.toString());
node.appendChild(childNode);
} else {
((Element) node).setAttribute(name, value.toString());
}
} else if (cls.isEnum()) {
} else if (cls != null && cls.isEnum()) {
((Element) node).setAttribute(name, obj.toString());
} else if (obj instanceof ByteArrayRange) {
ByteArrayRange range = (ByteArrayRange) obj;
@@ -135,22 +130,22 @@ public class SwfXmlExporter {
}
((Element) node).setAttribute(name, sb.toString());
} else if (List.class.isAssignableFrom(cls)) {
} else if (cls != null && List.class.isAssignableFrom(cls)) {
List list = (List) obj;
Element listNode = doc.createElement(name);
node.appendChild(listNode);
for (int i = 0; i < list.size(); i++) {
generateXml(doc, listNode, "item", list.get(i), true, level + 1);
}
} else if (cls.isArray()) {
String arrayType = cls.getComponentType().getSimpleName();
} else if (cls != null && cls.isArray()) {
Class arrayType = cls.getComponentType();
Element arrayNode = doc.createElement(name);
node.appendChild(arrayNode);
int length = Array.getLength(obj);
for (int i = 0; i < length; i++) {
generateXml(doc, arrayNode, "item", Array.get(obj, i), true, level + 1);
}
} else {
} else if (obj != null) {
if (obj instanceof LazyObject) {
((LazyObject) obj).load();
}
@@ -182,6 +177,12 @@ public class SwfXmlExporter {
Logger.getLogger(SwfXmlExporter.class.getName()).log(Level.SEVERE, null, ex);
}
}
} else {
if (isListItem) {
Element childNode = doc.createElement(name);
childNode.setAttribute("isNull", Boolean.TRUE.toString());
node.appendChild(childNode);
}
}
}
}

View File

@@ -81,6 +81,14 @@ import com.jpexs.decompiler.flash.types.SOUNDINFO;
import com.jpexs.decompiler.flash.types.TEXTRECORD;
import com.jpexs.decompiler.flash.types.ZONEDATA;
import com.jpexs.decompiler.flash.types.ZONERECORD;
import com.jpexs.decompiler.flash.types.filters.BEVELFILTER;
import com.jpexs.decompiler.flash.types.filters.BLURFILTER;
import com.jpexs.decompiler.flash.types.filters.COLORMATRIXFILTER;
import com.jpexs.decompiler.flash.types.filters.CONVOLUTIONFILTER;
import com.jpexs.decompiler.flash.types.filters.DROPSHADOWFILTER;
import com.jpexs.decompiler.flash.types.filters.GLOWFILTER;
import com.jpexs.decompiler.flash.types.filters.GRADIENTBEVELFILTER;
import com.jpexs.decompiler.flash.types.filters.GRADIENTGLOWFILTER;
import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
@@ -213,6 +221,11 @@ public class SwfXmlImporter {
processElement(element, childObj, swf);
return childObj;
} else {
String isNullAttr = element.getAttribute("isNull");
if (Boolean.parseBoolean(isNullAttr)) {
return null;
}
return getAs(requiredType, element.getTextContent());
}
}
@@ -249,6 +262,10 @@ public class SwfXmlImporter {
PIX24.class, RECT.class, RGB.class, RGBA.class, SHAPE.class, SHAPEWITHSTYLE.class, SOUNDENVELOPE.class,
SOUNDINFO.class, TEXTRECORD.class, ZONEDATA.class, ZONERECORD.class,
CurvedEdgeRecord.class, EndShapeRecord.class, StraightEdgeRecord.class, StyleChangeRecord.class,
BEVELFILTER.class, BLURFILTER.class, COLORMATRIXFILTER.class, CONVOLUTIONFILTER.class,
DROPSHADOWFILTER.class, GLOWFILTER.class, GRADIENTBEVELFILTER.class, GRADIENTGLOWFILTER.class,
AVM2ConstantPool.class, Decimal.class, Namespace.class, NamespaceSet.class, Multiname.class, MethodInfo.class,
ValueKind.class, InstanceInfo.class, Traits.class, TraitClass.class, TraitFunction.class,
TraitMethodGetterSetter.class, TraitSlotConst.class, ClassInfo.class, ScriptInfo.class, MethodBody.class,

View File

@@ -869,7 +869,7 @@ public class Helper {
return text;
}
public static String escapeXML(String text) {
public static String removeInvalidXMLCharacters(String text) {
StringBuilder sb = new StringBuilder(text.length());
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
@@ -878,9 +878,9 @@ public class Helper {
}
}
return escapeHTML(sb.toString());
return sb.toString();
}
public static Shape imageToShape(BufferedImage image) {
Area area = new Area();
Rectangle rectangle = new Rectangle();