Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
MailStatusResultSerializer | 30 | 11 | 0% | 4 | 3 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.mail; | |
21 | ||
22 | import java.util.Iterator; | |
23 | ||
24 | /** | |
25 | * Serialize {@link org.xwiki.mail.MailStatusResult}. Helps reporting errors. | |
26 | * | |
27 | * @version $Id: 8185f38d6c0ee923cf51a6dbd127d44cce76a268 $ | |
28 | * @since 6.4RC1 | |
29 | */ | |
30 | public final class MailStatusResultSerializer | |
31 | { | |
32 | 0 | private MailStatusResultSerializer() |
33 | { | |
34 | // Voluntarily empty. | |
35 | } | |
36 | ||
37 | /** | |
38 | * @param statusResult the mail status results retrieved from a Mail Listener | |
39 | * @return the errors serialized as a String | |
40 | */ | |
41 | 1 | public static String serializeErrors(MailStatusResult statusResult) |
42 | { | |
43 | 1 | String result; |
44 | ||
45 | 1 | Iterator<MailStatus> statuses = statusResult.getAllErrors(); |
46 | 1 | if (statuses.hasNext()) { |
47 | 1 | StringBuilder builder = |
48 | new StringBuilder("Some messages have failed to be sent: ["); | |
49 | 3 | while (statuses.hasNext()) { |
50 | 2 | MailStatus status = statuses.next(); |
51 | 2 | builder.append('[').append(status.toString()).append(']'); |
52 | } | |
53 | 1 | builder.append(']'); |
54 | 1 | result = builder.toString(); |
55 | } else { | |
56 | 0 | result = null; |
57 | } | |
58 | 1 | return result; |
59 | } | |
60 | } |