Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

751 Expose isEmpty and isBlank for EL evaluation #752

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
kwin marked this conversation as resolved.
Show resolved Hide resolved
`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
Loading