Class FormHtmlHandler
java.lang.Object
sk.iway.iwcm.components.multistep_form.rest.FormHtmlHandler
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 Summary
ConstructorsConstructorDescriptionFormHtmlHandler(String formName, int formCounter, jakarta.servlet.http.HttpServletRequest request) Creates a renderer for a specific form instance.FormHtmlHandler(String formName, jakarta.servlet.http.HttpServletRequest request) Creates a renderer and resolves the form instance number from the current request state. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringappendStyle(String htmlData, String styleHtml, String emailEncoding, boolean forceTextPlain) Wraps HTML with minimal email document structure and appends stylesheet markup.getCssDataLink(Integer docId, boolean forceTextPlain) Resolves CSS for email/PDF rendering given a document context.getCssDataLink(Integer docId, boolean forceTextPlain, String formSpecificCssStr) Resolves CSS for email/PDF rendering including template, editor and form‑specific CSS.Returns CSS collected during the last render.final StringReturns the prefix used to map logical form item identifiers to DOM identifiers.final StringReturns the last rendered form content before CSS or encryption is applied.final StringReturns the PDF-oriented form representation, based on the lastsetFormHtml(FormsEntity, Map, HttpServletRequest, Integer)call.final StringgetFormStepHtml(Long stepId, jakarta.servlet.http.HttpServletRequest request) Builds HTML for a single form step including its items and wrappers.final voidsetFormHtml(FormsEntity form, Map<String, String> formData, jakarta.servlet.http.HttpServletRequest request, Integer docId) Builds and stores the complete multistep form representation for email delivery.
-
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 renderformCounter- one-based form instance number used to create unique DOM identifiersrequest- current HTTP request used to resolve language and form settings- Throws:
IllegalStateException- if a required repository is unavailable orformCounteris invalid
-
FormHtmlHandler
Creates a renderer and resolves the form instance number from the current request state.- Parameters:
formName- name of the form to renderrequest- 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
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
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
Returns the prefix used to map logical form item identifiers to DOM identifiers.- Returns:
- form-instance-specific DOM ID prefix
-
getFormStepHtml
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 renderrequest- 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 contentformData- ordered form data values keyed by logical field IDs, containing HTML-escaped text, sanitized WYSIWYG HTML, saved filenames and empty answersrequest- current HTTP requestdocId- 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
Returns the PDF-oriented form representation, based on the lastsetFormHtml(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 contentstyleHtml- stylesheet markup such as<style>or<link>elementsemailEncoding- optional character set for the metadata headerforceTextPlain- whether to returnhtmlDatawithout wrapping- Returns:
- full HTML document, or
htmlDatawhenforceTextPlainis true
-
getCssDataLink
Resolves CSS for email/PDF rendering given a document context.- Parameters:
docId- document IDforceTextPlain- whether to return empty CSS- Returns:
- pair containing inline
<style>CSS and<link>elements, an empty pair for plain text, ornullif 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 IDforceTextPlain- whether to return empty CSSformSpecificCssStr- 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, ornullif the document cannot be resolved
-