Add javadoc.
[jSite.git] / src / de / todesbaum / jsite / application / ProjectInserter.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.jsite.application;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.ByteArrayOutputStream;
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37 import java.util.Map.Entry;
38 import java.util.logging.Level;
39 import java.util.logging.Logger;
40 import java.util.zip.ZipEntry;
41 import java.util.zip.ZipOutputStream;
42
43 import de.todesbaum.jsite.gui.FileScanner;
44 import de.todesbaum.jsite.gui.FileScannerListener;
45 import de.todesbaum.util.freenet.fcp2.Client;
46 import de.todesbaum.util.freenet.fcp2.ClientPutComplexDir;
47 import de.todesbaum.util.freenet.fcp2.Connection;
48 import de.todesbaum.util.freenet.fcp2.DirectFileEntry;
49 import de.todesbaum.util.freenet.fcp2.FileEntry;
50 import de.todesbaum.util.freenet.fcp2.Message;
51 import de.todesbaum.util.freenet.fcp2.RedirectFileEntry;
52 import de.todesbaum.util.freenet.fcp2.Verbosity;
53 import de.todesbaum.util.io.Closer;
54 import de.todesbaum.util.io.ReplacingOutputStream;
55 import de.todesbaum.util.io.StreamCopier;
56 import de.todesbaum.util.io.StreamCopier.ProgressListener;
57
58 /**
59  * Manages project inserts.
60  *
61  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
62  */
63 public class ProjectInserter implements FileScannerListener, Runnable {
64
65         /** The logger. */
66         private static final Logger logger = Logger.getLogger(ProjectInserter.class.getName());
67
68         /** Random number for FCP instances. */
69         private static final int random = (int) (Math.random() * Integer.MAX_VALUE);
70
71         /** Counter for FCP connection identifier. */
72         private static int counter = 0;
73
74         /** The list of insert listeners. */
75         private List<InsertListener> insertListeners = new ArrayList<InsertListener>();
76
77         /** The freenet interface. */
78         protected Freenet7Interface freenetInterface;
79
80         /** The project to insert. */
81         protected Project project;
82
83         /** The file scanner. */
84         private FileScanner fileScanner;
85
86         /** Object used for synchronization. */
87         protected final Object lockObject = new Object();
88
89         /** The temp directory. */
90         private String tempDirectory;
91
92         /** The current connection. */
93         private Connection connection;
94
95         /** Whether the insert is cancelled. */
96         private volatile boolean cancelled = false;
97
98         /** Progress listener for payload transfers. */
99         private ProgressListener progressListener;
100
101         /**
102          * Adds a listener to the list of registered listeners.
103          *
104          * @param insertListener
105          *            The listener to add
106          */
107         public void addInsertListener(InsertListener insertListener) {
108                 insertListeners.add(insertListener);
109         }
110
111         /**
112          * Removes a listener from the list of registered listeners.
113          *
114          * @param insertListener
115          *            The listener to remove
116          */
117         public void removeInsertListener(InsertListener insertListener) {
118                 insertListeners.remove(insertListener);
119         }
120
121         /**
122          * Notifies all listeners that the project insert has started.
123          *
124          * @see InsertListener#projectInsertStarted(Project)
125          */
126         protected void fireProjectInsertStarted() {
127                 for (InsertListener insertListener : insertListeners) {
128                         insertListener.projectInsertStarted(project);
129                 }
130         }
131
132         /**
133          * Notifies all listeners that the insert has generated a URI.
134          *
135          * @see InsertListener#projectURIGenerated(Project, String)
136          * @param uri
137          *            The generated URI
138          */
139         protected void fireProjectURIGenerated(String uri) {
140                 for (InsertListener insertListener : insertListeners) {
141                         insertListener.projectURIGenerated(project, uri);
142                 }
143         }
144
145         /**
146          * Notifies all listeners that the insert has made some progress.
147          *
148          * @see InsertListener#projectUploadFinished(Project)
149          */
150         protected void fireProjectUploadFinished() {
151                 for (InsertListener insertListener : insertListeners) {
152                         insertListener.projectUploadFinished(project);
153                 }
154         }
155
156         /**
157          * Notifies all listeners that the insert has made some progress.
158          *
159          * @see InsertListener#projectInsertProgress(Project, int, int, int, int,
160          *      boolean)
161          * @param succeeded
162          *            The number of succeeded blocks
163          * @param failed
164          *            The number of failed blocks
165          * @param fatal
166          *            The number of fatally failed blocks
167          * @param total
168          *            The total number of blocks
169          * @param finalized
170          *            <code>true</code> if the total number of blocks has already
171          *            been finalized, <code>false</code> otherwise
172          */
173         protected void fireProjectInsertProgress(int succeeded, int failed, int fatal, int total, boolean finalized) {
174                 for (InsertListener insertListener : insertListeners) {
175                         insertListener.projectInsertProgress(project, succeeded, failed, fatal, total, finalized);
176                 }
177         }
178
179         /**
180          * Notifies all listeners the project insert has finished.
181          *
182          * @see InsertListener#projectInsertFinished(Project, boolean, Throwable)
183          * @param success
184          *            <code>true</code> if the project was inserted successfully,
185          *            <code>false</code> if it failed
186          * @param cause
187          *            The cause of the failure, if any
188          */
189         protected void fireProjectInsertFinished(boolean success, Throwable cause) {
190                 for (InsertListener insertListener : insertListeners) {
191                         insertListener.projectInsertFinished(project, success, cause);
192                 }
193         }
194
195         /**
196          * Sets the project to insert.
197          *
198          * @param project
199          *            The project to insert
200          */
201         public void setProject(Project project) {
202                 this.project = project;
203         }
204
205         /**
206          * Sets the freenet interface to use.
207          *
208          * @param freenetInterface
209          *            The freenet interface to use
210          */
211         public void setFreenetInterface(Freenet7Interface freenetInterface) {
212                 this.freenetInterface = freenetInterface;
213         }
214
215         /**
216          * Sets the temp directory to use.
217          *
218          * @param tempDirectory
219          *            The temp directory to use, or {@code null} to use the system
220          *            default
221          */
222         public void setTempDirectory(String tempDirectory) {
223                 this.tempDirectory = tempDirectory;
224         }
225
226         /**
227          * Starts the insert.
228          *
229          * @param progressListener
230          *            Listener to notify on progress events
231          */
232         public void start(ProgressListener progressListener) {
233                 cancelled = false;
234                 this.progressListener = progressListener;
235                 fileScanner = new FileScanner(project);
236                 fileScanner.addFileScannerListener(this);
237                 new Thread(fileScanner).start();
238         }
239
240         /**
241          * Stops the current insert.
242          */
243         public void stop() {
244                 cancelled = true;
245                 synchronized (lockObject) {
246                         if (connection != null) {
247                                 connection.disconnect();
248                         }
249                 }
250         }
251
252         /**
253          * Creates an input stream that delivers the given file, replacing edition
254          * tokens in the file’s content, if necessary.
255          *
256          * @param filename
257          *            The name of the file
258          * @param fileOption
259          *            The file options
260          * @param edition
261          *            The current edition
262          * @param length
263          *            An array containing a single long which is used to
264          *            <em>return</em> the final length of the file, after all
265          *            replacements
266          * @return The input stream for the file
267          * @throws IOException
268          *             if an I/O error occurs
269          */
270         private InputStream createFileInputStream(String filename, FileOption fileOption, int edition, long[] length) throws IOException {
271                 File file = new File(project.getLocalPath(), filename);
272                 length[0] = file.length();
273                 if (!fileOption.getReplaceEdition()) {
274                         return new FileInputStream(file);
275                 }
276                 ByteArrayOutputStream filteredByteOutputStream = new ByteArrayOutputStream(Math.min(Integer.MAX_VALUE, (int) length[0]));
277                 ReplacingOutputStream outputStream = new ReplacingOutputStream(filteredByteOutputStream);
278                 FileInputStream fileInput = new FileInputStream(file);
279                 try {
280                         outputStream.addReplacement("$[EDITION]", String.valueOf(edition));
281                         outputStream.addReplacement("$[URI]", project.getFinalRequestURI(0));
282                         for (int index = 1; index <= fileOption.getEditionRange(); index++) {
283                                 outputStream.addReplacement("$[URI+" + index + "]", project.getFinalRequestURI(index));
284                                 outputStream.addReplacement("$[EDITION+" + index + "]", String.valueOf(edition + index));
285                         }
286                         StreamCopier.copy(fileInput, outputStream, length[0]);
287                 } finally {
288                         Closer.close(fileInput);
289                         Closer.close(outputStream);
290                         Closer.close(filteredByteOutputStream);
291                 }
292                 byte[] filteredBytes = filteredByteOutputStream.toByteArray();
293                 length[0] = filteredBytes.length;
294                 return new ByteArrayInputStream(filteredBytes);
295         }
296
297         /**
298          * Creates an input stream for a container.
299          *
300          * @param containerFiles
301          *            All container definitions
302          * @param containerName
303          *            The name of the container to create
304          * @param edition
305          *            The current edition
306          * @param containerLength
307          *            An array containing a single long which is used to
308          *            <em>return</em> the final length of the container stream,
309          *            after all replacements
310          * @return The input stream for the container
311          * @throws IOException
312          *             if an I/O error occurs
313          */
314         private InputStream createContainerInputStream(Map<String, List<String>> containerFiles, String containerName, int edition, long[] containerLength) throws IOException {
315                 File tempFile = File.createTempFile("jsite", ".zip", (tempDirectory == null) ? null : new File(tempDirectory));
316                 tempFile.deleteOnExit();
317                 FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
318                 ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
319                 try {
320                         for (String filename : containerFiles.get(containerName)) {
321                                 File dataFile = new File(project.getLocalPath(), filename);
322                                 if (dataFile.exists()) {
323                                         ZipEntry zipEntry = new ZipEntry(filename);
324                                         long[] fileLength = new long[1];
325                                         InputStream wrappedInputStream = createFileInputStream(filename, project.getFileOption(filename), edition, fileLength);
326                                         try {
327                                                 zipOutputStream.putNextEntry(zipEntry);
328                                                 StreamCopier.copy(wrappedInputStream, zipOutputStream, fileLength[0]);
329                                         } finally {
330                                                 zipOutputStream.closeEntry();
331                                                 wrappedInputStream.close();
332                                         }
333                                 }
334                         }
335                 } finally {
336                         zipOutputStream.closeEntry();
337                         Closer.close(zipOutputStream);
338                         Closer.close(fileOutputStream);
339                 }
340
341                 containerLength[0] = tempFile.length();
342                 return new FileInputStream(tempFile);
343         }
344
345         /**
346          * Creates a file entry suitable for handing in to
347          * {@link ClientPutComplexDir#addFileEntry(FileEntry)}.
348          *
349          * @param filename
350          *            The name of the file to insert
351          * @param edition
352          *            The current edition
353          * @param containerFiles
354          *            The container definitions
355          * @return A file entry for the given file
356          */
357         private FileEntry createFileEntry(String filename, int edition, Map<String, List<String>> containerFiles) {
358                 FileEntry fileEntry = null;
359                 FileOption fileOption = project.getFileOption(filename);
360                 if (filename.startsWith("/container/:")) {
361                         String containerName = filename.substring("/container/:".length());
362                         try {
363                                 long[] containerLength = new long[1];
364                                 InputStream containerInputStream = createContainerInputStream(containerFiles, containerName, edition, containerLength);
365                                 fileEntry = new DirectFileEntry(containerName + ".zip", "application/zip", containerInputStream, containerLength[0]);
366                         } catch (IOException ioe1) {
367                                 /* ignore, null is returned. */
368                         }
369                 } else {
370                         if (fileOption.isInsert()) {
371                                 try {
372                                         long[] fileLength = new long[1];
373                                         InputStream fileEntryInputStream = createFileInputStream(filename, fileOption, edition, fileLength);
374                                         fileEntry = new DirectFileEntry(filename, project.getFileOption(filename).getMimeType(), fileEntryInputStream, fileLength[0]);
375                                 } catch (IOException ioe1) {
376                                         /* ignore, null is returned. */
377                                 }
378                         } else {
379                                 if (fileOption.isInsertRedirect()) {
380                                         fileEntry = new RedirectFileEntry(filename, fileOption.getMimeType(), fileOption.getCustomKey());
381                                 }
382                         }
383                 }
384                 return fileEntry;
385         }
386
387         /**
388          * Creates container definitions.
389          *
390          * @param files
391          *            The list of all files
392          * @param containers
393          *            The list of all containers
394          * @param containerFiles
395          *            Empty map that will be filled with container definitions
396          */
397         private void createContainers(List<String> files, List<String> containers, Map<String, List<String>> containerFiles) {
398                 for (String filename : new ArrayList<String>(files)) {
399                         FileOption fileOption = project.getFileOption(filename);
400                         String containerName = fileOption.getContainer();
401                         if (!containerName.equals("")) {
402                                 if (!containers.contains(containerName)) {
403                                         containers.add(containerName);
404                                         containerFiles.put(containerName, new ArrayList<String>());
405                                         /* hmm. looks like a hack to me. */
406                                         files.add("/container/:" + containerName);
407                                 }
408                                 containerFiles.get(containerName).add(filename);
409                                 files.remove(filename);
410                         }
411                 }
412         }
413
414         /**
415          * Validates the given project. The project will be checked for any invalid
416          * conditions, such as invalid insert or request keys, missing path names,
417          * missing default file, and so on.
418          *
419          * @param project
420          *            The project to check
421          * @return The encountered warnings and errors
422          */
423         public static CheckReport validateProject(Project project) {
424                 CheckReport checkReport = new CheckReport();
425                 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
426                         checkReport.addIssue("error.no-local-path", true);
427                 }
428                 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
429                         checkReport.addIssue("error.no-path", true);
430                 }
431                 if ((project.getIndexFile() == null) || (project.getIndexFile().length() == 0)) {
432                         checkReport.addIssue("warning.empty-index", false);
433                 } else {
434                         File indexFile = new File(project.getLocalPath(), project.getIndexFile());
435                         if (!indexFile.exists()) {
436                                 checkReport.addIssue("error.index-missing", true);
437                         }
438                 }
439                 String indexFile = project.getIndexFile();
440                 boolean hasIndexFile = (indexFile != null) && (indexFile.length() > 0);
441                 if (hasIndexFile && !project.getFileOption(indexFile).getContainer().equals("")) {
442                         checkReport.addIssue("warning.container-index", false);
443                 }
444                 List<String> allowedIndexContentTypes = Arrays.asList("text/html", "application/xhtml+xml");
445                 if (hasIndexFile && !allowedIndexContentTypes.contains(project.getFileOption(indexFile).getMimeType())) {
446                         checkReport.addIssue("warning.index-not-html", false);
447                 }
448                 Map<String, FileOption> fileOptions = project.getFileOptions();
449                 Set<Entry<String, FileOption>> fileOptionEntries = fileOptions.entrySet();
450                 boolean insert = fileOptionEntries.isEmpty();
451                 for (Entry<String, FileOption> fileOptionEntry : fileOptionEntries) {
452                         String fileName = fileOptionEntry.getKey();
453                         FileOption fileOption = fileOptionEntry.getValue();
454                         insert |= fileOption.isInsert() || fileOption.isInsertRedirect();
455                         if (fileName.equals(project.getIndexFile()) && !fileOption.isInsert() && !fileOption.isInsertRedirect()) {
456                                 checkReport.addIssue("error.index-not-inserted", true);
457                         }
458                         if (!fileOption.isInsert() && fileOption.isInsertRedirect() && ((fileOption.getCustomKey().length() == 0) || "CHK@".equals(fileOption.getCustomKey()))) {
459                                 checkReport.addIssue("error.no-custom-key", true, fileName);
460                         }
461                 }
462                 if (!insert) {
463                         checkReport.addIssue("error.no-files-to-insert", true);
464                 }
465                 Set<String> fileNames = new HashSet<String>();
466                 for (Entry<String, FileOption> fileOptionEntry : fileOptionEntries) {
467                         FileOption fileOption = fileOptionEntry.getValue();
468                         if (!fileOption.isInsert() && !fileOption.isInsertRedirect()) {
469                                 logger.log(Level.FINEST, "Ignoring {0}.", fileOptionEntry.getKey());
470                                 continue;
471                         }
472                         String fileName = fileOptionEntry.getKey();
473                         if (fileOption.hasChangedName()) {
474                                 fileName = fileOption.getChangedName();
475                         }
476                         logger.log(Level.FINEST, "Adding “{0}” for {1}.", new Object[] { fileName, fileOptionEntry.getKey() });
477                         if (!fileNames.add(fileName)) {
478                                 checkReport.addIssue("error.duplicate-file", true, fileName);
479                         }
480                 }
481                 return checkReport;
482         }
483
484         /**
485          * {@inheritDoc}
486          */
487         public void run() {
488                 fireProjectInsertStarted();
489                 List<String> files = fileScanner.getFiles();
490
491                 /* create connection to node */
492                 synchronized (lockObject) {
493                         connection = freenetInterface.getConnection("project-insert-" + random + counter++);
494                 }
495                 connection.setTempDirectory(tempDirectory);
496                 boolean connected = false;
497                 Throwable cause = null;
498                 try {
499                         connected = connection.connect();
500                 } catch (IOException e1) {
501                         cause = e1;
502                 }
503
504                 if (!connected || cancelled) {
505                         fireProjectInsertFinished(false, cancelled ? new AbortedException() : cause);
506                         return;
507                 }
508
509                 Client client = new Client(connection);
510
511                 /* create containers */
512                 final List<String> containers = new ArrayList<String>();
513                 final Map<String, List<String>> containerFiles = new HashMap<String, List<String>>();
514                 createContainers(files, containers, containerFiles);
515
516                 /* collect files */
517                 int edition = project.getEdition();
518                 String dirURI = "USK@" + project.getInsertURI() + "/" + project.getPath() + "/" + edition + "/";
519                 ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI, tempDirectory);
520                 if ((project.getIndexFile() != null) && (project.getIndexFile().length() > 0)) {
521                         putDir.setDefaultName(project.getIndexFile());
522                 }
523                 putDir.setVerbosity(Verbosity.ALL);
524                 putDir.setMaxRetries(-1);
525                 putDir.setEarlyEncode(false);
526                 for (String filename : files) {
527                         FileEntry fileEntry = createFileEntry(filename, edition, containerFiles);
528                         if (fileEntry != null) {
529                                 try {
530                                         putDir.addFileEntry(fileEntry);
531                                 } catch (IOException ioe1) {
532                                         fireProjectInsertFinished(false, ioe1);
533                                         return;
534                                 }
535                         }
536                 }
537
538                 /* start request */
539                 try {
540                         client.execute(putDir, progressListener);
541                         fireProjectUploadFinished();
542                 } catch (IOException ioe1) {
543                         fireProjectInsertFinished(false, ioe1);
544                         return;
545                 }
546
547                 /* parse progress and success messages */
548                 String finalURI = null;
549                 boolean success = false;
550                 boolean finished = false;
551                 boolean disconnected = false;
552                 while (!finished && !cancelled) {
553                         Message message = client.readMessage();
554                         finished = (message == null) || (disconnected = client.isDisconnected());
555                         logger.log(Level.FINE, "Received message: " + message);
556                         if (!finished) {
557                                 @SuppressWarnings("null")
558                                 String messageName = message.getName();
559                                 if ("URIGenerated".equals(messageName)) {
560                                         finalURI = message.get("URI");
561                                         fireProjectURIGenerated(finalURI);
562                                 }
563                                 if ("SimpleProgress".equals(messageName)) {
564                                         int total = Integer.parseInt(message.get("Total"));
565                                         int succeeded = Integer.parseInt(message.get("Succeeded"));
566                                         int fatal = Integer.parseInt(message.get("FatallyFailed"));
567                                         int failed = Integer.parseInt(message.get("Failed"));
568                                         boolean finalized = Boolean.parseBoolean(message.get("FinalizedTotal"));
569                                         fireProjectInsertProgress(succeeded, failed, fatal, total, finalized);
570                                 }
571                                 success = "PutSuccessful".equals(messageName);
572                                 finished = success || "PutFailed".equals(messageName) || messageName.endsWith("Error");
573                         }
574                 }
575
576                 /* post-insert work */
577                 if (success) {
578                         @SuppressWarnings("null")
579                         String editionPart = finalURI.substring(finalURI.lastIndexOf('/') + 1);
580                         int newEdition = Integer.parseInt(editionPart);
581                         project.setEdition(newEdition);
582                         project.setLastInsertionTime(System.currentTimeMillis());
583                 }
584                 fireProjectInsertFinished(success, cancelled ? new AbortedException() : (disconnected ? new IOException("Connection terminated") : null));
585         }
586
587         //
588         // INTERFACE FileScannerListener
589         //
590
591         /**
592          * {@inheritDoc}
593          */
594         public void fileScannerFinished(FileScanner fileScanner) {
595                 if (!fileScanner.isError()) {
596                         new Thread(this).start();
597                 } else {
598                         fireProjectInsertFinished(false, null);
599                 }
600                 fileScanner.removeFileScannerListener(this);
601         }
602
603         /**
604          * Container class that collects all warnings and errors that occured during
605          * {@link ProjectInserter#validateProject(Project) project validation}.
606          *
607          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
608          */
609         public static class CheckReport implements Iterable<Issue> {
610
611                 /** The issures that occured. */
612                 private final List<Issue> issues = new ArrayList<Issue>();
613
614                 /**
615                  * Adds an issue.
616                  *
617                  * @param issue
618                  *            The issue to add
619                  */
620                 public void addIssue(Issue issue) {
621                         issues.add(issue);
622                 }
623
624                 /**
625                  * Creates an {@link Issue} from the given error key and fatality flag
626                  * and {@link #addIssue(Issue) adds} it.
627                  *
628                  * @param errorKey
629                  *            The error key
630                  * @param fatal
631                  *            {@code true} if the error is fatal, {@code false} if only
632                  *            a warning should be generated
633                  * @param parameters
634                  *            Any additional parameters
635                  */
636                 public void addIssue(String errorKey, boolean fatal, String... parameters) {
637                         addIssue(new Issue(errorKey, fatal, parameters));
638                 }
639
640                 /**
641                  * {@inheritDoc}
642                  */
643                 public Iterator<Issue> iterator() {
644                         return issues.iterator();
645                 }
646
647                 /**
648                  * Returns whether this check report does not contain any errors.
649                  *
650                  * @return {@code true} if this check report does not contain any
651                  *         errors, {@code false} if this check report does contain
652                  *         errors
653                  */
654                 public boolean isEmpty() {
655                         return issues.isEmpty();
656                 }
657
658                 /**
659                  * Returns the number of issues in this check report.
660                  *
661                  * @return The number of issues
662                  */
663                 public int size() {
664                         return issues.size();
665                 }
666
667         }
668
669         /**
670          * Container class for a single issue. An issue contains an error key
671          * that describes the error, and a fatality flag that determines whether
672          * the insert has to be aborted (if the flag is {@code true}) or if it
673          * can still be performed and only a warning should be generated (if the
674          * flag is {@code false}).
675          *
676          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’
677          *         Roden</a>
678          */
679         public static class Issue {
680
681                 /** The error key. */
682                 private final String errorKey;
683
684                 /** The fatality flag. */
685                 private final boolean fatal;
686
687                 /** Additional parameters. */
688                 private String[] parameters;
689
690                 /**
691                  * Creates a new issue.
692                  *
693                  * @param errorKey
694                  *            The error key
695                  * @param fatal
696                  *            The fatality flag
697                  * @param parameters
698                  *            Any additional parameters
699                  */
700                 protected Issue(String errorKey, boolean fatal, String... parameters) {
701                         this.errorKey = errorKey;
702                         this.fatal = fatal;
703                         this.parameters = parameters;
704                 }
705
706                 /**
707                  * Returns the key of the encountered error.
708                  *
709                  * @return The error key
710                  */
711                 public String getErrorKey() {
712                         return errorKey;
713                 }
714
715                 /**
716                  * Returns whether the issue is fatal and the insert has to be
717                  * aborted. Otherwise only a warning should be shown.
718                  *
719                  * @return {@code true} if the insert needs to be aborted, {@code
720                  *         false} otherwise
721                  */
722                 public boolean isFatal() {
723                         return fatal;
724                 }
725
726                 /**
727                  * Returns any additional parameters.
728                  *
729                  * @return The additional parameters
730                  */
731                 public String[] getParameters() {
732                         return parameters;
733                 }
734
735         }
736
737 }