Ejemplo n.º 1
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;
    }
  }
Ejemplo n.º 2
0
  protected void initialiseParse(
      final String input, final String baseUri, final ParseErrorList errors) {
    Validate.notNull(input, "String input must not be null");
    Validate.notNull(baseUri, "BaseURI must not be null");

    doc = new Document(baseUri);
    reader = new CharacterReader(input);
    this.errors = errors;
    tokeniser = new Tokeniser(reader, errors);
    stack = new DescendableLinkedList<Element>();
    this.baseUri = baseUri;
  }
Ejemplo n.º 3
0
  /**
   * Create a new doctype element.
   *
   * @param name the doctype's name
   * @param publicId the doctype's public ID
   * @param systemId the doctype's system ID
   * @param baseUri the doctype's base URI
   */
  public DocumentType(
      final String name, final String publicId, final String systemId, final String baseUri) {
    super(baseUri);

    Validate.notEmpty(name);
    attr("name", name);
    attr("publicId", publicId);
    attr("systemId", systemId);
  }
Ejemplo n.º 4
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;
  }