JM§: how to import XML files for further processing

Alpedar said:
So if one asset type use extension .xml, other can use .tileset.xml and still keep lazymans xml extension.

Yeah, as I said, that should already be possible, the OgreXML loader should only react to "its own" xml types. @rhavin still didn't tell me if he actually tried this..

tehflah said:
AssetLoaders, AssetKeys, AssetManagers oh my! :p

Simplest example of the whole loader stuff I could think of is the NeoTexture loader. The texture loader even uses its own locator, but mainly to "hack" support for tgr files as textures like /Textures/procedural.tgr?NormalMap
normen said:
@rhavin still didn't tell me if he actually tried this..

I just started, but also have to create some leadsheets for our next gig, so im a little bit distracted atm.
What i did so far is pretty few, just a skelleton for a loader:
[java]package dmf;

import java.io.IOException;
import java.io.InputStreamReader;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoader;

/****************************************************************************
* DMF TilesetLoader for JM3s AssetManger
* @author .rhavin grobert */
public class TileSetLoader extends DefaultHandler implements AssetLoader
{
private TileSet tileSet = null;
@Override
public Object load(AssetInfo i) throws IOException
{
XMLReader xr;
try
{
xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler(this);
xr.setErrorHandler(this);
InputStreamReader r = new InputStreamReader(i.openStream());
xr.parse(new InputSource(r));
r.close();
return null;
}
catch (SAXException e)
{throw new IOException(i.getKey()+ " : " + e.toString());}
}

@Override
public void startDocument()
{
}

@Override
public void startElement(String uri, String localName, String qName,
Attributes attribs) throws SAXException
{

}

@Override
public void endElement(String uri, String name, String qName)
{
}

@Override
public void characters(char ch[], int start, int length)
{
}

@Override
public void endDocument() throws SAXException
{
}
}

[/java]

… but it already rises a question (that could shurely be answered by concentrated study of the src, but thats another story;–)
… so the question: is it save to have a private member like my
[java]private TileSet tileSet = null;[/java]
and can i rely on the assetmanager to only call one loader instance for a single file or does the asset loader may call the same instance for x files in paralel and is it my job to syncronize by having a collection of TileSets and an identifier for the actual one, set in startDocument()…?

You can define that behavior via the clone() method.

see here for a working solution