Class Meta<T extends Meta<T>>

java.lang.Object
com.oorian.html.Element<T>
com.oorian.html.elements.Meta<T>
All Implemented Interfaces:
HeadElement

public class Meta<T extends Meta<T>> extends Element<T> implements HeadElement
Represents an HTML <meta> element that defines metadata about an HTML document.

The <meta> element provides information about the HTML document such as character encoding, page description, keywords, author, viewport settings, and other metadata. Meta tags are placed in the document's head section and are not displayed on the page.

Features:

  • Character encoding specification (UTF-8, ISO-8859-1, etc.)
  • HTTP header equivalents (refresh, content-type, etc.)
  • Standard metadata (description, keywords, author, viewport)
  • OpenGraph and social media metadata support
  • Self-closing tag (no closing tag required)
  • ID attribute excluded by default

Usage:


 // Character encoding
 Meta charset = new Meta();
 charset.setCharset("UTF-8");

 // Page description
 Meta description = new Meta("name", "description", "Page description text");

 // Viewport settings
 Meta viewport = new Meta("name", "viewport");
 viewport.setContent("width=device-width, initial-scale=1.0");

 // HTTP refresh
 Meta refresh = new Meta();
 refresh.setHttpEquiv("refresh");
 refresh.setContent("30");

 // OpenGraph property
 Meta ogTitle = new Meta();
 ogTitle.setProperty("og:title");
 ogTitle.setContent("Page Title");
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Meta

      public Meta()
      Constructs a new Meta element.

      Creates a self-closing <meta> tag with ID attribute excluded.

    • Meta

      public Meta(String attribute, String value)
      Constructs a new Meta element with a specified attribute and value.

      This constructor is useful for creating meta tags with a single attribute-value pair, such as <meta name="viewport">.

      Parameters:
      attribute - the attribute name (e.g., "name", "property", "http-equiv")
      value - the attribute value (e.g., "viewport", "og:title", "refresh")
    • Meta

      public Meta(String attribute, String value, String content)
      Constructs a new Meta element with an attribute, value, and content.

      This constructor provides a convenient way to create complete meta tags with both an identifying attribute and content in a single statement.

      Parameters:
      attribute - the attribute name (e.g., "name", "property", "http-equiv")
      value - the attribute value (e.g., "description", "og:description")
      content - the content value for the meta tag
  • Method Details

    • setCharset

      public T setCharset(String characterSet)
      Sets the character encoding for the document.

      Specifies the character encoding used by the document. The most common value is "UTF-8". This attribute is mutually exclusive with the http-equiv attribute.

      Parameters:
      characterSet - the character encoding (e.g., "UTF-8")
      Returns:
      this element for method chaining
    • setContent

      public final T setContent(String text)
      Sets the content value for this meta element.

      The content attribute provides the value associated with the name, http-equiv, or property attribute.

      Parameters:
      text - the content value
      Returns:
      this element for method chaining
    • setHttpEquiv

      public final T setHttpEquiv(String httpEquiv)
      Sets the HTTP-equiv pragma directive using a string value.

      Defines a pragma directive that simulates an HTTP response header. Common values include "content-type", "refresh", "default-style", and "content-security-policy".

      Parameters:
      httpEquiv - the pragma directive name
      Returns:
      this element for method chaining
    • setHttpEquiv

      public final T setHttpEquiv(HttpEquiv httpEquiv)
      Sets the HTTP-equiv pragma directive using the HttpEquiv enum.
      Parameters:
      httpEquiv - The pragma directive.
      Returns:
      This element for method chaining.
    • setName

      public final T setName(String name)
      Sets the name attribute identifying the metadata type.

      Common values include "description", "keywords", "author", "viewport", and "robots".

      Parameters:
      name - The metadata name.
      Returns:
      This element for method chaining.
    • setMedia

      public final T setMedia(String media)
      Sets the media attribute specifying the media query for which this metadata applies.
      Parameters:
      media - The media query string.
      Returns:
      This element for method chaining.
    • setProperty

      public final T setProperty(String property)
      Sets the property attribute for extended metadata protocols.

      The property attribute is used for metadata protocols like OpenGraph (og:*) and Twitter Cards (twitter:*). This allows rich social media integration.

      Parameters:
      property - the property name (e.g., "og:title", "og:description", "twitter:card")
      Returns:
      this element for method chaining