Example #1
0
  /**
   * Get a Tag by name. If not previously defined (unknown), returns a new generic tag, that can do
   * anything.
   *
   * <p>Pre-defined tags (P, DIV etc) will be ==, but unknown tags are not registered and will only
   * .equals().
   *
   * @param tagName Name of tag, e.g. "p". Case insensitive.
   * @return The tag, either defined or new generic.
   */
  public static Tag valueOf(String tagName) {
    Validate.notNull(tagName);
    Tag tag = tags.get(tagName);

    if (tag == null) {
      tagName = tagName.trim().toLowerCase();
      Validate.notEmpty(tagName);
      tag = tags.get(tagName);

      if (tag == null) {
        // not defined: create default; go anywhere, do anything! (incl be
        // inside a <p>)
        tag = new Tag(tagName);
        tag.isBlock = false;
        tag.canContainBlock = true;
      }
    }
    return tag;
  }
Example #2
0
  static {
    // creates
    for (final String tagName : blockTags) {
      final Tag tag = new Tag(tagName);
      register(tag);
    }
    for (final String tagName : inlineTags) {
      final Tag tag = new Tag(tagName);
      tag.isBlock = false;
      tag.canContainBlock = false;
      tag.formatAsBlock = false;
      register(tag);
    }

    // mods:
    for (final String tagName : emptyTags) {
      final Tag tag = tags.get(tagName);
      Validate.notNull(tag);
      tag.canContainBlock = false;
      tag.canContainInline = false;
      tag.empty = true;
    }

    for (final String tagName : formatAsInlineTags) {
      final Tag tag = tags.get(tagName);
      Validate.notNull(tag);
      tag.formatAsBlock = false;
    }

    for (final String tagName : preserveWhitespaceTags) {
      final Tag tag = tags.get(tagName);
      Validate.notNull(tag);
      tag.preserveWhitespace = true;
    }
  }