Created XMLUtil to centralize our XML machinations and allow for
code-sharing between the tileset and scene XML antics. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@87 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
//
|
//
|
||||||
// $Id: XMLTileSetParser.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
|
// $Id: XMLTileSetParser.java,v 1.3 2001/07/20 08:08:59 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.tile;
|
package com.threerings.miso.tile;
|
||||||
|
|
||||||
import com.threerings.miso.Log;
|
import com.threerings.miso.Log;
|
||||||
|
import com.threerings.miso.util.XMLUtil;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import org.xml.sax.*;
|
import org.xml.sax.*;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import javax.xml.parsers.*;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an XML tileset description file and construct tileset objects
|
* Parse an XML tileset description file and construct tileset objects
|
||||||
@@ -78,12 +78,7 @@ public class XMLTileSetParser extends DefaultHandler
|
|||||||
public void loadTileSets (InputStream tis) throws IOException
|
public void loadTileSets (InputStream tis) throws IOException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
XMLReader xr = _pfactory.newSAXParser().getXMLReader();
|
XMLUtil.parse(this, tis);
|
||||||
|
|
||||||
xr.setContentHandler(this);
|
|
||||||
xr.setErrorHandler(this);
|
|
||||||
|
|
||||||
xr.parse(new InputSource(tis));
|
|
||||||
|
|
||||||
} catch (ParserConfigurationException pce) {
|
} catch (ParserConfigurationException pce) {
|
||||||
throw new IOException(pce.toString());
|
throw new IOException(pce.toString());
|
||||||
@@ -107,12 +102,4 @@ public class XMLTileSetParser extends DefaultHandler
|
|||||||
protected int _tsTsid;
|
protected int _tsTsid;
|
||||||
protected String _tsImgFile;
|
protected String _tsImgFile;
|
||||||
protected int[] _tsRowHeight, _tsTileCount;
|
protected int[] _tsRowHeight, _tsTileCount;
|
||||||
|
|
||||||
// the slithy tove from whence came the XMLReader object
|
|
||||||
protected static SAXParserFactory _pfactory;
|
|
||||||
|
|
||||||
static {
|
|
||||||
_pfactory = SAXParserFactory.newInstance();
|
|
||||||
_pfactory.setValidating(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
//
|
//
|
||||||
// $Id: CompiledSceneManager.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
// $Id: CompiledSceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class CompiledSceneManager extends SceneManagerImpl
|
public class CompiledSceneManager extends SceneManagerImpl
|
||||||
{
|
{
|
||||||
|
public void loadScenes (InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
//
|
//
|
||||||
// $Id: EditableSceneManager.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
// $Id: EditableSceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class EditableSceneManager extends SceneManagerImpl
|
public class EditableSceneManager extends SceneManagerImpl
|
||||||
{
|
{
|
||||||
|
public void loadScenes (InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
//
|
//
|
||||||
// $Id: SceneManager.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
// $Id: SceneManager.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the various scenes that are displayed during the game and
|
* Manages the various scenes that are displayed during the game and
|
||||||
* provides simplified retrieval and caching facilities.
|
* provides simplified retrieval and caching facilities.
|
||||||
@@ -19,4 +22,16 @@ public interface SceneManager
|
|||||||
* layer id.
|
* layer id.
|
||||||
*/
|
*/
|
||||||
public String[] getLayerNames ();
|
public String[] getLayerNames ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all scene objects described in the specified file into the
|
||||||
|
* set of available scenes.
|
||||||
|
*/
|
||||||
|
public void loadScenes (String fname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all scene objects described in the specified input stream
|
||||||
|
* into the set of available scenes.
|
||||||
|
*/
|
||||||
|
public void loadScenes (InputStream in) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
//
|
//
|
||||||
// $Id: SceneManagerImpl.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
// $Id: SceneManagerImpl.java,v 1.4 2001/07/20 08:08:59 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
|
import com.threerings.miso.Log;
|
||||||
|
|
||||||
|
import com.samskivert.util.ConfigUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public abstract class SceneManagerImpl implements SceneManager
|
public abstract class SceneManagerImpl implements SceneManager
|
||||||
{
|
{
|
||||||
public Scene getScene (int sid)
|
public Scene getScene (int sid)
|
||||||
@@ -15,4 +22,21 @@ public abstract class SceneManagerImpl implements SceneManager
|
|||||||
{
|
{
|
||||||
return Scene.XLATE_LAYERS;
|
return Scene.XLATE_LAYERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadScenes (String fname)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
InputStream tis = ConfigUtil.getStream(fname);
|
||||||
|
if (tis == null) {
|
||||||
|
Log.warning("Couldn't find file [fname=" + fname + "].");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadScenes(tis);
|
||||||
|
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
Log.warning("Exception loading tileset [fname=" + fname +
|
||||||
|
", ioe=" + ioe + "].");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// $Id: XMLUtil.java,v 1.1 2001/07/20 08:08:59 shaper Exp $
|
||||||
|
|
||||||
|
package com.threerings.miso.util;
|
||||||
|
|
||||||
|
import org.xml.sax.*;
|
||||||
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import javax.xml.parsers.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The XMLUtil class provides a simplified interface for XML parsing.
|
||||||
|
*
|
||||||
|
* <p> Classes wishing to parse XML data need only extend the
|
||||||
|
* <code>org.xml.sax.helpers.DefaultHandler</code> class, override the
|
||||||
|
* desired methods, and then call <code>XMLUtil.parse()</code>.
|
||||||
|
*/
|
||||||
|
public class XMLUtil
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Parse the XML data in the given input stream, using the
|
||||||
|
* specified handler object as both the content and error handler.
|
||||||
|
*/
|
||||||
|
public static void parse (DefaultHandler handler, InputStream in)
|
||||||
|
throws IOException, ParserConfigurationException, SAXException
|
||||||
|
{
|
||||||
|
XMLReader xr = _pfactory.newSAXParser().getXMLReader();
|
||||||
|
|
||||||
|
xr.setContentHandler(handler);
|
||||||
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
|
xr.parse(new InputSource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
// the slithy tove from whence came the XMLReader object
|
||||||
|
protected static SAXParserFactory _pfactory;
|
||||||
|
|
||||||
|
static {
|
||||||
|
_pfactory = SAXParserFactory.newInstance();
|
||||||
|
_pfactory.setValidating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user