SimplePropertyDefinition.java
4.38 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
*/
package com.adobe.cq.mobile.index.impl.builder;
import com.adobe.cq.mobile.index.impl.builder.PropertyDefinition;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
public class SimplePropertyDefinition
implements PropertyDefinition {
private String nodeName;
private String property;
private String propertyType;
private boolean propertyIndex;
private float boost = 1.0f;
private boolean nodeScopeIndex;
private boolean analyzed;
private boolean useInSuggest;
private boolean useInSpellcheck;
private boolean ordered;
public SimplePropertyDefinition(String property, String nodeName) {
this.setNodeName(nodeName);
this.setProperty(property);
this.setPropertyIndex(true);
}
public SimplePropertyDefinition(String property, String nodeName, String propertyType) {
this(property, nodeName);
this.setPropertyType(propertyType);
}
public SimplePropertyDefinition(String property, String nodeName, String propertyType, boolean nodeScopeIndex, boolean analyzed) {
this(property, nodeName, propertyType);
this.setNodeScopeIndex(nodeScopeIndex);
this.setAnalyzed(analyzed);
}
public SimplePropertyDefinition(String property, String nodeName, String propertyType, boolean nodeScopeIndex, boolean analyzed, float boost) {
this(property, nodeName, propertyType, nodeScopeIndex, analyzed);
this.setBoost(boost);
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
public void setProperty(String prop) {
this.property = prop;
}
public SimplePropertyDefinition setPropertyType(String type) {
this.propertyType = type;
return this;
}
public SimplePropertyDefinition setNodeScopeIndex(boolean nodeScopeIndex) {
this.nodeScopeIndex = nodeScopeIndex;
return this;
}
public SimplePropertyDefinition setBoost(float boost) {
this.boost = boost;
return this;
}
public SimplePropertyDefinition setAnalyzed(boolean analyzed) {
this.analyzed = analyzed;
return this;
}
public SimplePropertyDefinition setUseInSuggest(boolean useInSuggest) {
this.useInSuggest = useInSuggest;
return this;
}
public SimplePropertyDefinition setUseInSpellcheck(boolean useInSpellcheck) {
this.useInSpellcheck = useInSpellcheck;
return this;
}
public SimplePropertyDefinition setOrdered(boolean ordered) {
this.ordered = ordered;
return this;
}
private SimplePropertyDefinition setPropertyIndex(boolean propertyIndex) {
this.propertyIndex = propertyIndex;
return this;
}
@Override
public void build(Resource resource) throws PersistenceException {
ResourceResolver resolver = resource.getResourceResolver();
if (resolver.getResource(resource, this.nodeName) != null) {
resolver.delete(resolver.getResource(resource, this.nodeName));
}
HashMap<String, Object> propsMap = new HashMap<String, Object>();
propsMap.put("name", this.property);
propsMap.put("propertyIndex", this.propertyIndex);
if (this.ordered) {
propsMap.put("ordered", true);
}
if (this.analyzed) {
propsMap.put("analyzed", true);
}
if (this.useInSuggest) {
propsMap.put("useInSuggest", true);
propsMap.put("nodeScopeIndex", true);
}
if (this.useInSpellcheck) {
propsMap.put("useInSpellcheck", true);
propsMap.put("nodeScopeIndex", true);
}
if (this.boost > 1.0f) {
propsMap.put("boost", Float.valueOf(this.boost));
}
if (this.nodeScopeIndex) {
propsMap.put("nodeScopeIndex", this.nodeScopeIndex);
}
if (this.propertyType != null && !this.propertyType.isEmpty()) {
propsMap.put("type", this.propertyType);
}
resolver.create(resource, this.nodeName, propsMap);
}
}