Class FreeMarkerProcessor

java.lang.Object
org.nuxeo.template.processors.AbstractTemplateProcessor
org.nuxeo.template.processors.fm.FreeMarkerProcessor
All Implemented Interfaces:
TemplateProcessor

public class FreeMarkerProcessor extends AbstractTemplateProcessor implements TemplateProcessor
  • Field Details

    • GUESS_MIMETYPE_MAX_SIZE_PROP

      protected static final String GUESS_MIMETYPE_MAX_SIZE_PROP
      Property to configure the maximum content size (in bytes) used for MIME type detection.

      Accepts size notation like "8KiB", "1MB", etc. using ByteSize.parse(String).

      Since:
      2025.17
      See Also:
    • DEFAULT_GUESS_MIMETYPE_MAX_SIZE

      protected static final String DEFAULT_GUESS_MIMETYPE_MAX_SIZE
      Default maximum content size for MIME type detection (8 KiB).
      Since:
      2025.17
      See Also:
    • loader

      protected freemarker.cache.StringTemplateLoader loader
    • fmEngine

      protected FreemarkerEngine fmEngine
    • fmContextBuilder

      protected FMContextBuilder fmContextBuilder
    • XMLStartPattern

      protected static final Pattern XMLStartPattern
    • HtmlTagPattern

      @Deprecated(since="2025.17", forRemoval=true) protected static final Pattern HtmlTagPattern
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 2025.17, use HtmlStartPattern instead
      Pattern to detect HTML content by matching opening and closing tag pairs.

      This pattern is deprecated because it requires finding complete tag pairs, which may not work reliably with truncated content where closing tags might be cut off.

    • HtmlStartPattern

      protected static final Pattern HtmlStartPattern
      Pattern to detect HTML content by looking for HTML start tag or DOCTYPE declaration at the beginning of the content.

      Anchored to the start of the content (optionally allowing leading whitespace) to avoid false positives from <html> occurrences in the middle of the content. Uses prefix-based matching to work reliably with truncated content, avoiding the need to find matching opening/closing tag pairs which may be split by truncation.

      Since:
      2025.17
  • Constructor Details

    • FreeMarkerProcessor

      public FreeMarkerProcessor()
  • Method Details

    • getEngine

      protected FreemarkerEngine getEngine()
    • guessMimeType

      protected String guessMimeType(Blob result, MimetypeRegistry mreg)
    • getTruncatedContent

      protected String getTruncatedContent(Blob result)
      Extracts content from the blob for MIME type detection, limiting it to a configurable maximum size to avoid performance issues with large files.

      The content is read from the blob's input stream and limited to the configured maximum size using BoundedInputStream. This prevents loading entire large files into memory when only a small portion is needed for MIME type pattern matching.

      The blob's encoding is used for reading the content, defaulting to UTF-8 if no encoding is specified.

      If the configured maximum size is unlimited (-1), the entire content will be read without truncation.

      Parameters:
      result - the blob to extract content from
      Returns:
      the content string, truncated if the blob is larger than the configured maximum size, or null if the blob is null
      Since:
      2025.17
    • setBlobAttributes

      protected void setBlobAttributes(Blob result, TemplateBasedDocument templateBasedDocument)
    • renderTemplate

      public Blob renderTemplate(TemplateBasedDocument templateBasedDocument, String templateName) throws IOException
      Description copied from interface: TemplateProcessor
      Perform rendering of the named template against the TemplateBasedDocument
      Specified by:
      renderTemplate in interface TemplateProcessor
      Throws:
      IOException
    • getInitialParametersDefinition

      public List<TemplateInput> getInitialParametersDefinition(Blob blob) throws IOException
      Description copied from interface: TemplateProcessor
      Extract parameters from the Template file.
      Specified by:
      getInitialParametersDefinition in interface TemplateProcessor
      Returns:
      List of parameters for this template
      Throws:
      IOException