Class Image

java.lang.Object
io.mindspice.simplypages.core.HtmlTag
io.mindspice.simplypages.components.Image
All Implemented Interfaces:
Component

public class Image extends HtmlTag
Image element with basic source/size configuration helpers.

Mutable and not thread-safe. Source and dimensions are retained on this instance. Mutate within a request-scoped flow. For reuse, stop mutating and render as a stable structure with per-request slot/context values.

Security boundary: source URLs are validated to reject javascript: and non-image data: schemes. Classification trims boundary C0/ASCII space, removes TAB/LF/CR, and folds ASCII case independently of locale; storage and attribute encoding retain the original value. Other schemes remain accepted. This is not MIME/payload inspection, destination authorization, or a guarantee that an image loads safely.

  • Constructor Details

    • Image

      public Image(String src, String alt)
      Creates an image using the source policy described on withSrc(String).
      Parameters:
      src - original source URL, retained without normalization
      alt - alternative text; null becomes empty
    • Image

      public Image(String src)
      Creates an image with empty alternative text and the same validated source policy.
  • Method Details

    • create

      public static Image create(String src, String alt)
      Creates an image using Image(String, String) and its source policy.
    • create

      public static Image create(String src)
      Creates an image using Image(String) and its source policy.
    • getSrc

      public String getSrc()
    • getAlt

      public String getAlt()
    • getWidth

      public String getWidth()
    • getHeight

      public String getHeight()
    • withId

      public Image withId(String id)
      Sets the HTML id attribute for this image.
      Overrides:
      withId in class HtmlTag
      Parameters:
      id - the HTML id attribute value
      Returns:
      this Image for method chaining
    • withClass

      public Image withClass(String className)
      Description copied from class: HtmlTag
      Overrides:
      withClass in class HtmlTag
    • withSrc

      public Image withSrc(String src)
      Sets the image source URL.

      Security: This method rejects javascript: URLs and non-image data: URLs after boundary C0/ASCII-space trimming, TAB/LF/CR removal, and ASCII case folding for classification only. Data URLs must have the classified prefix data:image/; payloads and MIME types are not inspected. Other schemes, including custom schemes, remain accepted. Original strings are stored and encoded unchanged; generic withAttribute("src", ...) does not apply this policy.

      Parameters:
      src - the image URL or data URL
      Returns:
      this Image instance for method chaining
      Throws:
      IllegalArgumentException - if src contains a dangerous URL scheme
    • withSize

      public Image withSize(String width, String height)