Skip to content

Commit

Permalink
Expose isEmpty and isBlank for EL evaluation (#752)
Browse files Browse the repository at this point in the history
This closes #751
  • Loading branch information
Positronic-Brain authored Jul 16, 2024
1 parent 4c4ae9e commit 71ccfd8
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion accesscontroltool-apps-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ 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("defaultIfBlank", 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,9 +34,15 @@ 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"})));
assertEquals("foo", evaluateSimpleExpression("defaultIfBlank(\" \",\"foo\")"));
assertEquals("bar", evaluateSimpleExpression("defaultIfBlank(\"bar\",\"foo\")"));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-content-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-exampleconfig-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-oakindex-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion accesscontroltool-startuphook-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
52 changes: 27 additions & 25 deletions docs/AdvancedFeatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ Expressions are evaluated using the [Jakarta Expression Language 4.0](https://ja
The following utility functions are made available to any EL expression used in YAML.
They can either be used standalone or combined with the [default EL operators](https://docs.oracle.com/javaee/6/tutorial/doc/bnaik.html).

Function Signature | Description
---|---
`split(String str, String separator)`|[`StringUtils.split(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#split(java.lang.String,%20java.lang.String))
`join(Object[] array, String separator)`|[`StringUtils.join(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#join(java.lang.Object[],%20java.lang.String))
`subarray(String array, startIndexInclusive,endIndexExclusive)`| [`ArrayUtils.subarray(...)`](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/ArrayUtils.html#subarray-T:A-int-int-)
`upperCase(String str)`|[`StringUtils.upperCase(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#upperCase(java.lang.String))
`lowerCase(String str)`|[`StringUtils.lowerCase(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#lowerCase(java.lang.String))
`capitalize(String str)`|[`StringUtils.capitalize(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#capitalize(java.lang.String))
`replace(String text, String searchString, String replacement)`|[`StringUtils.replace(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#replace(java.lang.String,%20java.lang.String,%20java.lang.String))
`substringAfter(String str, String separator)`|[`StringUtils.substringAfter(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringAfter(java.lang.String,%20java.lang.String))
`substringBefore(String str, String separator)`|[`StringUtils.substringBefore(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringBefore(java.lang.String,%20java.lang.String))
`substringAfterLast(String str, String separator)`|[`StringUtils.substringAfterLast(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringAfterLast(java.lang.String,%20java.lang.String))
`substringBeforeLast(String str, String separator)`|[`StringUtils.substringBeforeLast(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringBeforeLast(java.lang.String,%20java.lang.String))
`contains(String str, String fragmentStr)`|[`StringUtils.contains(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#contains(java.lang.CharSequence,%20java.lang.CharSequence))
`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))
`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.
`containsAnyItem(List<String> list, List<String> items)`| Returns `true` if any of the items is contained in the given list.
`containsAllItems(List<String> list, List<String> items)`| Returns `true` if all of the items are contained in the given list (independent of their order).
`keys(Map<Object, Object> map)`| Returns the list of keys for the given map. The order is non-predictable.
`values(Map<Object, Object> map)`| Returns all values for the given map. The order is non-predictable.

Function Signature | Description | Since
---|---|---
`capitalize(String str)`| [`StringUtils.capitalize(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#capitalize(java.lang.String)) | 3.1.0
`contains(String str, String fragmentStr)`| [`StringUtils.contains(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#contains(java.lang.CharSequence,%20java.lang.CharSequence)) | 1.8.0
`containsAllItems(List<String> list, List<String> items)`| Returns `true` if all of the items are contained in the given list (independent of their order). | 2.6.1
`containsAnyItem(List<String> list, List<String> items)`| Returns `true` if any of the items is contained in the given list. | 2.6.1
`containsItem(List<String> list, String item)`| Returns `true` if the item is contained in the given list. | 2.2.0
`defaultIfBlank(String str, String default)` | [`StringUtils.defaultIfBlank(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#defaultIfBlank(T,%20T)) | 3.3.0
`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)) | 2.5.0
`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)) | 1.8.0
`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) | 3.1.0
`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)) | 3.3.0
`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)) | 3.3.0
`join(Object[] array, String separator)`| [`StringUtils.join(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#join(java.lang.Object[],%20java.lang.String)) | 1.8.0
`keys(Map<Object, Object> map)`| Returns the list of keys for the given map. The order is non-predictable. | 2.6.0
`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)) | 2.0.6
`lowerCase(String str)`| [`StringUtils.lowerCase(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#lowerCase(java.lang.String)) | 1.8.0
`upperCase(String str)`| [`StringUtils.upperCase(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#upperCase(java.lang.String)) | 1.8.0
`replace(String text, String searchString, String replacement)`| [`StringUtils.replace(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#replace(java.lang.String,%20java.lang.String,%20java.lang.String)) | 1.9.3
`split(String str, String separator)`| [`StringUtils.split(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#split(java.lang.String,%20java.lang.String)) | 1.8.0
`subarray(String array, startIndexInclusive,endIndexExclusive)`| [`ArrayUtils.subarray(...)`](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/ArrayUtils.html#subarray-T:A-int-int-) | 1.8.0
`substringAfter(String str, String separator)`| [`StringUtils.substringAfter(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringAfter(java.lang.String,%20java.lang.String)) | 1.8.0
`substringAfterLast(String str, String separator)`| [`StringUtils.substringAfterLast(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringAfterLast(java.lang.String,%20java.lang.String)) | 1.8.0
`substringBefore(String str, String separator)`| [`StringUtils.substringBefore(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringBefore(java.lang.String,%20java.lang.String)) | 1.8.0
`substringBeforeLast(String str, String separator)`| [`StringUtils.substringBeforeLast(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#substringBeforeLast(java.lang.String,%20java.lang.String)) | 1.8.0
`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)) | 1.8.0
`values(Map<Object, Object> map)`| Returns all values for the given map. The order is non-predictable. | 2.6.0

## Variables

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>accesscontroltool</artifactId>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Access Control Tool</name>
Expand Down
2 changes: 1 addition & 1 deletion target-osgi-environment/maximum-environment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>biz.netcentric.cq.tools.accesscontroltool</groupId>
<artifactId>target-osgi-environment</artifactId>
<relativePath>../pom.xml</relativePath>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
</parent>

<artifactId>maximum-environment</artifactId>
Expand Down
Loading

0 comments on commit 71ccfd8

Please sign in to comment.