56b99030c8c0552ffe1d6f2b84f58aa05fee0482
[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         public void start(ProgressListener progressListener) {
230                 cancelled = false;
231                 this.progressListener = progressListener;
232                 fileScanner = new FileScanner(project);
233                 fileScanner.addFileScannerListener(this);
234                 new Thread(fileScanner).start();
235         }
236
237         /**
238          * Stops the current insert.
239          */
240         public void stop() {
241                 cancelled = true;
242                 synchronized (lockObject) {
243                         if (connection != null) {
244                                 connection.disconnect();
245                         }
246                 }
247         }
248
249         /**
250          * Creates an input stream that delivers the given file, replacing edition
251          * tokens in the file’s content, if necessary.
252          *
253          * @param filename
254          *            The name of the file
255          * @param fileOption
256          *            The file options
257          * @param edition
258          *            The current edition
259          * @param length
260          *            An array containing a single long which is used to
261          *            <em>return</em> the final length of the file, after all
262          *            replacements
263          * @return The input stream for the file
264          * @throws IOException
265          *             if an I/O error occurs
266          */
267         private InputStream createFileInputStream(String filename, FileOption fileOption, int edition, long[] length) throws IOException {
268                 File file = new File(project.getLocalPath(), filename);
269                 length[0] = file.length();
270                 if (!fileOption.getReplaceEdition()) {
271                         return new FileInputStream(file);
272                 }
273                 ByteArrayOutputStream filteredByteOutputStream = new ByteArrayOutputStream(Math.min(Integer.MAX_VALUE, (int) length[0]));
274                 ReplacingOutputStream outputStream = new ReplacingOutputStream(filteredByteOutputStream);
275                 FileInputStream fileInput = new FileInputStream(file);
276                 try {
277                         outputStream.addReplacement("$[EDITION]", String.valueOf(edition));
278                         outputStream.addReplacement("$[URI]", project.getFinalRequestURI(0));
279                         for (int index = 1; index <= fileOption.getEditionRange(); index++) {
280                                 outputStream.addReplacement("$[URI+" + index + "]", project.getFinalRequestURI(index));
281                                 outputStream.addReplacement("$[EDITION+" + index + "]", String.valueOf(edition + index));
282                         }
283                         StreamCopier.copy(fileInput, outputStream, length[0]);
284                 } finally {
285                         Closer.close(fileInput);
286                         Closer.close(outputStream);
287                         Closer.close(filteredByteOutputStream);
288                 }
289                 byte[] filteredBytes = filteredByteOutputStream.toByteArray();
290                 length[0] = filteredBytes.length;
291                 return new ByteArrayInputStream(filteredBytes);
292         }
293
294         /**
295          * Creates an input stream for a container.
296          *
297          * @param containerFiles
298          *            All container definitions
299          * @param containerName
300          *            The name of the container to create
301          * @param edition
302          *            The current edition
303          * @param containerLength
304          *            An array containing a single long which is used to
305          *            <em>return</em> the final length of the container stream,
306          *            after all replacements
307          * @return The input stream for the container
308          * @throws IOException
309          *             if an I/O error occurs
310          */
311         private InputStream createContainerInputStream(Map<String, List<String>> containerFiles, String containerName, int edition, long[] containerLength) throws IOException {
312                 File tempFile = File.createTempFile("jsite", ".zip", (tempDirectory == null) ? null : new File(tempDirectory));
313                 tempFile.deleteOnExit();
314                 FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
315                 ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
316                 try {
317                         for (String filename : containerFiles.get(containerName)) {
318                                 File dataFile = new File(project.getLocalPath(), filename);
319                                 if (dataFile.exists()) {
320                                         ZipEntry zipEntry = new ZipEntry(filename);
321                                         long[] fileLength = new long[1];
322                                         InputStream wrappedInputStream = createFileInputStream(filename, project.getFileOption(filename), edition, fileLength);
323                                         try {
324                                                 zipOutputStream.putNextEntry(zipEntry);
325                                                 StreamCopier.copy(wrappedInputStream, zipOutputStream, fileLength[0]);
326                                         } finally {
327                                                 zipOutputStream.closeEntry();
328                                                 wrappedInputStream.close();
329                                         }
330                                 }
331                         }
332                 } finally {
333                         zipOutputStream.closeEntry();
334                         Closer.close(zipOutputStream);
335                         Closer.close(fileOutputStream);
336                 }
337
338                 containerLength[0] = tempFile.length();
339                 return new FileInputStream(tempFile);
340         }
341
342         /**
343          * Creates a file entry suitable for handing in to
344          * {@link ClientPutComplexDir#addFileEntry(FileEntry)}.
345          *
346          * @param filename
347          *            The name of the file to insert
348          * @param edition
349          *            The current edition
350          * @param containerFiles
351          *            The container definitions
352          * @return A file entry for the given file
353          */
354         private FileEntry createFileEntry(String filename, int edition, Map<String, List<String>> containerFiles) {
355                 FileEntry fileEntry = null;
356                 FileOption fileOption = project.getFileOption(filename);
357                 if (filename.startsWith("/container/:")) {
358                         String containerName = filename.substring("/container/:".length());
359                         try {
360                                 long[] containerLength = new long[1];
361                                 InputStream containerInputStream = createContainerInputStream(containerFiles, containerName, edition, containerLength);
362                                 fileEntry = new DirectFileEntry(containerName + ".zip", "application/zip", containerInputStream, containerLength[0]);
363                         } catch (IOException ioe1) {
364                                 /* ignore, null is returned. */
365                         }
366                 } else {
367                         if (fileOption.isInsert()) {
368                                 try {
369                                         long[] fileLength = new long[1];
370                                         InputStream fileEntryInputStream = createFileInputStream(filename, fileOption, edition, fileLength);
371                                         fileEntry = new DirectFileEntry(filename, project.getFileOption(filename).getMimeType(), fileEntryInputStream, fileLength[0]);
372                                 } catch (IOException ioe1) {
373                                         /* ignore, null is returned. */
374                                 }
375                         } else {
376                                 if (fileOption.isInsertRedirect()) {
377                                         fileEntry = new RedirectFileEntry(filename, fileOption.getMimeType(), fileOption.getCustomKey());
378                                 }
379                         }
380                 }
381                 return fileEntry;
382         }
383
384         /**
385          * Creates container definitions.
386          *
387          * @param files
388          *            The list of all files
389          * @param containers
390          *            The list of all containers
391          * @param containerFiles
392          *            Empty map that will be filled with container definitions
393          */
394         private void createContainers(List<String> files, List<String> containers, Map<String, List<String>> containerFiles) {
395                 for (String filename : new ArrayList<String>(files)) {
396                         FileOption fileOption = project.getFileOption(filename);
397                         String containerName = fileOption.getContainer();
398                         if (!containerName.equals("")) {
399                                 if (!containers.contains(containerName)) {
400                                         containers.add(containerName);
401                                         containerFiles.put(containerName, new ArrayList<String>());
402                                         /* hmm. looks like a hack to me. */
403                                         files.add("/container/:" + containerName);
404                                 }
405                                 containerFiles.get(containerName).add(filename);
406                                 files.remove(filename);
407                         }
408                 }
409         }
410
411         /**
412          * Validates the given project. The project will be checked for any invalid
413          * conditions, such as invalid insert or request keys, missing path names,
414          * missing default file, and so on.
415          *
416          * @param project
417          *            The project to check
418          * @return The encountered warnings and errors
419          */
420         public static CheckReport validateProject(Project project) {
421                 CheckReport checkReport = new CheckReport();
422                 if ((project.getLocalPath() == null) || (project.getLocalPath().trim().length() == 0)) {
423                         checkReport.addIssue("error.no-local-path", true);
424                 }
425                 if ((project.getPath() == null) || (project.getPath().trim().length() == 0)) {
426                         checkReport.addIssue("error.no-path", true);
427                 }
428                 if ((project.getIndexFile() == null) || (project.getIndexFile().length() == 0)) {
429                         checkReport.addIssue("warning.empty-index", false);
430                 } else {
431                         File indexFile = new File(project.getLocalPath(), project.getIndexFile());
432                         if (!indexFile.exists()) {
433                                 checkReport.addIssue("error.index-missing", true);
434                         }
435                 }
436                 String indexFile = project.getIndexFile();
437                 boolean hasIndexFile = (indexFile != null) && (indexFile.length() > 0);
438                 if (hasIndexFile && !project.getFileOption(indexFile).getContainer().equals("")) {
439                         checkReport.addIssue("warning.container-index", false);
440                 }
441                 List<String> allowedIndexContentTypes = Arrays.asList("text/html", "application/xhtml+xml");
442                 if (hasIndexFile && !allowedIndexContentTypes.contains(project.getFileOption(indexFile).getMimeType())) {
443                         checkReport.addIssue("warning.index-not-html", false);
444                 }
445                 Map<String, FileOption> fileOptions = project.getFileOptions();
446                 Set<Entry<String, FileOption>> fileOptionEntries = fileOptions.entrySet();
447                 boolean insert = fileOptionEntries.isEmpty();
448                 for (Entry<String, FileOption> fileOptionEntry : fileOptionEntries) {
449                         String fileName = fileOptionEntry.getKey();
450                         FileOption fileOption = fileOptionEntry.getValue();
451                         insert |= fileOption.isInsert() || fileOption.isInsertRedirect();
452                         if (fileName.equals(project.getIndexFile()) && !fileOption.isInsert() && !fileOption.isInsertRedirect()) {
453                                 checkReport.addIssue("error.index-not-inserted", true);
454                         }
455                         if (!fileOption.isInsert() && fileOption.isInsertRedirect() && ((fileOption.getCustomKey().length() == 0) || "CHK@".equals(fileOption.getCustomKey()))) {
456                                 checkReport.addIssue("error.no-custom-key", true, fileName);
457                         }
458                 }
459                 if (!insert) {
460                         checkReport.addIssue("error.no-files-to-insert", true);
461                 }
462                 Set<String> fileNames = new HashSet<String>();
463                 for (Entry<String, FileOption> fileOptionEntry : fileOptionEntries) {
464                         FileOption fileOption = fileOptionEntry.getValue();
465                         if (!fileOption.isInsert() && !fileOption.isInsertRedirect()) {
466                                 logger.log(Level.FINEST, "Ignoring {0}.", fileOptionEntry.getKey());
467                                 continue;
468                         }
469                         String fileName = fileOptionEntry.getKey();
470                         if (fileOption.hasChangedName()) {
471                                 fileName = fileOption.getChangedName();
472                         }
473                         logger.log(Level.FINEST, "Adding “{0}” for {1}.", new Object[] { fileName, fileOptionEntry.getKey() });
474                         if (!fileNames.add(fileName)) {
475                                 checkReport.addIssue("error.duplicate-file", true, fileName);
476                         }
477                 }
478                 return checkReport;
479         }
480
481         /**
482          * {@inheritDoc}
483          */
484         public void run() {
485                 fireProjectInsertStarted();
486                 List<String> files = fileScanner.getFiles();
487
488                 /* create connection to node */
489                 synchronized (lockObject) {
490                         connection = freenetInterface.getConnection("project-insert-" + random + counter++);
491                 }
492                 connection.setTempDirectory(tempDirectory);
493                 boolean connected = false;
494                 Throwable cause = null;
495                 try {
496                         connected = connection.connect();
497                 } catch (IOException e1) {
498                         cause = e1;
499                 }
500
501                 if (!connected || cancelled) {
502                         fireProjectInsertFinished(false, cancelled ? new AbortedException() : cause);
503                         return;
504                 }
505
506                 Client client = new Client(connection);
507
508                 /* create containers */
509                 final List<String> containers = new ArrayList<String>();
510                 final Map<String, List<String>> containerFiles = new HashMap<String, List<String>>();
511                 createContainers(files, containers, containerFiles);
512
513                 /* collect files */
514                 int edition = project.getEdition();
515                 String dirURI = "USK@" + project.getInsertURI() + "/" + project.getPath() + "/" + edition + "/";
516                 ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI, tempDirectory);
517                 if ((project.getIndexFile() != null) && (project.getIndexFile().length() > 0)) {
518                         putDir.setDefaultName(project.getIndexFile());
519                 }
520                 putDir.setVerbosity(Verbosity.ALL);
521                 putDir.setMaxRetries(-1);
522                 putDir.setEarlyEncode(false);
523                 for (String filename : files) {
524                         FileEntry fileEntry = createFileEntry(filename, edition, containerFiles);
525                         if (fileEntry != null) {
526                                 try {
527                                         putDir.addFileEntry(fileEntry);
528                                 } catch (IOException ioe1) {
529                                         fireProjectInsertFinished(false, ioe1);
530                                         return;
531                                 }
532                         }
533                 }
534
535                 /* start request */
536                 try {
537                         client.execute(putDir, progressListener);
538                         fireProjectUploadFinished();
539                 } catch (IOException ioe1) {
540                         fireProjectInsertFinished(false, ioe1);
541                         return;
542                 }
543
544                 /* parse progress and success messages */
545                 String finalURI = null;
546                 boolean success = false;
547                 boolean finished = false;
548                 boolean disconnected = false;
549                 while (!finished && !cancelled) {
550                         Message message = client.readMessage();
551                         finished = (message == null) || (disconnected = client.isDisconnected());
552                         logger.log(Level.FINE, "Received message: " + message);
553                         if (!finished) {
554                                 @SuppressWarnings("null")
555                                 String messageName = message.getName();
556                                 if ("URIGenerated".equals(messageName)) {
557                                         finalURI = message.get("URI");
558                                         fireProjectURIGenerated(finalURI);
559                                 }
560                                 if ("SimpleProgress".equals(messageName)) {
561                                         int total = Integer.parseInt(message.get("Total"));
562                                         int succeeded = Integer.parseInt(message.get("Succeeded"));
563                                         int fatal = Integer.parseInt(message.get("FatallyFailed"));
564                                         int failed = Integer.parseInt(message.get("Failed"));
565                                         boolean finalized = Boolean.parseBoolean(message.get("FinalizedTotal"));
566                                         fireProjectInsertProgress(succeeded, failed, fatal, total, finalized);
567                                 }
568                                 success = "PutSuccessful".equals(messageName);
569                                 finished = success || "PutFailed".equals(messageName) || messageName.endsWith("Error");
570                         }
571                 }
572
573                 /* post-insert work */
574                 if (success) {
575                         @SuppressWarnings("null")
576                         String editionPart = finalURI.substring(finalURI.lastIndexOf('/') + 1);
577                         int newEdition = Integer.parseInt(editionPart);
578                         project.setEdition(newEdition);
579                         project.setLastInsertionTime(System.currentTimeMillis());
580                 }
581                 fireProjectInsertFinished(success, cancelled ? new AbortedException() : (disconnected ? new IOException("Connection terminated") : null));
582         }
583
584         //
585         // INTERFACE FileScannerListener
586         //
587
588         /**
589          * {@inheritDoc}
590          */
591         public void fileScannerFinished(FileScanner fileScanner) {
592                 if (!fileScanner.isError()) {
593                         new Thread(this).start();
594                 } else {
595                         fireProjectInsertFinished(false, null);
596                 }
597                 fileScanner.removeFileScannerListener(this);
598         }
599
600         /**
601          * Container class that collects all warnings and errors that occured during
602          * {@link ProjectInserter#validateProject(Project) project validation}.
603          *
604          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
605          */
606         public static class CheckReport implements Iterable<Issue> {
607
608                 /** The issures that occured. */
609                 private final List<Issue> issues = new ArrayList<Issue>();
610
611                 /**
612                  * Adds an issue.
613                  *
614                  * @param issue
615                  *            The issue to add
616                  */
617                 public void addIssue(Issue issue) {
618                         issues.add(issue);
619                 }
620
621                 /**
622                  * Creates an {@link Issue} from the given error key and fatality flag
623                  * and {@link #addIssue(Issue) adds} it.
624                  *
625                  * @param errorKey
626                  *            The error key
627                  * @param fatal
628                  *            {@code true} if the error is fatal, {@code false} if only
629                  *            a warning should be generated
630                  * @param parameters
631                  *            Any additional parameters
632                  */
633                 public void addIssue(String errorKey, boolean fatal, String... parameters) {
634                         addIssue(new Issue(errorKey, fatal, parameters));
635                 }
636
637                 /**
638                  * {@inheritDoc}
639                  */
640                 public Iterator<Issue> iterator() {
641                         return issues.iterator();
642                 }
643
644                 /**
645                  * Returns whether this check report does not contain any errors.
646                  *
647                  * @return {@code true} if this check report does not contain any
648                  *         errors, {@code false} if this check report does contain
649                  *         errors
650                  */
651                 public boolean isEmpty() {
652                         return issues.isEmpty();
653                 }
654
655                 /**
656                  * Returns the number of issues in this check report.
657                  *
658                  * @return The number of issues
659                  */
660                 public int size() {
661                         return issues.size();
662                 }
663
664         }
665
666         /**
667          * Container class for a single issue. An issue contains an error key
668          * that describes the error, and a fatality flag that determines whether
669          * the insert has to be aborted (if the flag is {@code true}) or if it
670          * can still be performed and only a warning should be generated (if the
671          * flag is {@code false}).
672          *
673          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’
674          *         Roden</a>
675          */
676         public static class Issue {
677
678                 /** The error key. */
679                 private final String errorKey;
680
681                 /** The fatality flag. */
682                 private final boolean fatal;
683
684                 /** Additional parameters. */
685                 private String[] parameters;
686
687                 /**
688                  * Creates a new issue.
689                  *
690                  * @param errorKey
691                  *            The error key
692                  * @param fatal
693                  *            The fatality flag
694                  * @param parameters
695                  *            Any additional parameters
696                  */
697                 protected Issue(String errorKey, boolean fatal, String... parameters) {
698                         this.errorKey = errorKey;
699                         this.fatal = fatal;
700                         this.parameters = parameters;
701                 }
702
703                 /**
704                  * Returns the key of the encountered error.
705                  *
706                  * @return The error key
707                  */
708                 public String getErrorKey() {
709                         return errorKey;
710                 }
711
712                 /**
713                  * Returns whether the issue is fatal and the insert has to be
714                  * aborted. Otherwise only a warning should be shown.
715                  *
716                  * @return {@code true} if the insert needs to be aborted, {@code
717                  *         false} otherwise
718                  */
719                 public boolean isFatal() {
720                         return fatal;
721                 }
722
723                 /**
724                  * Returns any additional parameters.
725                  *
726                  * @return The additional parameters
727                  */
728                 public String[] getParameters() {
729                         return parameters;
730                 }
731
732         }
733
734 }