1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
|
24 |
|
import javax.inject.Singleton; |
25 |
|
import javax.mail.Address; |
26 |
|
import javax.mail.internet.AddressException; |
27 |
|
import javax.mail.internet.InternetAddress; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.properties.converter.AbstractConverter; |
31 |
|
import org.xwiki.properties.converter.ConversionException; |
32 |
|
|
33 |
|
|
34 |
|
@link |
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
40 |
|
@Component |
41 |
|
@Singleton |
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
42 |
|
public class AddressesConverter extends AbstractConverter<Address[]> |
43 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
44 |
24 |
@Override... |
45 |
|
protected Address[] convertToType(Type targetType, Object value) |
46 |
|
{ |
47 |
24 |
if (value == null) { |
48 |
18 |
return null; |
49 |
|
} |
50 |
|
|
51 |
6 |
if (value instanceof Address[]) { |
52 |
1 |
return (Address[]) value; |
53 |
|
} |
54 |
|
|
55 |
5 |
Address[] addresses; |
56 |
|
|
57 |
5 |
try { |
58 |
5 |
addresses = InternetAddress.parse(value.toString()); |
59 |
|
} catch (AddressException e) { |
60 |
1 |
throw new ConversionException( |
61 |
|
String.format("Failed to convert [%s] to an array of [%s]", value, Address.class.getName()), e); |
62 |
|
} |
63 |
|
|
64 |
4 |
return addresses; |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
@Override... |
68 |
|
protected String convertToString(Address[] value) |
69 |
|
{ |
70 |
0 |
return InternetAddress.toString(value); |
71 |
|
} |
72 |
|
} |