1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io.importexport;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.FileOutputStream;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.io.OutputStream;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
12 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
13 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
14 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.ValidatorLayer;
|
---|
16 | import org.openstreetmap.josm.io.ValidatorErrorWriter;
|
---|
17 | import org.openstreetmap.josm.tools.Logging;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Exporter to write validator errors to an XML file.
|
---|
21 | * @since 12667
|
---|
22 | */
|
---|
23 | public class ValidatorErrorExporter extends FileExporter {
|
---|
24 |
|
---|
25 | /** File extension filter for .xml files */
|
---|
26 | public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
|
---|
27 | "xml", "xml", tr("Validation Error Files") + " (*.xml)");
|
---|
28 |
|
---|
29 | /** Create a new validator error exporter with the default .xml file filter */
|
---|
30 | public ValidatorErrorExporter() {
|
---|
31 | super(FILE_FILTER);
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public boolean acceptFile(File pathname, Layer layer) {
|
---|
36 | if (!(layer instanceof ValidatorLayer))
|
---|
37 | return false;
|
---|
38 | return super.acceptFile(pathname, layer);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public void exportData(File file, Layer layer) throws IOException {
|
---|
43 | OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
|
---|
44 | if (layer instanceof ValidatorLayer && editLayer != null) {
|
---|
45 | Logging.info("exporting validation errors to file: " + file);
|
---|
46 | try (OutputStream os = new FileOutputStream(file);
|
---|
47 | ValidatorErrorWriter writer = new ValidatorErrorWriter(os)) {
|
---|
48 | writer.write(editLayer.validationErrors);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|