Ticket #16497: 16497.patch

File 16497.patch, 3.1 KB (added by simon04, 5 months ago)
  • src/org/openstreetmap/josm/io/session/GenericSessionExporter.java

    diff --git a/src/org/openstreetmap/josm/io/session/GenericSessionExporter.java b/src/org/openstreetmap/josm/io/session/GenericSessionExporter.java
    index 6d1e3eb0d..ab8592c7e 100644
    a b  
    1212import java.io.File;
    1313import java.io.IOException;
    1414import java.io.OutputStream;
    15 import java.net.MalformedURLException;
     15import java.nio.file.Path;
    1616
    1717import javax.swing.AbstractAction;
    1818import javax.swing.ButtonGroup;
    public Element export(ExportSupport support) throws IOException { 
    191191            file.appendChild(support.createTextNode(zipPath));
    192192            addDataFile(support.getOutputStreamZip(zipPath));
    193193        } else {
    194             try {
    195                 File f = layer.getAssociatedFile();
    196                 if (f != null) {
    197                     file.appendChild(support.createTextNode(f.toURI().toURL().toString()));
     194            File f = layer.getAssociatedFile();
     195            if (f != null) {
     196                final Path sessionDirectory = support.getOutput().getParent();
     197                final String fileString;
     198                if (f.toPath().startsWith(sessionDirectory)) {
     199                    fileString = sessionDirectory.relativize(f.toPath()).toString();
     200                } else {
     201                    fileString = f.toPath().toString();
    198202                }
    199             } catch (MalformedURLException e) {
    200                 throw new IOException(e);
     203                file.appendChild(support.createTextNode(fileString));
    201204            }
    202205        }
    203206        return layerEl;
  • src/org/openstreetmap/josm/io/session/SessionWriter.java

    diff --git a/src/org/openstreetmap/josm/io/session/SessionWriter.java b/src/org/openstreetmap/josm/io/session/SessionWriter.java
    index c116c219e..efccebab3 100644
    a b  
    88import java.io.OutputStreamWriter;
    99import java.nio.charset.StandardCharsets;
    1010import java.nio.file.Files;
     11import java.nio.file.Path;
    1112import java.util.ArrayList;
    1213import java.util.Collection;
    1314import java.util.HashMap;
     
    6364    private final MultiMap<Layer, Layer> dependencies;
    6465    private final boolean zip;
    6566
     67    private Path output;
    6668    private ZipOutputStream zipOut;
    6769
    6870    static {
    public OutputStream getOutputStreamZip(String zipPath) throws IOException { 
    195197        public boolean isZip() {
    196198            return zip;
    197199        }
     200
     201        /**
     202         * Returns the path of the output file.
     203         *
     204         * @return the path of the output file
     205         */
     206        public Path getOutput() {
     207            return output;
     208        }
    198209    }
    199210
    200211    /**
    public void writeJos(Document doc, OutputStream out) throws IOException { 
    328339     * @throws IOException if any I/O error occurs
    329340     */
    330341    public void write(File f) throws IOException {
    331         try (OutputStream out = Files.newOutputStream(f.toPath())) {
     342        output = f.toPath();
     343        try (OutputStream out = Files.newOutputStream(output)) {
    332344            write(out);
    333345        }
    334346    }