@Override
  public void startEntity(final String name) throws SAXException {
    entityDepth++;

    if (expand || entityDepth > 1) {
      // Shortcut out if we're expanding or if we're nested
      return;
    }

    // A "[dtd]" entity indicates the beginning of the external subset
    if (name.equals("[dtd]")) {
      inInternalSubset = false;
      return;
    }

    // Ignore DTD references, and translate the standard 5
    if ((!inDTD) && (!name.equals("amp")) && (!name.equals("lt"))
        && (!name.equals("gt")) && (!name.equals("apos"))
        && (!name.equals("quot"))) {

      String pub = null;
      String sys = null;
      String[] ids = externalEntities.get(name);
      if (ids != null) {
        pub = ids[0]; // may be null, that's OK
        sys = ids[1]; // may be null, that's OK
      }
      /*
        if no current element, this entity belongs to an attribute in
        these cases, it is an error on the part of the parser to call
        startEntity but this will help in some cases. See
        org/xml/sax/
        ext/LexicalHandler.html#startEntity(java.lang.String) for
        more information
       */
      if (!atRoot) {
        flushCharacters();
        final EntityRef entity = currentLocator == null ? factory
          .entityRef(name, pub, sys) : factory.entityRef(
          currentLocator.getLineNumber(),
          currentLocator.getColumnNumber(), name, pub, sys);

        // no way to tell if the entity was from an attribute or
        // element so just assume element
        factory.addContent(getCurrentElement(), entity);
      }
      suppress = true;
    }
  }
@Override
  public void startEntity(final String name)