//
// $Id: MisoSceneRuleSet.java,v 1.6 2002/02/02 01:09:53 mdb Exp $

package com.threerings.miso.scene.tools.xml;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.RuleSetBase;

import com.samskivert.xml.SetFieldRule;

import com.threerings.miso.scene.MisoSceneModel;

/**
 * Used to parse a {@link MisoSceneModel} from XML.
 */
public class MisoSceneRuleSet extends RuleSetBase
{
    /**
     * Configures the rule set to match scenes with the supplied prefix.
     * For example, passing <code>scene.miso</code> will match the scene
     * in the following XML file:
     *
     * <pre>
     * &lt;scene&gt;
     *   &lt;miso&gt;
     *     &lt;width&gt;50&lt;/width&gt;
     *     &lt;height&gt;50&lt;/height&gt;
     *     &lt;!-- ... --&gt;
     *   &lt;/miso&gt;
     * &lt;/scene&gt;
     * </pre>
     */
    public void setPrefix (String prefix)
    {
        _prefix = prefix;
    }

    /**
     * Adds the necessary rules to the digester to parse our miso scene
     * data.
     */
    public void addRuleInstances (Digester digester)
    {
        // this creates the appropriate instance when we encounter our
        // prefix tag
        digester.addObjectCreate(_prefix, MisoSceneModel.class.getName());

        // set up rules to parse and set our fields
        digester.addRule(_prefix + "/width",
                         new SetFieldRule(digester, "width"));
        digester.addRule(_prefix + "/height",
                         new SetFieldRule(digester, "height"));
        digester.addRule(_prefix + "/base",
                         new SetFieldRule(digester, "baseTileIds"));
        digester.addRule(_prefix + "/fringe",
                         new SetFieldRule(digester, "fringeTileIds"));
        digester.addRule(_prefix + "/object",
                         new SetFieldRule(digester, "objectTileIds"));
        digester.addRule(_prefix + "/actions",
                         new SetFieldRule(digester, "objectActions"));
    }

    /** The prefix at which me match our scenes. */
    protected String _prefix;
}

@@ -34,9 +34,9 @@
 v 1.
-6
+7
  200
@@ -50,13 +50,13 @@
  01:
-09:53
+32:18
  mdb
@@ -199,24 +199,73 @@
 leSetBase;%0A%0A
+import com.samskivert.xml.CallMethodSpecialRule;%0A
 import com.s
@@ -2027,24 +2027,770 @@
 tActions%22));
+%0A%0A        // we have to unfuck the objectActions field in the event that%0A        // there's one object in the objects element which has a blank%0A        // action string (which the parser will parse as a zero length%0A        // array, when we want a length one array with a blank string)%0A        digester.addRule(_prefix, new CallMethodSpecialRule(digester) %7B%0A            public void parseAndSet (String bodyText, Object target)%0A                throws Exception%0A            %7B%0A                MisoSceneModel model = (MisoSceneModel)target;%0A                if (model.objectTileIds.length %3E 0 &&%0A                    model.objectActions.length == 0) %7B%0A                    model.objectActions = new String%5B1%5D;%0A                %7D%0A            %7D%0A        %7D);
 %0A    %7D%0A%0A    

Add code to MisoSceneModel parser that handles the situation where a scene with a single object that has no action string gets parsed as a scene with zero action strings instead of a scene with a single empty action string.