32
32
import javax .jcr .Value ;
33
33
import javax .jcr .ValueFactory ;
34
34
import javax .jcr .ValueFormatException ;
35
+ import org .apache .commons .collections4 .CollectionUtils ;
35
36
import org .apache .commons .lang3 .StringUtils ;
36
37
37
38
public class Restrictions {
@@ -40,12 +41,14 @@ public class Restrictions {
40
41
41
42
private static final String REP_GLOB_PROPERTY = "rep:glob" ;
42
43
44
+ private static final String REP_GLOBS_PROPERTY = "rep:globs" ;
45
+
43
46
private static final String REP_NT_NAMES_PROPERTY = "rep:ntNames" ;
44
47
45
48
private static final String REP_ITEM_NAMES_PROPERTY = "rep:itemNames" ;
46
49
47
50
private static final Set <String > MULTI_VALUE_REP_PROPERTIES = ImmutableSet .of (
48
- REP_NT_NAMES_PROPERTY , REP_ITEM_NAMES_PROPERTY , "rep:prefixes" , "rep:current " , "rep:globs " ,
51
+ REP_NT_NAMES_PROPERTY , REP_ITEM_NAMES_PROPERTY , REP_GLOBS_PROPERTY , "rep:prefixes " , "rep:current " ,
49
52
"rep:subtrees" , "sling:resourceTypes" , "sling:resourceTypesWithDescendants"
50
53
);
51
54
@@ -91,11 +94,15 @@ public Map<String, Value> getSingleValueRestrictions(ValueFactory valueFactory)
91
94
92
95
private void addRestriction (ValueFactory valueFactory , Map <String , Value > result , String key , String value ) throws ValueFormatException {
93
96
if (StringUtils .isNotBlank (value )) {
94
- if (REP_GLOB_PROPERTY .equals (key )) {
95
- result .put (key , normalizeGlob (valueFactory ));
96
- } else {
97
- result .put (key , valueFactory .createValue (value , determinePropertyType (key )));
98
- }
97
+ result .put (key , createValue (valueFactory , key , value ));
98
+ }
99
+ }
100
+
101
+ private Value createValue (ValueFactory valueFactory , String key , String value ) throws ValueFormatException {
102
+ if (StringUtils .equalsAny (key , REP_GLOB_PROPERTY , REP_GLOBS_PROPERTY )) {
103
+ return normalizeGlob (valueFactory );
104
+ } else {
105
+ return valueFactory .createValue (value , determinePropertyType (key ));
99
106
}
100
107
}
101
108
@@ -125,15 +132,15 @@ public Map<String, Value[]> getMultiValueRestrictions(ValueFactory valueFactory)
125
132
}
126
133
127
134
private void addRestrictions (ValueFactory valueFactory , Map <String , Value []> result , String key , List <String > names ) throws ValueFormatException {
128
- if (names != null && ! names .isEmpty ()) {
129
- result .put (key , createRestrictions (valueFactory , names , determinePropertyType ( key ) ));
135
+ if (! CollectionUtils .isEmpty (names )) {
136
+ result .put (key , createRestrictions (valueFactory , key , names ));
130
137
}
131
138
}
132
139
133
- private Value [] createRestrictions (ValueFactory valueFactory , List <String > names , int propertyType ) throws ValueFormatException {
140
+ private Value [] createRestrictions (ValueFactory valueFactory , String key , List <String > names ) throws ValueFormatException {
134
141
Value [] values = new Value [names .size ()];
135
142
for (int index = 0 ; index < names .size (); index ++) {
136
- values [index ] = valueFactory . createValue (names .get (index ), propertyType );
143
+ values [index ] = createValue (valueFactory , key , names .get (index ));
137
144
}
138
145
return values ;
139
146
}
0 commit comments