Ignore:
Timestamp:
2018-02-24T18:58:28+01:00 (9 months ago)
Author:
Don-vip
Message:

fix #8039, fix #10456: final fixes for the read-only/locked layers:

  • rename "read-only" to "locked" (in XML and Java classes/interfaces)
  • add a new download policy (true/never) to allow private layers forbidding only to download data, but allowing everything else

This leads to:

  • normal layers: download allowed, modifications allowed, upload allowed
  • private layers: download allowed or not (download=true/never), modifications allowed, upload allowed or not (upload=true/discouraged/never)
  • locked layers: nothing allowed, the data cannot be modified in any way
File:
1 edited

Legend:

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

    r13434 r13453  
    1212import java.util.List;
    1313import java.util.Objects;
     14import java.util.function.Consumer;
    1415import java.util.regex.Matcher;
    1516import java.util.regex.Pattern;
     
    2728import org.openstreetmap.josm.data.osm.Changeset;
    2829import org.openstreetmap.josm.data.osm.DataSet;
     30import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    2931import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    3032import org.openstreetmap.josm.data.osm.Node;
     
    139141        }
    140142        ds.setVersion(v);
    141         String upload = parser.getAttributeValue(null, "upload");
    142         if (upload != null) {
    143             try {
    144                 ds.setUploadPolicy(UploadPolicy.of(upload));
    145             } catch (IllegalArgumentException e) {
    146                 throwException(MessageFormat.format("Illegal value for attribute ''upload''. Got ''{0}''.", upload), e);
    147             }
    148         }
    149         if ("true".equalsIgnoreCase(parser.getAttributeValue(null, "read-only"))) {
    150             ds.setReadOnly();
     143        parsePolicy("download", policy -> ds.setDownloadPolicy(DownloadPolicy.of(policy)));
     144        parsePolicy("upload", policy -> ds.setUploadPolicy(UploadPolicy.of(policy)));
     145        if ("true".equalsIgnoreCase(parser.getAttributeValue(null, "locked"))) {
     146            ds.lock();
    151147        }
    152148        String generator = parser.getAttributeValue(null, "generator");
     
    185181            } else if (event == XMLStreamConstants.END_ELEMENT) {
    186182                return;
     183            }
     184        }
     185    }
     186
     187    private void parsePolicy(String key, Consumer<String> consumer) throws XMLStreamException {
     188        String policy = parser.getAttributeValue(null, key);
     189        if (policy != null) {
     190            try {
     191                consumer.accept(policy);
     192            } catch (IllegalArgumentException e) {
     193                throwException(MessageFormat.format("Illegal value for attribute ''{0}''. Got ''{1}''.", key, policy), e);
    187194            }
    188195        }
     
    621628            progressMonitor.worked(1);
    622629
    623             boolean readOnly = getDataSet().isReadOnly();
     630            boolean readOnly = getDataSet().isLocked();
    624631
    625632            progressMonitor.indeterminateSubTask(tr("Preparing data set..."));
    626633            if (readOnly) {
    627                 getDataSet().unsetReadOnly();
     634                getDataSet().unlock();
    628635            }
    629636            prepareDataSet();
    630637            if (readOnly) {
    631                 getDataSet().setReadOnly();
     638                getDataSet().lock();
    632639            }
    633640            progressMonitor.worked(1);
     
    641648            }
    642649            // Make sure postprocessors did not change the read-only state
    643             if (readOnly && !getDataSet().isReadOnly()) {
    644                 getDataSet().setReadOnly();
     650            if (readOnly && !getDataSet().isLocked()) {
     651                getDataSet().lock();
    645652            }
    646653            return getDataSet();
Note: See TracChangeset for help on using the changeset viewer.