diff --git a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java
index bcde2e95..32d33c9c 100644
--- a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java
+++ b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneRuleSet.java
@@ -52,11 +52,11 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet
// this creates the appropriate instance when we encounter our
// prefix tag
dig.addRule(prefix, new Rule() {
- public void begin (String namespace, String name,
+ @Override public void begin (String namespace, String name,
Attributes attributes) throws Exception {
digester.push(createMisoSceneModel());
}
- public void end (String namespace, String name) throws Exception {
+ @Override public void end (String namespace, String name) throws Exception {
digester.pop();
}
});
@@ -70,14 +70,23 @@ public class SparseMisoSceneRuleSet implements NestableRuleSet
dig.addObjectCreate(sprefix, Section.class.getName());
dig.addRule(sprefix, new SetPropertyFieldsRule());
dig.addRule(sprefix + "/base", new SetFieldRule("baseTileIds"));
- dig.addObjectCreate(sprefix + "/objects/object",
- ObjectInfo.class.getName());
- dig.addRule(sprefix + "/objects/object", new SetPropertyFieldsRule());
- dig.addSetNext(sprefix + "/objects/object", "addObject",
- ObjectInfo.class.getName());
+ addObjectExtractor(dig, "objects", sprefix, "addObject");
dig.addSetNext(sprefix, "setSection", Section.class.getName());
}
+ /**
+ * Adds a set of rules to dig to create an Object info from the element at
+ * base/type/object and calls methodName on the object on dig's stack.
+ */
+ public static void addObjectExtractor (Digester dig, String type, String base,
+ String methodName)
+ {
+ String prefix = base + "/" + type + "/object";
+ dig.addObjectCreate(prefix, ObjectInfo.class);
+ dig.addRule(prefix, new SetPropertyFieldsRule());
+ dig.addSetNext(prefix, methodName, ObjectInfo.class.getName());
+ }
+
protected SparseMisoSceneModel createMisoSceneModel ()
{
return new SparseMisoSceneModel();
diff --git a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java
index 090d51fa..eb31e8cc 100644
--- a/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java
+++ b/src/java/com/threerings/miso/tools/xml/SparseMisoSceneWriter.java
@@ -66,8 +66,8 @@ public class SparseMisoSceneWriter implements NestableWriter
writer.dataElement("defTileSet", Integer.toString(model.defTileSet));
writer.startElement("sections");
- for (Iterator iter = model.getSections(); iter.hasNext(); ) {
- Section sect = (Section)iter.next();
+ for (Iterator iter = model.getSections(); iter.hasNext(); ) {
+ Section sect = iter.next();
if (sect.isBlank()) {
continue;
}
@@ -95,37 +95,39 @@ public class SparseMisoSceneWriter implements NestableWriter
// write our interesting object tile information
for (int ii = 0; ii < sect.objectInfo.length; ii++) {
- ObjectInfo info = sect.objectInfo[ii];
- attrs = new AttributesImpl();
- attrs.addAttribute("", "tileId", "", "",
- String.valueOf(info.tileId));
- attrs.addAttribute("", "x", "", "", String.valueOf(info.x));
- attrs.addAttribute("", "y", "", "", String.valueOf(info.y));
-
- if (!StringUtil.isBlank(info.action)) {
- attrs.addAttribute("", "action", "", "", info.action);
- }
- if (info.priority != 0) {
- attrs.addAttribute("", "priority", "", "",
- String.valueOf(info.priority));
- }
- if (info.sx != 0 || info.sy != 0) {
- attrs.addAttribute("", "sx", "", "",
- String.valueOf(info.sx));
- attrs.addAttribute("", "sy", "", "",
- String.valueOf(info.sy));
- attrs.addAttribute("", "sorient", "", "",
- String.valueOf(info.sorient));
- }
- if (info.zations != 0) {
- attrs.addAttribute("", "zations", "", "",
- String.valueOf(info.zations));
- }
- writer.emptyElement("", "object", "", attrs);
+ writeInterestingObject(sect.objectInfo[ii], writer);
}
writer.endElement("objects");
writer.endElement("section");
}
writer.endElement("sections");
}
+
+ /**
+ * Writes info out to writer.
+ */
+ public static void writeInterestingObject (ObjectInfo info, DataWriter writer)
+ throws SAXException
+ {
+ AttributesImpl attrs = new AttributesImpl();
+ attrs.addAttribute("", "tileId", "", "", String.valueOf(info.tileId));
+ attrs.addAttribute("", "x", "", "", String.valueOf(info.x));
+ attrs.addAttribute("", "y", "", "", String.valueOf(info.y));
+
+ if (!StringUtil.isBlank(info.action)) {
+ attrs.addAttribute("", "action", "", "", info.action);
+ }
+ if (info.priority != 0) {
+ attrs.addAttribute("", "priority", "", "", String.valueOf(info.priority));
+ }
+ if (info.sx != 0 || info.sy != 0) {
+ attrs.addAttribute("", "sx", "", "", String.valueOf(info.sx));
+ attrs.addAttribute("", "sy", "", "", String.valueOf(info.sy));
+ attrs.addAttribute("", "sorient", "", "", String.valueOf(info.sorient));
+ }
+ if (info.zations != 0) {
+ attrs.addAttribute("", "zations", "", "", String.valueOf(info.zations));
+ }
+ writer.emptyElement("", "object", "", attrs);
+ }
}