context: namespace Sax.Net.Helpers {
    using System;
    using System.IO;
  
    /// <summary>
    ///   Base class for deriving an XML filter.
    ///   <blockquote>
    ///     <em>
    ///       This module, both source code and documentation, is in the
    ///       Public Domain, and comes with <strong>NO WARRANTY</strong>.
    ///     </em>
    ///     See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
    ///     for further information.
    ///   </blockquote>
    ///   <para>
    ///     This class is designed to sit between an <see cref="IXmlReader" />
    ///     and the client application's event handlers.  By default, it
    ///     does nothing but pass requests up to the reader and events
    ///     on to the handlers unmodified, but subclasses can override
    ///     specific methods to modify the event stream or the configuration
    ///     requests as they pass through.
    ///   </para>
    /// </summary>
    /// <seealso cref="IXmlFilter" />
    /// <seealso cref="IXmlReader" />
    /// <seealso cref="IEntityResolver" />
    /// <seealso cref="IDTDHandler" />
    /// <seealso cref="IContentHandler" />
    /// <seealso cref="IErrorHandler" />
    public class XmlFilter : IXmlFilter, IEntityResolver, IDTDHandler, IContentHandler, IErrorHandler {
      private IContentHandler _contentHandler;
      private IDTDHandler _dtdHandler;
      private IEntityResolver _entityResolver;
      private IErrorHandler _errorHandler;
      private ILocator _locator;
      private IXmlReader _parent;
  
      /// <summary>
      ///   Construct an empty XML filter, with no parent.
      ///   <para>
      ///     This filter will have no parent: you must assign a parent
      ///     before you start a parse or do any configuration with
      ///     setFeature or setProperty, unless you use this as a pure event
      ///     consumer rather than as an <see cref="IXmlReader" />.
      ///   </para>
      /// </summary>
      /// <seealso cref="IXmlReader.SetFeature" />
      /// <seealso cref="IXmlReader.SetProperty" />
      /// <seealso cref="Parent" />
      public XmlFilter() {
      }
  
      /// <summary>
      ///   Construct an XML filter with the specified parent.
      /// </summary>
      /// <param name="parent">The parent</param>
      /// <seealso cref="Parent" />
      public XmlFilter(IXmlReader parent) {
        _parent = parent;
      }
  
      public virtual void SetDocumentLocator(ILocator locator) {
        _locator = locator;
        if (_contentHandler != null) {
          _contentHandler.SetDocumentLocator(locator);
        }
      }
  
      public virtual void StartDocument() {
        if (_contentHandler != null) {
          _contentHandler.StartDocument();
        }
      }
  
      public virtual void EndDocument() {
        if (_contentHandler != null) {
          _contentHandler.EndDocument();
        }
      }
  
      public virtual void StartPrefixMapping(string prefix, string uri) {
        if (_contentHandler != null) {
          _contentHandler.StartPrefixMapping(prefix, uri);
        }
      }
  
      public virtual void EndPrefixMapping(string prefix) {
        if (_contentHandler != null) {
          _contentHandler.EndPrefixMapping(prefix);
        }
      }
  
      public virtual void StartElement(string uri, string localName, string qName, IAttributes atts) {
        if (_contentHandler != null) {
          _contentHandler.StartElement(uri, localName, qName, atts);
        }
      }
  
      public virtual void EndElement(string uri, string localName, string qName) {
        if (_contentHandler != null) {
          _contentHandler.EndElement(uri, localName, qName);
        }
      }
  
      public virtual void Characters(char[] ch, int start, int length) {
        if (_contentHandler != null) {
          _contentHandler.Characters(ch, start, length);
        }
      }
  
      public virtual void IgnorableWhitespace(char[] ch, int start, int length) {
        if (_contentHandler != null) {
          _contentHandler.IgnorableWhitespace(ch, start, length);
        }
      }
  
      public virtual void ProcessingInstruction(string target, string data) {
        if (_contentHandler != null) {
          _contentHandler.ProcessingInstruction(target, data);
        }
      }
  
      public virtual void SkippedEntity(string name) {
        if (_contentHandler != null) {
          _contentHandler.SkippedEntity(name);
        }
      }
  
      public virtual void NotationDecl(string name, string publicId, string systemId) {
        if (_dtdHandler != null) {
          _dtdHandler.NotationDecl(name, publicId, systemId);
        }
      }
  
      public virtual void UnparsedEntityDecl(string name, string publicId, string systemId, string notationName) {
        if (_dtdHandler != null) {
          _dtdHandler.UnparsedEntityDecl(name, publicId, systemId, notationName);
        }
      }
  
      public virtual InputSource ResolveEntity(string publicId, string systemId) {
        if (_entityResolver != null) {
          return _entityResolver.ResolveEntity(publicId, systemId);
        }
        return null;
      }
  
      public virtual void Warning(SAXParseException e) {
        if (_errorHandler != null) {
          _errorHandler.Warning(e);
        }
      }
  
      public virtual void Error(SAXParseException e) {
        if (_errorHandler != null) {
          _errorHandler.Error(e);
        }
      }
  
      public virtual void FatalError(SAXParseException e) {
        if (_errorHandler != null) {
          _errorHandler.FatalError(e);
        }
      }
  
      public IXmlReader Parent {
        get { return _parent; }
        set { _parent = value; }
      }
  
      public virtual void SetFeature(string name, bool value) {
        if (_parent != null) {
          _parent.SetFeature(name, value);
        } else {
          throw new SAXNotRecognizedException("Feature: " + name);
        }
      }
  
      public virtual bool GetFeature(string name) {
        if (_parent != null) {
          return _parent.GetFeature(name);
        }
        throw new SAXNotRecognizedException("Feature: " + name);
      }
  
      public virtual void SetProperty(string name, object value) {
        if (_parent != null) {
          _parent.SetProperty(name, value);
        } else {
          throw new SAXNotRecognizedException("Property: " + name);
        }
      }
  
      public virtual object GetProperty(string name) {
        if (_parent != null) {
          return _parent.GetProperty(name);
        }
        throw new SAXNotRecognizedException("Property: " + name);
      }
  
      public IEntityResolver EntityResolver {
        get { return _entityResolver; }
        set { _entityResolver = value; }
      }
  
      public IDTDHandler DTDHandler {
        get { return _dtdHandler; }
        set { _dtdHandler = value; }
      }
  
      public IContentHandler ContentHandler {
  
gt:       get { return _contentHandler; }