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