Changeset 13485 in josm


Ignore:
Timestamp:
2018-03-03T16:20:56+01:00 (9 months ago)
Author:
Don-vip
Message:

see #8039, see #10456 - keep layer download/upload/locked flags when saving to .osm file

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r13173 r13485  
    1818import org.openstreetmap.josm.data.osm.Changeset;
    1919import org.openstreetmap.josm.data.osm.DataSet;
     20import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    2021import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    2122import org.openstreetmap.josm.data.osm.INode;
     
    9091    }
    9192
     93    /**
     94     * Writes OSM header with normal download and upload policies.
     95     */
    9296    public void header() {
    93         header(UploadPolicy.NORMAL);
    94     }
    95 
     97        header(DownloadPolicy.NORMAL, UploadPolicy.NORMAL);
     98    }
     99
     100    /**
     101     * Writes OSM header with normal download policy and given upload policy.
     102     * @deprecated Use {@link #header(DownloadPolicy, UploadPolicy)} instead
     103     * @param upload upload policy
     104     */
     105    @Deprecated
    96106    public void header(UploadPolicy upload) {
     107        header(DownloadPolicy.NORMAL, upload);
     108    }
     109
     110    /**
     111     * Writes OSM header with given download upload policies.
     112     * @param download download policy
     113     * @param upload upload policy
     114     * @since 13485
     115     */
     116    public void header(DownloadPolicy download, UploadPolicy upload) {
     117        header(download, upload, false);
     118    }
     119
     120    private void header(DownloadPolicy download, UploadPolicy upload, boolean locked) {
    97121        out.println("<?xml version='1.0' encoding='UTF-8'?>");
    98122        out.print("<osm version='");
    99123        out.print(version);
     124        if (download != null && download != DownloadPolicy.NORMAL) {
     125            out.print("' download='");
     126            out.print(download.getXmlFlag());
     127        }
    100128        if (upload != null && upload != UploadPolicy.NORMAL) {
    101129            out.print("' upload='");
    102130            out.print(upload.getXmlFlag());
    103131        }
     132        if (locked) {
     133            out.print("' locked=true");
     134        }
    104135        out.println("' generator='JOSM'>");
    105136    }
    106137
     138    /**
     139     * Writes OSM footer.
     140     */
    107141    public void footer() {
    108142        out.println("</osm>");
     
    135169     */
    136170    public void write(DataSet data) {
    137         header(data.getUploadPolicy());
     171        header(data.getDownloadPolicy(), data.getUploadPolicy(), data.isLocked());
    138172        writeDataSources(data);
    139173        writeContent(data);
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r13204 r13485  
    2424import org.openstreetmap.josm.data.coor.LatLon;
    2525import org.openstreetmap.josm.data.osm.DataSet;
     26import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
     27import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    2628import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2729import org.openstreetmap.josm.data.osm.Relation;
     
    158160             OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion())
    159161            ) {
    160             w.header(DataSet.UploadPolicy.DISCOURAGED);
     162            w.header(DownloadPolicy.NORMAL, UploadPolicy.DISCOURAGED);
    161163            w.writeContent(ds);
    162164            w.footer();
  • trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java

    r10717 r13485  
    33
    44import static org.junit.Assert.assertArrayEquals;
     5import static org.junit.Assert.assertEquals;
    56
     7import java.io.ByteArrayOutputStream;
     8import java.io.IOException;
     9import java.io.PrintWriter;
    610import java.util.ArrayList;
    711import java.util.Arrays;
     
    1014
    1115import org.junit.Test;
     16import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
     17import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    1218import org.openstreetmap.josm.data.osm.NodeData;
    1319
     
    3743        }, longIds);
    3844    }
     45
     46    /**
     47     * Unit test of {@link OsmWriter#header(DownloadPolicy, UploadPolicy)}.
     48     * @throws IOException if an I/O error occurs
     49     */
     50    @Test
     51    public void testHeader() throws IOException {
     52        doTestHeader(null, null,
     53                "<osm version='0.6' generator='JOSM'>");
     54        doTestHeader(DownloadPolicy.NORMAL, UploadPolicy.NORMAL,
     55                "<osm version='0.6' generator='JOSM'>");
     56        doTestHeader(DownloadPolicy.BLOCKED, UploadPolicy.BLOCKED,
     57                "<osm version='0.6' download='never' upload='never' generator='JOSM'>");
     58    }
     59
     60    private static void doTestHeader(DownloadPolicy download, UploadPolicy upload, String expected) throws IOException {
     61        ByteArrayOutputStream baos = new ByteArrayOutputStream();
     62        try (PrintWriter out = new PrintWriter(baos);
     63             OsmWriter writer = OsmWriterFactory.createOsmWriter(out, true, OsmWriter.DEFAULT_API_VERSION)) {
     64            writer.header(download, upload);
     65        }
     66        assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + expected,
     67                baos.toString("UTF-8").replaceAll("\r", "").replaceAll("\n", ""));
     68    }
    3969}
Note: See TracChangeset for help on using the changeset viewer.