| 1 | /* | 
| 2 | *  jDTAUS Core Messages | 
| 3 | *  Copyright (C) 2005 Christian Schulte | 
| 4 | *  <cs@schulte.it> | 
| 5 | * | 
| 6 | *  This library is free software; you can redistribute it and/or | 
| 7 | *  modify it under the terms of the GNU Lesser General Public | 
| 8 | *  License as published by the Free Software Foundation; either | 
| 9 | *  version 2.1 of the License, or any later version. | 
| 10 | * | 
| 11 | *  This library is distributed in the hope that it will be useful, | 
| 12 | *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 13 | *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
| 14 | *  Lesser General Public License for more details. | 
| 15 | * | 
| 16 | *  You should have received a copy of the GNU Lesser General Public | 
| 17 | *  License along with this library; if not, write to the Free Software | 
| 18 | *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
| 19 | * | 
| 20 | */ | 
| 21 | package org.jdtaus.core.messages; | 
| 22 |  | 
| 23 | import java.io.File; | 
| 24 | import java.net.URL; | 
| 25 | import java.util.Locale; | 
| 26 | import org.jdtaus.core.container.ContainerFactory; | 
| 27 | import org.jdtaus.core.text.Message; | 
| 28 |  | 
| 29 | /** | 
| 30 | * {@code Message} stating how to report a bug. | 
| 31 | * | 
| 32 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> | 
| 33 | * @version $JDTAUS: BugReportMessage.java 8794 2012-12-03 16:51:09Z schulte $ | 
| 34 | */ | 
| 35 | public final class BugReportMessage extends Message | 
| 36 | { | 
| 37 | //--Contstants-------------------------------------------------------------- | 
| 38 |  | 
| 39 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ | 
| 40 | private static final long serialVersionUID = -6031830488657149254L; | 
| 41 |  | 
| 42 | //---------------------------------------------------------------Constants-- | 
| 43 | //--Message----------------------------------------------------------------- | 
| 44 |  | 
| 45 | /** | 
| 46 | * {@inheritDoc} | 
| 47 | * | 
| 48 | * @return Strings giving information for where to report bugs and where | 
| 49 | * to find any data to attach to any bug reports. | 
| 50 | * <ul> | 
| 51 | * <li>[0]: the absolute path of the directory holding the application's | 
| 52 | * logfiles.</li> | 
| 53 | * <li>[1]: URL of the online bugtracking system.</li> | 
| 54 | * <li>[2]: email address to alternatively send the bugreport to.</li> | 
| 55 | * </ul> | 
| 56 | */ | 
| 57 | public Object[] getFormatArguments( final Locale locale ) | 
| 58 | { | 
| 59 | if ( this.trackerUrl != null && this.reportAddress != null ) | 
| 60 | { | 
| 61 | return new Object[] | 
| 62 | { | 
| 63 | this.logDirectory.getAbsolutePath(), | 
| 64 | this.trackerUrl.toExternalForm(), | 
| 65 | this.reportAddress | 
| 66 | }; | 
| 67 | } | 
| 68 | else if ( this.trackerUrl != null ) | 
| 69 | { | 
| 70 | return new Object[] | 
| 71 | { | 
| 72 | this.logDirectory.getAbsolutePath(), | 
| 73 | this.trackerUrl.toExternalForm() | 
| 74 | }; | 
| 75 |  | 
| 76 | } | 
| 77 | else if ( this.reportAddress != null ) | 
| 78 | { | 
| 79 | return new Object[] | 
| 80 | { | 
| 81 | this.logDirectory.getAbsolutePath(), | 
| 82 | this.reportAddress | 
| 83 | }; | 
| 84 |  | 
| 85 | } | 
| 86 | else | 
| 87 | { | 
| 88 | return new Object[] | 
| 89 | { | 
| 90 | this.logDirectory.getAbsolutePath() | 
| 91 | }; | 
| 92 |  | 
| 93 | } | 
| 94 | } | 
| 95 |  | 
| 96 | /** | 
| 97 | * {@inheritDoc} | 
| 98 | * | 
| 99 | * @return The corresponding text from the message's {@code ResourceBundle}: | 
| 100 | * <blockquote><pre> | 
| 101 | * Please report this at {1} or send | 
| 102 | * an email to {2} including a copy of the logfiles located in directory | 
| 103 | * {0}. | 
| 104 | * </pre></blockquote> | 
| 105 | */ | 
| 106 | public String getText( final Locale locale ) | 
| 107 | { | 
| 108 | if ( this.trackerUrl != null && this.reportAddress != null ) | 
| 109 | { | 
| 110 | return this.getBugReportUrlAndEmailMessage( | 
| 111 | locale, this.logDirectory.getAbsolutePath(), | 
| 112 | this.trackerUrl.toExternalForm(), this.reportAddress ); | 
| 113 |  | 
| 114 | } | 
| 115 | else if ( this.trackerUrl != null ) | 
| 116 | { | 
| 117 | return this.getBugReportUrlMessage( | 
| 118 | locale, this.logDirectory.getAbsolutePath(), | 
| 119 | this.trackerUrl.toExternalForm() ); | 
| 120 |  | 
| 121 | } | 
| 122 | else if ( this.reportAddress != null ) | 
| 123 | { | 
| 124 | return this.getBugReportEmailMessage( | 
| 125 | locale, this.logDirectory.getAbsolutePath(), | 
| 126 | this.reportAddress ); | 
| 127 |  | 
| 128 | } | 
| 129 | else | 
| 130 | { | 
| 131 | return this.getBugReportMessage( | 
| 132 | locale, this.logDirectory.getAbsolutePath() ); | 
| 133 |  | 
| 134 | } | 
| 135 | } | 
| 136 |  | 
| 137 | //-----------------------------------------------------------------Message-- | 
| 138 | //--BugReportMessage-------------------------------------------------------- | 
| 139 |  | 
| 140 | /** | 
| 141 | * Directory holding the application's log files. | 
| 142 | * @serial | 
| 143 | */ | 
| 144 | private File logDirectory; | 
| 145 |  | 
| 146 | /** | 
| 147 | * URL of the online bugtracking system. | 
| 148 | * @serial | 
| 149 | */ | 
| 150 | private URL trackerUrl; | 
| 151 |  | 
| 152 | /** | 
| 153 | * Mail address to send the bugreport to. | 
| 154 | * @serial | 
| 155 | */ | 
| 156 | private String reportAddress; | 
| 157 |  | 
| 158 | /** | 
| 159 | * Creates a new {@code BugReportMessage} taking the application's logfile | 
| 160 | * directory, an URL to the application's online bugtracking system, and | 
| 161 | * an email address where to send bugreports to alternatively. | 
| 162 | * | 
| 163 | * @param logDirectory the directory holding the application's logfiles. | 
| 164 | * @param trackerUrl an URL to the application's online bugtracking system. | 
| 165 | * @param reportAddress an email address to alternatively send bugreports | 
| 166 | * to. | 
| 167 | * | 
| 168 | * @throws NullPointerException if either {@code logDirectory} is | 
| 169 | * {@code null}. | 
| 170 | * @throws IllegalArgumentException if {@code logDirectory} is not a | 
| 171 | * directory. | 
| 172 | */ | 
| 173 | public BugReportMessage( final File logDirectory, final URL trackerUrl, | 
| 174 | final String reportAddress ) | 
| 175 | { | 
| 176 | if ( logDirectory == null ) | 
| 177 | { | 
| 178 | throw new NullPointerException( "logDirectory" ); | 
| 179 | } | 
| 180 | if ( !logDirectory.isDirectory() ) | 
| 181 | { | 
| 182 | throw new IllegalArgumentException( logDirectory.getAbsolutePath() ); | 
| 183 | } | 
| 184 |  | 
| 185 | this.logDirectory = logDirectory; | 
| 186 | this.trackerUrl = trackerUrl; | 
| 187 | this.reportAddress = reportAddress; | 
| 188 | } | 
| 189 |  | 
| 190 | //--------------------------------------------------------BugReportMessage-- | 
| 191 | //--Messages---------------------------------------------------------------- | 
| 192 |  | 
| 193 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages | 
| 194 | // This section is managed by jdtaus-container-mojo. | 
| 195 |  | 
| 196 | /** | 
| 197 | * Gets the text of message <code>bugReport</code>. | 
| 198 | * <blockquote><pre>Bitte melden Sie dieses Problem. Fügen Sie Ihrem Fehlerbericht bitte eine Kopie der aktuellen Protokolldateien der Anwendung aus Verzeichnis {0} bei.</pre></blockquote> | 
| 199 | * <blockquote><pre>Please report this including a copy of the logfiles located in directory {0}.</pre></blockquote> | 
| 200 | * | 
| 201 | * @param locale The locale of the message instance to return. | 
| 202 | * @param logDirectory Directory holding the application's logfiles. | 
| 203 | * | 
| 204 | * @return Information about how to report a bug. | 
| 205 | */ | 
| 206 | private String getBugReportMessage( final Locale locale, | 
| 207 | final java.lang.String logDirectory ) | 
| 208 | { | 
| 209 | return ContainerFactory.getContainer(). | 
| 210 | getMessage( this, "bugReport", locale, | 
| 211 | new Object[] | 
| 212 | { | 
| 213 | logDirectory | 
| 214 | }); | 
| 215 |  | 
| 216 | } | 
| 217 |  | 
| 218 | /** | 
| 219 | * Gets the text of message <code>bugReportUrl</code>. | 
| 220 | * <blockquote><pre>Bitte melden Sie dieses Problem unter {1}. Fügen Sie Ihrem Fehlerbericht bitte eine Kopie der aktuellen Protokolldateien der Anwendung aus Verzeichnis {0} bei.</pre></blockquote> | 
| 221 | * <blockquote><pre>Please report this at {1} including a copy of the logfiles located in directory {0}.</pre></blockquote> | 
| 222 | * | 
| 223 | * @param locale The locale of the message instance to return. | 
| 224 | * @param logDirectory Directory holding the application's logfiles. | 
| 225 | * @param trackerUrl URL to the application's online bugtracking system. | 
| 226 | * | 
| 227 | * @return Information about how to report a bug. | 
| 228 | */ | 
| 229 | private String getBugReportUrlMessage( final Locale locale, | 
| 230 | final java.lang.String logDirectory, | 
| 231 | final java.lang.String trackerUrl ) | 
| 232 | { | 
| 233 | return ContainerFactory.getContainer(). | 
| 234 | getMessage( this, "bugReportUrl", locale, | 
| 235 | new Object[] | 
| 236 | { | 
| 237 | logDirectory, | 
| 238 | trackerUrl | 
| 239 | }); | 
| 240 |  | 
| 241 | } | 
| 242 |  | 
| 243 | /** | 
| 244 | * Gets the text of message <code>bugReportEmail</code>. | 
| 245 | * <blockquote><pre>Bitte melden Sie dieses Problem per eMail an {1}. Fügen Sie Ihrem Fehlerbericht bitte eine Kopie der aktuellen Protokolldateien der Anwendung aus Verzeichnis {0} bei.</pre></blockquote> | 
| 246 | * <blockquote><pre>Please report this by sending an email to {1} including a copy of the logfiles located in directory {0}.</pre></blockquote> | 
| 247 | * | 
| 248 | * @param locale The locale of the message instance to return. | 
| 249 | * @param logDirectory Directory holding the application's logfiles. | 
| 250 | * @param reportAddress Email address to send bugreports to. | 
| 251 | * | 
| 252 | * @return Information about how to report a bug. | 
| 253 | */ | 
| 254 | private String getBugReportEmailMessage( final Locale locale, | 
| 255 | final java.lang.String logDirectory, | 
| 256 | final java.lang.String reportAddress ) | 
| 257 | { | 
| 258 | return ContainerFactory.getContainer(). | 
| 259 | getMessage( this, "bugReportEmail", locale, | 
| 260 | new Object[] | 
| 261 | { | 
| 262 | logDirectory, | 
| 263 | reportAddress | 
| 264 | }); | 
| 265 |  | 
| 266 | } | 
| 267 |  | 
| 268 | /** | 
| 269 | * Gets the text of message <code>bugReportUrlAndEmail</code>. | 
| 270 | * <blockquote><pre>Bitte melden Sie dieses Problem entweder unter {1} oder per eMail an {2}. Fügen Sie Ihrem Fehlerbericht bitte eine Kopie der aktuellen Protokolldateien der Anwendung aus Verzeichnis {0} bei.</pre></blockquote> | 
| 271 | * <blockquote><pre>Please report this at {1} or send an email to {2} including a copy of the logfiles located in directory {0}.</pre></blockquote> | 
| 272 | * | 
| 273 | * @param locale The locale of the message instance to return. | 
| 274 | * @param logDirectory Directory holding the application's logfiles. | 
| 275 | * @param trackerUrl URL to the application's online bugtracking system. | 
| 276 | * @param reportAddress Email address to alternatively send bugreports to. | 
| 277 | * | 
| 278 | * @return Information about how to report a bug. | 
| 279 | */ | 
| 280 | private String getBugReportUrlAndEmailMessage( final Locale locale, | 
| 281 | final java.lang.String logDirectory, | 
| 282 | final java.lang.String trackerUrl, | 
| 283 | final java.lang.String reportAddress ) | 
| 284 | { | 
| 285 | return ContainerFactory.getContainer(). | 
| 286 | getMessage( this, "bugReportUrlAndEmail", locale, | 
| 287 | new Object[] | 
| 288 | { | 
| 289 | logDirectory, | 
| 290 | trackerUrl, | 
| 291 | reportAddress | 
| 292 | }); | 
| 293 |  | 
| 294 | } | 
| 295 |  | 
| 296 | // </editor-fold>//GEN-END:jdtausMessages | 
| 297 |  | 
| 298 | //----------------------------------------------------------------Messages-- | 
| 299 | } |