those are pipes that will spit out resources, without modifying them. They are usually combined with logical and/or writer pipes
echo <path>
)outputs what is in input (so what is configured in path).
It's handy to set the input of a given sequence in a talkative manner:
echo /content | write foo=bar
You can also pipe it with relative path to go to a children:
echo /content | $ some/parent | echo child/path | ...
xpath <xpath query>
) xpath /jcr:root/content/foo//element(*,nt:unstructured)[@sling:resourceType="foo/bar"] | write foo=bar
traverse
)traverse current input resource's tree, outputing, as resources, either the node of the tree, either its properties
breadthFirst
the tree visit will be done deep first, unless this flag is set to true,depth
max depth the visit should go to,properties
is a flag mentioning the pipe should traverse node's property,nameGlobs
filters the property that should get outputed
echo /content | traverse @ with breadFirst=true depth=10 properties=true | ...
mp
)iterates through values of input multi value property and write them to bindings
echo /content/my/months | mp @ name currentMonth | echo /content/year/${currentMonth} | write visited=true
Sling Query shares with Sling Pipes the same objective to write more concise (and efficient) code for most common operations. Below are the most common Sling Query methods as reader pipes.
$ <expr>
)executes find(expression) that searches through the subtree below the current input resource. Typical handy usage would be to use resource type selector like that:
echo /content | $ foo/bar
children <expr>
)executes children(expression) that searches through the immediate children of the current input resource)
echo /content/some/container | children foo/bar
siblings <expr>
)executes siblings(expression) that searches through siblings of current input resource
echo /content | siblings foo/bar
parent <expr>
)executes parent() that retrieves current parent
closest <expr>
)executes closest(expression) that searches the closest parent resource of current input resource
echo /content | $ foo/bar | closest jcr:content
will find jcr:content
nodes that have foo/bar
typed resource somewhere in their tree
parents <expr>
)executes parents(expression) that searches all the parents of the current input resource
those are specific reader pipes, that read information an input stream from defined in expr configuration, that can be:
pipes_inputFile
as parameter name (in that case, expr can be empty)json expr
)feeds bindings with json stream valuePath
is a property as a json path like expression that defines where the json value we care about is. E.g. $.items[2]
considers root is an object and that we want the 3rd item of items array, located at items
key of the root object.
In case the json value is an array, the pipe will loop over the array elements, and output each one in the binding. Output resource remains each time the input one.
json {"items":[{"val":"1"},{"val":"2"},{"val":"3"}]} @ with valuePath=$.items @ name demo | mkdir /content/${demo.val}
will create a tree of 3 resources /content/1, /content/2 and /content/3.
An interesting usage of the JSON pipe can also be to loop over an array of Strings like
json ["/content/mySite/page1","/content/mySite/page2","/content/mySite/page3"]
| echo ${one}
| echo jcr:content
| write update=something
csv <expr>
)feeds bindings with csv stream
csv idx,val\\n1,1\n2,2\\n3,3 @ name demo
| mkdir /content/${demo.val}
should create a tree of 3 resources /content/1, /content/2 and /content/3. You can change separator with separator
property
csv a;b @ with separator=;
egrep <expr>
)feeds bindings with text input stream, parsed with a regexp pattern
, that is a regular expression, with named group (e.g. (?<user>.*)
) that will be used to produce the output binding names
egrep http://some.site.com @ with pattern=/res/(?<asset>/[\-\w\.\/0-9]+) @ name demo
| echo /content/assets
| write test=demo.asset
If the regex should be applied directly to the value of the expression rather than fetching the input from the url, property url_mode=as_is
can be configured
| json ["https://sling.apache.org/","http://sling.apache.org/"] @name domain
| egrep ${domain} @ with pattern=(?<httpspattern>https.*) with url_mode=as_is @ name httpsDomains
| write test=${httpsDomains.httpspattern}