Class Link

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

public class Link extends HtmlTag
Hyperlink component with URL-scheme validation and HTMX helpers.

Mutable and not thread-safe. Configure and render within a request-scoped lifecycle. For reuse, stop mutating shared instances and render stable structures with per-request context data.

Security boundary: withHref(String) and constructor validate href schemes and allow only http, https, mailto, tel, or relative URLs. Classification trims boundary C0/ASCII space, removes TAB/LF/CR, and folds ASCII case, independently of locale; the original value is stored and attribute-encoded unchanged. This is not destination authorization. Generic attribute replacement and HTMX endpoints do not use this href policy.

  • Constructor Details

    • Link

      public Link(String href, String text)
      Creates a link with validated href and escaped text content.
      Parameters:
      href - target URL (allowlisted schemes or relative path)
      text - link text
      Throws:
      IllegalArgumentException - when scheme is disallowed
  • Method Details

    • create

      public static Link create(String href, String text)
      Factory for a link.
      Parameters:
      href - target URL
      text - link text
      Returns:
      new link
    • getHref

      public String getHref()
      Returns current href value.
      Returns:
      href
    • getText

      public String getText()
      Returns current text value.
      Returns:
      text
    • withId

      public Link withId(String id)
      Sets id attribute.
      Overrides:
      withId in class HtmlTag
      Parameters:
      id - element id
      Returns:
      this link
    • withTarget

      public Link withTarget(String target)
      Sets target attribute.
      Parameters:
      target - target attribute value
      Returns:
      this link
    • openInNewTab

      public Link openInNewTab()
      Convenience for target="_blank".
      Returns:
      this link
    • withHref

      public Link withHref(String href)
      Sets href after allowlist validation.
      Parameters:
      href - the target URL
      Returns:
      this link
      Throws:
      IllegalArgumentException - when href scheme is disallowed
    • withClass

      public Link withClass(String className)
      Replaces class attribute.
      Overrides:
      withClass in class HtmlTag
      Parameters:
      className - class token(s)
      Returns:
      this link
    • withHxGet

      public Link withHxGet(String url)
      Sets hx-get to an application-controlled or separately endpoint-validated URL. This does not apply the href scheme policy or authorize requests.
      Parameters:
      url - HTMX GET endpoint
      Returns:
      this link
    • withHxPost

      public Link withHxPost(String url)
      Sets hx-post to an application-controlled or separately endpoint-validated URL. This does not apply the href scheme policy or provide authorization/CSRF enforcement.
      Parameters:
      url - HTMX POST endpoint
      Returns:
      this link
    • withHxTarget

      public Link withHxTarget(String target)
      Sets hx-target.
      Parameters:
      target - HTMX target selector
      Returns:
      this link
    • withHxSwap

      public Link withHxSwap(String swap)
      Sets hx-swap.
      Parameters:
      swap - HTMX swap mode
      Returns:
      this link
    • withHxPushUrl

      public Link withHxPushUrl(boolean pushUrl)
      Sets hx-push-url.
      Parameters:
      pushUrl - whether browser URL should be pushed
      Returns:
      this link
    • withHxScrollTargetTop

      public Link withHxScrollTargetTop()
      Tags this HTMX request to scroll the swapped target fragment to top after settle.
      Returns:
      this link
    • withChild

      public Link withChild(Component component)
      Appends child content inside the anchor.
      Overrides:
      withChild in class HtmlTag
      Parameters:
      component - child component
      Returns:
      this link