Class FormHtmlHandler

java.lang.Object
sk.iway.iwcm.components.multistep_form.rest.FormHtmlHandler

public class FormHtmlHandler extends Object
Renders a multistep form for page, email, and PDF contexts.

The handler builds localized step and item markup, converts interactive controls to read-only email representations, collects CSS, and optionally encrypts rendered email HTML with the configured public key.

  • Constructor Details

    • FormHtmlHandler

      public FormHtmlHandler(String formName, int formCounter, jakarta.servlet.http.HttpServletRequest request)
      Creates a renderer for a specific form instance.
      Parameters:
      formName - name of the form to render
      formCounter - one-based form instance number used to create unique DOM identifiers
      request - current HTTP request used to resolve language and form settings
      Throws:
      IllegalStateException - if a required repository is unavailable or formCounter is invalid
    • FormHtmlHandler

      public FormHtmlHandler(String formName, jakarta.servlet.http.HttpServletRequest request)
      Creates a renderer and resolves the form instance number from the current request state.
      Parameters:
      formName - name of the form to render
      request - current HTTP request used to resolve the form instance, language, and settings
      Throws:
      IllegalStateException - if a required service or repository is unavailable or the resolved counter is invalid
  • Method Details

    • getFormHtmlBeforeCss

      public final String getFormHtmlBeforeCss()
      Returns the last rendered form content before CSS or encryption is applied.
      Returns:
      rendered HTML or plain text, depending on form settings, or an empty string if unavailable
    • getCssDataPair

      public final Pair<String,String> getCssDataPair()
      Returns CSS collected during the last render.
      Returns:
      pair whose first value contains inline <style> CSS and whose second value contains <link> elements; both values are empty if unavailable
    • getDomIdPrefix

      public final String getDomIdPrefix()
      Returns the prefix used to map logical form item identifiers to DOM identifiers.
      Returns:
      form-instance-specific DOM ID prefix
    • getFormStepHtml

      public final String getFormStepHtml(Long stepId, jakarta.servlet.http.HttpServletRequest request)
      Builds HTML for a single form step including its items and wrappers. Intended for on‑page rendering (not email).
      Parameters:
      stepId - ID of the step to render
      request - current HTTP request
      Returns:
      HTML markup of the requested step
    • setFormHtml

      public final void setFormHtml(FormsEntity form, Map<String,String> formData, jakarta.servlet.http.HttpServletRequest request, Integer docId)
      Builds and stores the complete multistep form representation for email delivery. Uses the prepared unencrypted notification values, converts the content to plain text when configured, and encrypts only the stored HTML. Collects stylesheet data for readable email and PDF variants.
      Parameters:
      form - entity whose HTML field receives the rendered email content
      formData - ordered form data values keyed by logical field IDs, containing HTML-escaped text, sanitized WYSIWYG HTML, saved filenames and empty answers
      request - current HTTP request
      docId - ID of the document used to resolve template and group CSS
      Throws:
      IllegalStateException - if the entity belongs to a different form than this handler
    • getFormPdfVersion

      public final String getFormPdfVersion()
      Returns the PDF-oriented form representation, based on the last setFormHtml(FormsEntity, Map, HttpServletRequest, Integer) call.
      Returns:
      HTML with inline CSS, plain text when configured, or an empty string if unavailable
    • appendStyle

      public static String appendStyle(String htmlData, String styleHtml, String emailEncoding, boolean forceTextPlain)
      Wraps HTML with minimal email document structure and appends stylesheet markup.
      Parameters:
      htmlData - HTML body content
      styleHtml - stylesheet markup such as <style> or <link> elements
      emailEncoding - optional character set for the metadata header
      forceTextPlain - whether to return htmlData without wrapping
      Returns:
      full HTML document, or htmlData when forceTextPlain is true
    • getCssDataLink

      public static Pair<String,String> getCssDataLink(Integer docId, boolean forceTextPlain)
      Resolves CSS for email/PDF rendering given a document context.
      Parameters:
      docId - document ID
      forceTextPlain - whether to return empty CSS
      Returns:
      pair containing inline <style> CSS and <link> elements, an empty pair for plain text, or null if the document cannot be resolved
    • getCssDataLink

      public static Pair<String,String> getCssDataLink(Integer docId, boolean forceTextPlain, String formSpecificCssStr)
      Resolves CSS for email/PDF rendering including template, editor and form‑specific CSS.
      Parameters:
      docId - document ID
      forceTextPlain - whether to return empty CSS
      formSpecificCssStr - newline-separated list of additional CSS paths from form settings
      Returns:
      pair containing inline <style> CSS and <link> elements, an empty pair for plain text, or null if the document cannot be resolved