All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.owasp.html.HtmlElementTables Maven / Gradle / Ivy

There is a newer version: 20240325.1
Show newest version
package org.owasp.html;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

/**
 * Metadata about HTML elements.
 */
public final class HtmlElementTables {

  /** Pseudo element index for text nodes. */
  public static final int TEXT_NODE = -1;

  /** Maps between element indices and element names. */
  private final HtmlElementNames elementNames;
  /** Relates elements and the elements that can contain them. */
  private final DenseElementBinaryMatrix canContain;
  /**
   * Relates element names and the elements that are closed when that close
   * tag appears.
   */
  private final DenseElementBinaryMatrix closedOnClose;
  /**
   * Relates element names and the elements that are closed when that open
   * tag appears.
   */
  private final DenseElementBinaryMatrix closedOnOpen;
  /**
   * Close tags besides the tag itself which close the tag.
   */
  private final SparseElementToElements explicitClosers;
  /**
   * Elements in order which are implicitly opened when a descendant tag is
   * lexically nested within an ancestor.
   */
  private final SparseElementMultitable impliedElements;
  /**
   * The kind of character data that can appear in an element.
   */
  private final TextContentModel textContentModel;
  /** The elements that can be resumed after misnested inline tags. */
  private final DenseElementSet resumable;

  private final int DIR_TAG;
  private final int OL_TAG;
  private final int UL_TAG;
  private final int LI_TAG;
  private final int SELECT_TAG;
  private final int OPTION_TAG;
  private final int OPTGROUP_TAG;
  private final int SCRIPT_TAG;
  private final int STYLE_TAG;
  private final int TABLE_TAG;
  private final int TBODY_TAG;
  private final int TFOOT_TAG;
  private final int THEAD_TAG;
  private final int TR_TAG;
  private final int TD_TAG;
  private final int TH_TAG;
  private final int CAPTION_TAG;
  private final int COL_TAG;
  private final int COLGROUP_TAG;
  private final int IFRAME_TAG;

  private final FreeWrapper[] FREE_WRAPPERS;

  private final int[] LI_TAG_ARR;
  private final int[] OPTION_TAG_ARR;

  /** {@code