JcrProps.java
1.83 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
59
60
61
62
63
64
65
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.callbacks.Option
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.sling.api.resource.Resource
* org.jetbrains.annotations.NotNull
*/
package com.adobe.cq.dam.s7imaging.impl.jcr.props;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropKey;
import com.scene7.is.util.callbacks.Option;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.jetbrains.annotations.NotNull;
public class JcrProps {
private static final JcrProps EMPTY_PROPS = new JcrProps(null){
@Override
protected Option<Property> getValue(String key) throws RepositoryException {
return Option.none();
}
};
private final Node node;
public static JcrProps jcrProps(@NotNull Node node) {
return new JcrProps(node);
}
public static JcrProps jcrProps(@NotNull Resource resource) {
return new JcrProps((Node)resource.adaptTo(Node.class));
}
public static JcrProps emptyJcrProps() {
return EMPTY_PROPS;
}
public final <T> T get(PropKey<T> propKey) throws RepositoryException {
Option<Property> propValue = this.getValue(propKey.name);
return propKey.extractValue(propValue);
}
public final <T> T get(PropKey<Option<T>> propKey, T defaultValue) throws RepositoryException {
return (T)this.get(propKey).getOrElse(defaultValue);
}
protected Option<Property> getValue(String key) throws RepositoryException {
if (this.node.hasProperty(key)) {
return Option.some((Object)this.node.getProperty(key));
}
return Option.none();
}
private JcrProps(Node node) {
this.node = node;
}
}