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.factory; |
21 |
|
|
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Provider; |
28 |
|
import javax.mail.MessagingException; |
29 |
|
import javax.mail.internet.MimeMessage; |
30 |
|
|
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
34 |
|
import org.xwiki.mail.MimeMessageFactory; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
42 |
|
public abstract class AbstractIteratorMimeMessageFactory extends AbstractMimeMessageFactory<Iterator<MimeMessage>> |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@Inject |
48 |
|
@Named("context") |
49 |
|
protected Provider<ComponentManager> componentManagerProvider; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
51 |
35 |
protected MimeMessageFactory getInternalMimeMessageFactory(String hint) throws MessagingException... |
52 |
|
{ |
53 |
35 |
try { |
54 |
35 |
return this.componentManagerProvider.get().getInstance(new DefaultParameterizedType(null, |
55 |
|
MimeMessageFactory.class, MimeMessage.class), hint); |
56 |
|
} catch (ComponentLookupException e) { |
57 |
3 |
throw new MessagingException(String.format("Failed to find a [%s<MimeMessage>] for hint [%s]", |
58 |
|
MimeMessageFactory.class.getSimpleName(), hint)); |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
@param |
67 |
|
@throws |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
69 |
44 |
protected void validateParameters(Map<String, Object> parameters, String... names)... |
70 |
|
throws MessagingException |
71 |
|
{ |
72 |
44 |
if (parameters == null) { |
73 |
3 |
throw new MessagingException("You must pass parameters for this Mime Message Factory to work!"); |
74 |
|
} |
75 |
|
|
76 |
41 |
for (String name : names) { |
77 |
109 |
Object parameterValue = parameters.get(name); |
78 |
109 |
if (parameterValue == null) { |
79 |
6 |
throw new MessagingException(String.format("The parameter [%s] is mandatory.", name)); |
80 |
|
} |
81 |
|
} |
82 |
|
} |
83 |
|
} |