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 |
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
42 |
|
public class AddressConverter extends AbstractConverter<Address> |
43 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
44 |
12 |
@Override... |
45 |
|
protected Address convertToType(Type targetType, Object value) |
46 |
|
{ |
47 |
12 |
if (value == null) { |
48 |
2 |
return null; |
49 |
|
} |
50 |
|
|
51 |
10 |
Address address; |
52 |
|
|
53 |
10 |
try { |
54 |
10 |
address = InternetAddress.parse(value.toString())[0]; |
55 |
|
} catch (AddressException e) { |
56 |
1 |
throw new ConversionException( |
57 |
|
String.format("Failed to convert [%s] to [%s]", value, Address.class.getName()), e); |
58 |
|
} |
59 |
|
|
60 |
9 |
return address; |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0 |
@Override... |
64 |
|
protected String convertToString(Address value) |
65 |
|
{ |
66 |
0 |
return InternetAddress.toString(new Address[] {value}); |
67 |
|
} |
68 |
|
} |