예제 #1
0
  /**
   * Searches the attribute set and for each tag that is stored in the tag vector. If the tag isnt
   * found, then the tag is removed from the vector and a corresponding end tag is written out.
   *
   * @exception IOException on any I/O error
   */
  protected void closeOutUnwantedEmbeddedTags(AttributeSet attr) throws IOException {

    tagsToRemove.removeAllElements();

    // translate css attributes to html
    attr = convertToHTML(attr, null);

    HTML.Tag t;
    Object tValue;
    int firstIndex = -1;
    int size = tags.size();
    // First, find all the tags that need to be removed.
    for (int i = size - 1; i >= 0; i--) {
      t = (HTML.Tag) tags.elementAt(i);
      tValue = tagValues.elementAt(i);
      if ((attr == null) || noMatchForTagInAttributes(attr, t, tValue)) {
        firstIndex = i;
        tagsToRemove.addElement(t);
      }
    }
    if (firstIndex != -1) {
      // Then close them out.
      boolean removeAll = ((size - firstIndex) == tagsToRemove.size());
      for (int i = size - 1; i >= firstIndex; i--) {
        t = (HTML.Tag) tags.elementAt(i);
        if (removeAll || tagsToRemove.contains(t)) {
          tags.removeElementAt(i);
          tagValues.removeElementAt(i);
        }
        write('<');
        write('/');
        write(t.toString());
        write('>');
      }
      // Have to output any tags after firstIndex that still remaing,
      // as we closed them out, but they should remain open.
      size = tags.size();
      for (int i = firstIndex; i < size; i++) {
        t = (HTML.Tag) tags.elementAt(i);
        write('<');
        write(t.toString());
        Object o = tagValues.elementAt(i);
        if (o != null && o instanceof AttributeSet) {
          writeAttributes((AttributeSet) o);
        }
        write('>');
      }
    }
  }
예제 #2
0
  /**
   * Searches for embedded tags in the AttributeSet and writes them out. It also stores these tags
   * in a vector so that when appropriate the corresponding end tags can be written out.
   *
   * @exception IOException on any I/O error
   */
  protected void writeEmbeddedTags(AttributeSet attr) throws IOException {

    // translate css attributes to html
    attr = convertToHTML(attr, oConvAttr);

    Enumeration names = attr.getAttributeNames();
    while (names.hasMoreElements()) {
      Object name = names.nextElement();
      if (name instanceof HTML.Tag) {
        HTML.Tag tag = (HTML.Tag) name;
        if (tag == HTML.Tag.FORM || tags.contains(tag)) {
          continue;
        }
        write('<');
        write(tag.toString());
        Object o = attr.getAttribute(tag);
        if (o != null && o instanceof AttributeSet) {
          writeAttributes((AttributeSet) o);
        }
        write('>');
        tags.addElement(tag);
        tagValues.addElement(o);
      }
    }
  }