All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.xml.reader.PullParserReader Maven / Gradle / Ivy

Go to download

This Project includes a variant of the Jadex XML Parser that uses the Android XML Pull API.

There is a newer version: 3.0.115
Show newest version
package jadex.xml.reader;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.util.Xml;
import jadex.xml.SXML;
import jadex.xml.TypeInfoPathManager;
import jadex.xml.stax.XMLReporter;

public class PullParserReader extends AReader
{

	private XmlPullParserFactory factory;

	private boolean bulklink;

	public PullParserReader()
	{
		this(false, null, false);
	}

	public PullParserReader(boolean validate, XMLReporter reporter, boolean bulklink)
	{
		this(validate, false, reporter, bulklink);
	}

	public PullParserReader(boolean validate, boolean coalescing, XMLReporter reporter, boolean bulklink)
	{
		super(bulklink, reporter);
		try
		{
			factory = XmlPullParserFactory.newInstance();
			factory.setNamespaceAware(true);
			factory.setValidating(validate);
			this.bulklink = bulklink;
		} catch (XmlPullParserException e)
		{
			e.printStackTrace();
		}
	}

	@Override
	public Object read(TypeInfoPathManager tipmanager, IObjectReaderHandler handler, InputStream input, ClassLoader classloader,
			Object callcontext) throws Exception
	{
		return read(tipmanager, handler, new InputStreamReader(input, SXML.DEFAULT_ENCODING), classloader, callcontext);
	}

	protected IXMLReader createXMLReader(InputStream input) {
		try {
			XmlPullParser parser = factory.newPullParser();
			parser.setInput(input, Xml.Encoding.UTF_8.name());
			return new PullParserWrapper(parser);
		} catch (XmlPullParserException e) {
			e.printStackTrace();
			return null;
		}
	}

	protected IXMLReader createXMLReader(Reader input) {
		try {
			XmlPullParser parser = factory.newPullParser();
			parser.setInput(input);
			return new PullParserWrapper(parser);
		} catch (XmlPullParserException e) {
			e.printStackTrace();
			return null;
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy