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.Message; |
26 |
|
import javax.mail.internet.MimeMessage; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.properties.converter.AbstractConverter; |
30 |
|
import org.xwiki.properties.converter.ConversionException; |
31 |
|
|
32 |
|
|
33 |
|
@link |
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
39 |
|
@Component |
40 |
|
@Singleton |
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 6 |
Complexity Density: 0.43 |
|
41 |
|
public class RecipientConverter extends AbstractConverter<Message.RecipientType> |
42 |
|
{ |
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 6 |
Complexity Density: 0.43 |
|
43 |
7 |
@Override... |
44 |
|
protected <G extends Message.RecipientType> G convertToType(Type targetType, Object value) |
45 |
|
{ |
46 |
7 |
if (value == null) { |
47 |
0 |
return null; |
48 |
|
} |
49 |
|
|
50 |
7 |
Message.RecipientType recipientType; |
51 |
|
|
52 |
7 |
String valueAsString = value.toString(); |
53 |
7 |
if (valueAsString.equalsIgnoreCase("to")) { |
54 |
3 |
recipientType = Message.RecipientType.TO; |
55 |
4 |
} else if (valueAsString.equalsIgnoreCase("cc")) { |
56 |
1 |
recipientType = Message.RecipientType.CC; |
57 |
3 |
} else if (valueAsString.equalsIgnoreCase("bcc")) { |
58 |
1 |
recipientType = Message.RecipientType.BCC; |
59 |
2 |
} else if (valueAsString.equalsIgnoreCase("newsgroups")) { |
60 |
1 |
recipientType = MimeMessage.RecipientType.NEWSGROUPS; |
61 |
|
} else { |
62 |
1 |
throw new ConversionException(String.format("Cannot convert [%s] to [%s]", value, |
63 |
|
Message.RecipientType.class.getName())); |
64 |
|
} |
65 |
|
|
66 |
6 |
return (G) recipientType; |
67 |
|
} |
68 |
|
} |