| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DesktopMail |
|
| 1.7142857142857142;1.714 |
| 1 | package org.jtheque.utils; | |
| 2 | ||
| 3 | /* | |
| 4 | * This file is part of JTheque. | |
| 5 | * | |
| 6 | * JTheque is free software: you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation, either version 3 of the License. | |
| 9 | * | |
| 10 | * JTheque 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 | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | import java.net.URI; | |
| 20 | import java.net.URISyntaxException; | |
| 21 | ||
| 22 | /** | |
| 23 | * A desktop mail. It seems a mail to display on the default mailer. | |
| 24 | * | |
| 25 | * @author Baptiste Wicht | |
| 26 | */ | |
| 27 | 0 | public final class DesktopMail { |
| 28 | private String subject; | |
| 29 | private String body; | |
| 30 | private String to; | |
| 31 | ||
| 32 | /** | |
| 33 | * Return the URI for this mail. | |
| 34 | * | |
| 35 | * @return The URI. | |
| 36 | * @throws URISyntaxException When an errors occurs during the URI construction. | |
| 37 | */ | |
| 38 | public URI getURI() throws URISyntaxException { | |
| 39 | 0 | StringBuilder builder = new StringBuilder("mailto:"); |
| 40 | 0 | boolean first = true; |
| 41 | ||
| 42 | 0 | builder.append(to); |
| 43 | ||
| 44 | 0 | if (subject != null && !subject.isEmpty()) { |
| 45 | 0 | builder.append("?subject="); |
| 46 | 0 | builder.append(subject); |
| 47 | 0 | first = false; |
| 48 | } | |
| 49 | ||
| 50 | 0 | if (body != null && !body.isEmpty()) { |
| 51 | 0 | if (first) { |
| 52 | 0 | builder.append('?'); |
| 53 | } else { | |
| 54 | 0 | builder.append('&'); |
| 55 | } | |
| 56 | ||
| 57 | 0 | builder.append("body="); |
| 58 | 0 | builder.append(body); |
| 59 | } | |
| 60 | ||
| 61 | 0 | return new URI(builder.toString()); |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Return the body of the mail. | |
| 66 | * | |
| 67 | * @return The body of the mail. | |
| 68 | */ | |
| 69 | public String getBody() { | |
| 70 | 0 | return body; |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Set the body of the mail. | |
| 75 | * | |
| 76 | * @param body The body of the mail. | |
| 77 | */ | |
| 78 | public void setBody(String body) { | |
| 79 | 0 | this.body = body; |
| 80 | 0 | } |
| 81 | ||
| 82 | /** | |
| 83 | * Return the subject of the mail. | |
| 84 | * | |
| 85 | * @return The subject | |
| 86 | */ | |
| 87 | public String getSubject() { | |
| 88 | 0 | return subject; |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * Set the subject of the mail. | |
| 93 | * | |
| 94 | * @param subject The new subject to set | |
| 95 | */ | |
| 96 | public void setSubject(String subject) { | |
| 97 | 0 | this.subject = subject; |
| 98 | 0 | } |
| 99 | ||
| 100 | /** | |
| 101 | * Return the to address. | |
| 102 | * | |
| 103 | * @return The to address. | |
| 104 | */ | |
| 105 | public String getTo() { | |
| 106 | 0 | return to; |
| 107 | } | |
| 108 | ||
| 109 | /** | |
| 110 | * Set the to address. | |
| 111 | * | |
| 112 | * @param to The to address. | |
| 113 | */ | |
| 114 | public void setTo(String to) { | |
| 115 | 0 | this.to = to; |
| 116 | 0 | } |
| 117 | } |