From 5a3bea754e39c9212fae513d0bcc2ea1a58c2ed9 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 15 Jul 2024 15:44:24 +0200 Subject: [PATCH] 751 Expose isEmpty and isBlank for EL evaluation --- .../cq/tools/actool/configreader/YamlMacroElEvaluator.java | 2 ++ .../tools/actool/configreader/YamlMacroElEvaluatorTest.java | 4 ++++ docs/AdvancedFeatures.md | 2 ++ 3 files changed, 8 insertions(+) diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java index df194b6d..9a1ce468 100644 --- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java +++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java @@ -136,6 +136,8 @@ public ElFunctionMapper() { StringUtils.class.getMethod("replace", new Class[] { String.class, String.class, String.class }), StringUtils.class.getMethod("length", new Class[] { CharSequence.class }), StringUtils.class.getMethod("defaultIfEmpty", new Class[] { CharSequence.class, CharSequence.class }), + StringUtils.class.getMethod("isEmpty", new Class[] { CharSequence.class }), + StringUtils.class.getMethod("isBlank", new Class[] { CharSequence.class }), YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("containsItem", new Class[] { List.class, String.class }), YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("containsAllItems", new Class[] { List.class, List.class }), diff --git a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java index e44a37e4..c878ddd2 100644 --- a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java +++ b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java @@ -34,6 +34,10 @@ public void setUp() { @Test void testFunctions() { + assertEquals(true, evaluateSimpleExpression("isBlank(\"\")")); + assertEquals(true, evaluateSimpleExpression("isBlank(\" \")")); + assertEquals(true, evaluateSimpleExpression("isEmpty(\"\")")); + assertEquals(false, evaluateSimpleExpression("isEmpty(\" \")")); assertEquals("bread&butter", evaluateSimpleExpression("escapeXml(\"bread&butter\")")); assertEquals("Test", evaluateSimpleExpression("capitalize(\"test\")")); assertEquals("item1,item2", evaluateSimpleExpression("join(var1, \",\")", Collections.singletonMap("var1", new Object[] {"item1", "item2"}))); diff --git a/docs/AdvancedFeatures.md b/docs/AdvancedFeatures.md index 657e3bf3..383c3b70 100644 --- a/docs/AdvancedFeatures.md +++ b/docs/AdvancedFeatures.md @@ -24,6 +24,8 @@ Function Signature | Description `endsWith(String str, String suffix)`|[`StringUtils.endsWith(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#endsWith(java.lang.CharSequence,%20java.lang.CharSequence)) `startsWith(String str, String prefix)`| [`StringUtils.startsWith(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#startsWith(java.lang.CharSequence,%20java.lang.CharSequence)) `length(String string)`| [`StringUtils.length(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#length(java.lang.CharSequence)) +`isBlank(String str)` | [`StringUtils.isBlank(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#isBlank(java.lang.CharSequence)) +`isEmpty(String str)` | [`StringUtils.isEmpty(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#isEmpty(java.lang.CharSequence)) `defaultIfEmpty(String str, String default)` | [`StringUtils.defaultIfEmpty(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#defaultIfEmpty(T,%20T)) `escapeXml(String str)` | [`StringEscapeUtils.escapeXml10(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringEscapeUtils.html#escapeXml10(java.lang.String)), useful for escaping values within `initialContent` which uses [enhanced JCR DocView syntax (an XML 1.0 language)](https://jackrabbit.apache.org/filevault/docview.html). `containsItem(List list, String item)`| Returns `true` if the item is contained in the given list.