From 2c8dae0570e8a9c05dd5daeb1a19acacf2775191 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 29 Nov 2001 20:34:13 +0000 Subject: [PATCH] Wrote a simple miso scene parser. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@690 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../miso/tools/xml/MisoSceneParser.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/java/com/threerings/miso/tools/xml/MisoSceneParser.java diff --git a/src/java/com/threerings/miso/tools/xml/MisoSceneParser.java b/src/java/com/threerings/miso/tools/xml/MisoSceneParser.java new file mode 100644 index 000000000..0afd34460 --- /dev/null +++ b/src/java/com/threerings/miso/tools/xml/MisoSceneParser.java @@ -0,0 +1,58 @@ +// +// $Id: MisoSceneParser.java,v 1.1 2001/11/29 20:34:13 mdb Exp $ + +package com.threerings.miso.tools.scene.xml; + +import java.io.IOException; +import java.io.FileInputStream; + +import org.xml.sax.SAXException; +import org.apache.commons.digester.Digester; + +import com.threerings.miso.scene.MisoSceneModel; + +/** + * A simple class for parsing a standalone miso scene model. + */ +public class MisoSceneParser +{ + /** + * Constructs a miso scene parser that parses scenes with the + * specified XML path prefix. See the {@link + * MisoSceneRuleSet#MisoSceneRuleSet} documentation for more + * information. + */ + public MisoSceneParser (String prefix) + { + // create and configure our digester + _digester = new Digester(); + MisoSceneRuleSet set = new MisoSceneRuleSet(); + set.setPrefix(prefix); + _digester.addRuleSet(set); + _digester.addSetNext(prefix, "setSceneModel", + MisoSceneModel.class.getName()); + } + + /** + * Parses the XML file at the specified path into a miso scene model. + */ + public MisoSceneModel parseScene (String path) + throws IOException, SAXException + { + _model = null; + _digester.push(this); + _digester.parse(new FileInputStream(path)); + return _model; + } + + /** + * Called by the parser once the scene is parsed. + */ + public void setSceneModel (MisoSceneModel model) + { + _model = model; + } + + protected Digester _digester; + protected MisoSceneModel _model; +}