JcrUtil.java
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.callbacks.Option
* javax.jcr.Node
* javax.jcr.RepositoryException
* org.apache.sling.api.adapter.Adaptable
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.jetbrains.annotations.NotNull
*/
package com.adobe.cq.dam.s7imaging.impl.catalog;
import com.scene7.is.util.callbacks.Option;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.jetbrains.annotations.NotNull;
public class JcrUtil {
private static final String RELATIONS_PATH = "{http://www.jcp.org/jcr/1.0}content/related";
public static Option<Resource> getResource(ResourceResolver resolver, String path) {
return Option.some((Object)resolver.getResource(path));
}
public static Option<Node> getNode(Node node, String relPath) throws RepositoryException {
if (node.hasNode(relPath)) {
return Option.some((Object)node.getNode(relPath));
}
return Option.none();
}
public static Option<Resource> getChild(Resource resource, String relPath) {
return Option.some((Object)resource.getChild(relPath));
}
@NotNull
public static <T> Option<T> adaptTo(Class<T> clazz, @NotNull Adaptable instance) {
return Option.some((Object)instance.adaptTo(clazz));
}
@NotNull
public static <T> T as(@NotNull Class<T> clazz, @NotNull Adaptable instance) {
Object result = instance.adaptTo(clazz);
if (result != null) {
return (T)result;
}
throw new IllegalArgumentException((Object)instance + " is not adaptable to " + clazz);
}
private JcrUtil() {
}
}