Skip to content

Commit

Permalink
751 Expose isEmpty and isBlank for EL evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Positronic-Brain committed Jul 15, 2024
1 parent b253718 commit 5a3bea7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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&amp;butter", evaluateSimpleExpression("escapeXml(\"bread&butter\")"));
assertEquals("Test", evaluateSimpleExpression("capitalize(\"test\")"));
assertEquals("item1,item2", evaluateSimpleExpression("join(var1, \",\")", Collections.singletonMap("var1", new Object[] {"item1", "item2"})));
Expand Down
2 changes: 2 additions & 0 deletions docs/AdvancedFeatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> list, String item)`| Returns `true` if the item is contained in the given list.
Expand Down

0 comments on commit 5a3bea7

Please sign in to comment.