Exemple #1
0
  /**
   * This indicates that an unresolvable entity reference has been encountered, normally because the
   * external DTD subset has not been read.
   *
   * @param name <code>String</code> name of entity
   * @throws SAXException when things go wrong
   */
  public void skippedEntity(String name) throws SAXException {

    // We don't handle parameter entity references.
    if (name.startsWith("%")) return;

    flushCharacters();

    factory.addContent(getCurrentElement(), factory.entityRef(name));
  }
Exemple #2
0
  public void startEntity(String name) throws SAXException {
    entityDepth++;

    if (expand || entityDepth > 1) {
      // Short cut 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"))) {

      if (!expand) {
        String pub = null;
        String sys = null;
        String[] ids = (String[]) 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();
          EntityRef entity = factory.entityRef(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;
      }
    }
  }