com.thaiopensource.xml.sax.Sax2XMLReaderCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicketstuff-jing Show documentation
Show all versions of wicketstuff-jing Show documentation
Jing is a validator for RELAX NG and other schema languages. This
project was taken from http://code.google.com/p/jing-trang and
mavenized for inclusion in the Wicket Stuff HTML Validator.
The code was taken from the 20091111 release.
package com.thaiopensource.xml.sax;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.helpers.XMLReaderFactory;
import com.thaiopensource.xml.sax.XMLReaderCreator;
/**
* An XMLReaderCreator
that creates XMLReader
s using the SAX2 XMLReaderFactory
.
* An instance of this class is safe for concurrent access by multiple threads.
*
* @see org.xml.sax.helpers.XMLReaderFactory
* @author James Clark
*/
public class Sax2XMLReaderCreator implements XMLReaderCreator {
private final String className;
/**
* Constructs a Sax2XMLReaderCreator
that uses system defaults to construct XMLReader
s.
*/
public Sax2XMLReaderCreator() {
this.className = null;
}
/**
* Constructs a Sax2XMLReaderCreator
that constructs XMLReader
s with the specified
* class name.
*
* @param className the fully-qualified name of the class implementing XMLReader
;
* if null
equivalent to the no-argument constructor
*
*/
public Sax2XMLReaderCreator(String className) {
this.className = className;
}
public XMLReader createXMLReader() throws SAXException {
XMLReader xr;
if (className == null)
xr = XMLReaderFactory.createXMLReader();
else
xr = XMLReaderFactory.createXMLReader(className);
xr.setFeature("http://xml.org/sax/features/namespaces", true);
xr.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
try {
xr.setFeature("http://xml.org/sax/features/validation", false);
}
catch (SAXNotRecognizedException e) {
}
catch (SAXNotSupportedException e) {
}
return xr;
}
}