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

com.thaiopensource.xml.sax.Sax2XMLReaderCreator Maven / Gradle / Ivy

The newest version!
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 XMLReaders 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 XMLReaders.
   */
  public Sax2XMLReaderCreator() {
    this.className = null;
  }

 /**
  * Constructs a Sax2XMLReaderCreator that constructs XMLReaders 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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy