001/*
002 *  jDTAUS Core Messages
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.messages;
022
023import java.io.File;
024import java.net.URL;
025import java.util.Locale;
026import org.jdtaus.core.container.ContainerFactory;
027import org.jdtaus.core.text.Message;
028
029/**
030 * {@code Message} stating how to report a bug.
031 *
032 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
033 * @version $JDTAUS: BugReportMessage.java 8641 2012-09-27 06:45:17Z schulte $
034 */
035public final class BugReportMessage extends Message
036{
037    //--Contstants--------------------------------------------------------------
038
039    /** Serial version UID for backwards compatibility with 1.0.x classes. */
040    private static final long serialVersionUID = -6031830488657149254L;
041
042    //---------------------------------------------------------------Constants--
043    //--Message-----------------------------------------------------------------
044
045    /**
046     * {@inheritDoc}
047     *
048     * @return Strings giving information for where to report bugs and where
049     * to find any data to attach to any bug reports.
050     * <ul>
051     * <li>[0]: the absolute path of the directory holding the application's
052     * logfiles.</li>
053     * <li>[1]: URL of the online bugtracking system.</li>
054     * <li>[2]: email address to alternatively send the bugreport to.</li>
055     * </ul>
056     */
057    public Object[] getFormatArguments( final Locale locale )
058    {
059        return new Object[]
060            {
061                this.logDirectory.getAbsolutePath(),
062                this.trackerUrl.toExternalForm(),
063                this.reportAddress
064            };
065    }
066
067    /**
068     * {@inheritDoc}
069     *
070     * @return The corresponding text from the message's {@code ResourceBundle}:
071     * <blockquote><pre>
072     * Please report this at {1} or send
073     * an email to {2} including a copy of the logfiles located in directory
074     * {0}.
075     * </pre></blockquote>
076     */
077    public String getText( final Locale locale )
078    {
079        return this.getBugReportMessage( locale,
080                                         this.logDirectory.getAbsolutePath(),
081                                         this.trackerUrl.toExternalForm(),
082                                         this.reportAddress );
083
084    }
085
086    //-----------------------------------------------------------------Message--
087    //--BugReportMessage--------------------------------------------------------
088
089    /**
090     * Directory holding the application's log files.
091     * @serial
092     */
093    private File logDirectory;
094
095    /**
096     * URL of the online bugtracking system.
097     * @serial
098     */
099    private URL trackerUrl;
100
101    /**
102     * Mail address to send the bugreport to.
103     * @serial
104     */
105    private String reportAddress;
106
107    /**
108     * Creates a new {@code BugReportMessage} taking the application's logfile
109     * directory, an URL to the application's online bugtracking system, and
110     * an email address where to send bugreports to alternatively.
111     *
112     * @param logDirectory the directory holding the application's logfiles.
113     * @param trackerUrl an URL to the application's online bugtracking system.
114     * @param reportAddress an email address to alternatively send bugreports
115     * to.
116     *
117     * @throws NullPointerException if either {@code logDirectory},
118     * {@code trackerUrl} or {@code reportAddress} is {@code null}.
119     * @throws IllegalArgumentException if {@code logDirectory} is not a
120     * directory.
121     */
122    public BugReportMessage( final File logDirectory, final URL trackerUrl,
123                             final String reportAddress )
124    {
125        if ( logDirectory == null )
126        {
127            throw new NullPointerException( "logDirectory" );
128        }
129        if ( !logDirectory.isDirectory() )
130        {
131            throw new IllegalArgumentException( logDirectory.getAbsolutePath() );
132        }
133        if ( trackerUrl == null )
134        {
135            throw new NullPointerException( "trackerUrl" );
136        }
137        if ( reportAddress == null )
138        {
139            throw new NullPointerException( "reportAddress" );
140        }
141
142        this.logDirectory = logDirectory;
143        this.trackerUrl = trackerUrl;
144        this.reportAddress = reportAddress;
145    }
146
147    //--------------------------------------------------------BugReportMessage--
148    //--Messages----------------------------------------------------------------
149
150// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
151    // This section is managed by jdtaus-container-mojo.
152
153    /**
154     * Gets the text of message <code>bugReport</code>.
155     * <blockquote><pre>Bitte berichten 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>
156     * <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>
157     *
158     * @param locale The locale of the message instance to return.
159     * @param logDirectory Directory holding the application's logfiles.
160     * @param trackerUrl URL to the application's online bugtracking system.
161     * @param reportAddress Email address to alternatively send bugreports to.
162     *
163     * @return Information about how to report a bug.
164     */
165    private String getBugReportMessage( final Locale locale,
166            final java.lang.String logDirectory,
167            final java.lang.String trackerUrl,
168            final java.lang.String reportAddress )
169    {
170        return ContainerFactory.getContainer().
171            getMessage( this, "bugReport", locale,
172                new Object[]
173                {
174                    logDirectory,
175                    trackerUrl,
176                    reportAddress
177                });
178
179    }
180
181// </editor-fold>//GEN-END:jdtausMessages
182
183    //----------------------------------------------------------------Messages--
184}