BuilderResource.java
2.19 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
66
67
68
69
70
71
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceMetadata
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.SyntheticResource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
*/
package com.day.cq.wcm.core.impl;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.SyntheticResource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
public class BuilderResource
extends SyntheticResource {
private Map<String, Object> properties = new LinkedHashMap<String, Object>();
private Map<String, Resource> children = new LinkedHashMap<String, Resource>();
public BuilderResource(ResourceResolver resourceResolver, String path, String resourceType) {
super(resourceResolver, path, resourceType);
}
public BuilderResource(ResourceResolver resourceResolver, ResourceMetadata rm, String resourceType) {
super(resourceResolver, rm, resourceType);
}
public Resource getChild(String relPath) {
return this.children.get(relPath);
}
public Iterator<Resource> listChildren() {
return this.children.values().iterator();
}
public boolean hasChildren() {
return !this.children.isEmpty();
}
public BuilderResource setProperty(String name, Object value) {
this.properties.put(name, value);
return this;
}
public ValueMap getProperties() {
return this.adaptTo(ValueMap.class);
}
public BuilderResource addChild(Resource child) {
this.children.put(child.getName(), child);
return this;
}
public <Type> Type adaptTo(Class<Type> type) {
if (ValueMap.class.equals(type)) {
return (Type)new ValueMapDecorator(this.properties);
}
return (Type)super.adaptTo(type);
}
}