#1046: GroovyEngine.kt

projectforge-business/src/main/kotlin/org/projectforge/business/scripting/GroovyEngine.kt Groovy Template Engine, projectforge-business/src/main/kotlin/org/projectforge/business/scripting/GroovyEngine.kt 363 lines · 208 code · 118 comments · 37 blank
Template engine providing Groovy-based string interpolation and i18n formatting for script output. Exposed to scripts as the pf variable. Supports template includes (#INCLUDE{filename}), XML preprocessing (<groovy> tags), and comprehensive getString() overloads for formatting entities, dates, currencies, and numbers.

Architecture

Template Processing

executeTemplate(template) first processes #INCLUDE{filename} directives (loading resources via ConfigurationService), then delegates to GroovyExecutor.executeTemplate() for Groovy string interpolation. Special markers (#HURZ1#, #HURZ2#) work around Groovy's treatment of backslash and dollar signs in regex replacement.

XML Preprocessing

For well-formed XML templates, <groovy>...</groovy> tags are converted to <% ... %> and <groovy-out>...</groovy-out> to <%= ... %>, allowing Groovy scriptlets inside XML documents.

Formatting Methods

Overloaded getString() handles: KundeDO, ProjektDO, PFUserDO, TaskDO, Number, BigDecimal, LocalDate, Date, I18nEnum — each delegated to the appropriate formatter class. getCurrency(value) uses CurrencyFormatter. formatBytes() uses FormatterUtils.

Null Handling

Explicit isNull(), isBlank(), and isEmpty() overloads handle Groovy's NullObject to prevent script errors when accessing unset variables.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
0e449b8f1 Fix leftover typos Found via codespell
1204b927b Migration stuff in progress...
a72903e36 *.java, *.kt: StringBuffer -> StringBuilder.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
34a37e406 DataTransferPlugin: WIP: notification e-mail.
5f7ef41b8 Copyright 2021 -> 2022
0ab100d21 Configuration refactored. SEPA export.
ceb63e8a1 Source code header: (C) 2001-2021.
c1d6f116a Source file headers fixed.
c5e6d921b GroovyEngine and SendMail -> Kotlin.