StandardExtractors.java
3.63 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.text.Parser
* com.scene7.is.util.text.ParsingException
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Value
*/
package com.adobe.cq.dam.s7imaging.impl.jcr.props;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropExtractor;
import com.scene7.is.util.text.Parser;
import com.scene7.is.util.text.ParsingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
public class StandardExtractors {
public static final PropExtractor<Boolean> toBoolean = new PropExtractor<Boolean>(new int[]{6}){
@Override
public Boolean extract(Property prop) throws RepositoryException {
return prop.getBoolean();
}
};
public static final PropExtractor<Integer> toInteger = new PropExtractor<Integer>(new int[]{3, 1}){
@Override
public Integer extract(Property prop) throws RepositoryException {
return (int)prop.getLong();
}
};
public static final PropExtractor<Long> toLong = new PropExtractor<Long>(new int[]{3, 1, 5}){
@Override
public Long extract(Property prop) throws RepositoryException {
return prop.getLong();
}
};
public static final PropExtractor<Double> toDouble = new PropExtractor<Double>(new int[]{4, 3, 1}){
@Override
public Double extract(Property prop) throws RepositoryException {
return prop.getDouble();
}
};
public static final PropExtractor<Calendar> toCalendar = new PropExtractor<Calendar>(new int[]{5}){
@Override
public Calendar extract(Property prop) throws RepositoryException {
return prop.getDate();
}
};
public static final PropExtractor<URI> toURI = new PropExtractor<URI>(new int[]{11}){
@Override
public URI extract(Property prop) throws RepositoryException {
try {
return new URI(prop.getString());
}
catch (URISyntaxException e) {
throw new RepositoryException("Unable to parse URI from " + (Object)prop);
}
}
};
public static final PropExtractor<String> toString = new PropExtractor<String>(new int[]{1, 7}){
@Override
public String extract(Property prop) throws RepositoryException {
return prop.getString();
}
};
public static final PropExtractor<String[]> toStringArray = new PropExtractor<String[]>(new int[]{1}){
@Override
public String[] extract(Property prop) throws RepositoryException {
if (prop.isMultiple()) {
Value[] values = prop.getValues();
String[] result = new String[values.length];
for (int i = 0; i < values.length; ++i) {
result[i] = values[i].getString();
}
return result;
}
return new String[]{prop.getString()};
}
};
public static <T> PropExtractor<T> parsingExtractor(final Parser<T> parser) {
return new PropExtractor<T>(new int[]{1}){
@Override
protected T extract(Property prop) throws RepositoryException {
try {
return (T)parser.parse(prop.getString());
}
catch (ParsingException e) {
throw new RepositoryException("Unable to parse property: " + (Object)prop, (Throwable)e);
}
}
};
}
}