Ticket #12731: 12731-upload-block.patch
File 12731-upload-block.patch, 10.3 KB (added by , 8 years ago) |
---|
-
src/org/openstreetmap/josm/actions/ToggleUploadDiscouragedLayerAction.java
31 31 public ToggleUploadDiscouragedLayerAction(OsmDataLayer layer) { 32 32 super(tr("Discourage upload"), ImageProvider.get("no_upload")); 33 33 this.layer = layer; 34 setEnabled(layer.isUploadable()); 34 35 } 35 36 36 37 @Override … … 42 43 @Override 43 44 public Component createMenuComponent() { 44 45 JCheckBoxMenuItem item = new JCheckBoxMenuItem(this); 45 item.setSelected(layer.isUploadDiscouraged() );46 item.setSelected(layer.isUploadDiscouraged() || !layer.isUploadable()); 46 47 return item; 47 48 } 48 49 -
src/org/openstreetmap/josm/actions/UploadAction.java
140 140 */ 141 141 @Override 142 142 protected void updateEnabledState() { 143 setEnabled(getLayerManager().getEditLayer() != null); 143 OsmDataLayer editLayer = getLayerManager().getEditLayer(); 144 setEnabled(editLayer != null && editLayer.isUploadable()); 144 145 } 145 146 146 147 public static boolean checkPreUploadConditions(AbstractModifiableLayer layer) { -
src/org/openstreetmap/josm/data/osm/DataSet.java
98 98 */ 99 99 public final class DataSet implements Data, ProjectionChangeListener { 100 100 101 public enum UploadPolicy { 102 NORMAL("true"), 103 DISCOURAGED("false"), 104 BLOCKED("never"); 105 106 String xml_flag; 107 108 private UploadPolicy(String xml_flag) { 109 this.xml_flag = xml_flag; 110 } 111 112 public String getXmlFlag() { 113 return xml_flag; 114 } 115 }; 116 101 117 /** 102 118 * Maximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent) 103 119 */ … … 123 139 124 140 private int highlightUpdateCount; 125 141 126 private boolean uploadDiscouraged;142 private UploadPolicy uploadPolicy; 127 143 128 144 private final ReadWriteLock lock = new ReentrantReadWriteLock(); 129 145 private final Object selectionLock = new Object(); … … 299 315 } 300 316 301 317 /** 302 * Determines if upload is being discouraged (i.e. this dataset contains private data which should not be uploaded) 318 * Determines if upload is being discouraged. 319 * (i.e. this dataset contains private data which should not be uploaded) 303 320 * @return {@code true} if upload is being discouraged, {@code false} otherwise 304 321 * @see #setUploadDiscouraged 305 322 */ 323 @Deprecated 306 324 public boolean isUploadDiscouraged() { 307 return upload Discouraged;325 return uploadPolicy == UploadPolicy.DISCOURAGED || uploadPolicy == UploadPolicy.BLOCKED; 308 326 } 309 327 310 328 /** … … 312 330 * @param uploadDiscouraged {@code true} if this dataset contains private data which should not be uploaded 313 331 * @see #isUploadDiscouraged 314 332 */ 333 @Deprecated 315 334 public void setUploadDiscouraged(boolean uploadDiscouraged) { 316 this.uploadDiscouraged = uploadDiscouraged; 335 if (uploadPolicy != UploadPolicy.BLOCKED) { 336 this.uploadPolicy = uploadDiscouraged ? UploadPolicy.DISCOURAGED : UploadPolicy.NORMAL; 337 } 317 338 } 318 339 340 public UploadPolicy getUploadPolicy() { 341 return this.uploadPolicy; 342 } 343 344 public void setUploadPolicy(UploadPolicy uploadPolicy) { 345 this.uploadPolicy = uploadPolicy; 346 } 347 319 348 /** 320 349 * Holding bin for changeset tag information, to be applied when or if this is ever uploaded. 321 350 */ -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
62 62 import org.openstreetmap.josm.data.gpx.WayPoint; 63 63 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException; 64 64 import org.openstreetmap.josm.data.osm.DataSet; 65 import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy; 65 66 import org.openstreetmap.josm.data.osm.DataSetMerger; 66 67 import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 67 68 import org.openstreetmap.josm.data.osm.IPrimitive; … … 386 387 @Override 387 388 public Icon getIcon() { 388 389 ImageProvider base = getBaseIconProvider().setMaxSize(ImageSizes.LAYER); 389 if (isUploadDiscouraged() ) {390 if (isUploadDiscouraged() || data.getUploadPolicy() == UploadPolicy.BLOCKED) { 390 391 base.addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0)); 391 392 } 392 393 return base.get(); … … 603 604 if (isUploadDiscouraged()) { 604 605 p.add(new JLabel(tr("Upload is discouraged")), GBC.eop().insets(15, 0, 0, 0)); 605 606 } 607 if (data.getUploadPolicy() == UploadPolicy.BLOCKED) { 608 p.add(new JLabel(tr("Upload is blocked")), GBC.eop().insets(15, 0, 0, 0)); 609 } 606 610 607 611 return p; 608 612 } … … 873 877 874 878 @Override 875 879 public boolean isUploadable() { 876 return true;880 return data.getUploadPolicy() != UploadPolicy.BLOCKED; 877 881 } 878 882 879 883 @Override 880 884 public boolean requiresUploadToServer() { 881 return requiresUploadToServer;885 return isUploadable() && requiresUploadToServer; 882 886 } 883 887 884 888 @Override … … 967 971 // change listener and already got notified. 968 972 } 969 973 974 /** 975 * Determines if upload is being discouraged. 976 * (i.e. this dataset contains private data which should not be uploaded) 977 * @return {@code true} if upload is being discouraged, {@code false} otherwise 978 */ 970 979 @Override 971 980 public final boolean isUploadDiscouraged() { 972 return data. isUploadDiscouraged();981 return data.getUploadPolicy() == UploadPolicy.DISCOURAGED; 973 982 } 974 983 975 984 /** … … 978 987 * This feature allows to use "private" data layers. 979 988 */ 980 989 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 981 if (uploadDiscouraged ^ isUploadDiscouraged()) { 982 data.setUploadDiscouraged(uploadDiscouraged); 990 if (data.getUploadPolicy() != UploadPolicy.BLOCKED && 991 uploadDiscouraged ^ isUploadDiscouraged()) { 992 data.setUploadPolicy(uploadDiscouraged ? UploadPolicy.DISCOURAGED : UploadPolicy.NORMAL); 983 993 for (LayerStateChangeListener l : layerStateChangeListeners) { 984 994 l.uploadDiscouragedChanged(this, uploadDiscouraged); 985 995 } -
src/org/openstreetmap/josm/io/OsmReader.java
27 27 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 28 28 import org.openstreetmap.josm.data.osm.Changeset; 29 29 import org.openstreetmap.josm.data.osm.DataSet; 30 import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy; 30 31 import org.openstreetmap.josm.data.osm.Node; 31 32 import org.openstreetmap.josm.data.osm.NodeData; 32 33 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 138 139 ds.setVersion(v); 139 140 String upload = parser.getAttributeValue(null, "upload"); 140 141 if (upload != null) { 141 ds.setUploadDiscouraged(!Boolean.parseBoolean(upload)); 142 for (UploadPolicy policy : UploadPolicy.values()) { 143 if (policy.getXmlFlag().equalsIgnoreCase(upload)) { 144 ds.setUploadPolicy(policy); 145 break; 146 } 147 } 142 148 } 143 149 String generator = parser.getAttributeValue(null, "generator"); 144 150 Long uploadChangesetId = null; -
src/org/openstreetmap/josm/io/OsmWriter.java
16 16 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 17 17 import org.openstreetmap.josm.data.osm.Changeset; 18 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy; 19 20 import org.openstreetmap.josm.data.osm.INode; 20 21 import org.openstreetmap.josm.data.osm.IPrimitive; 21 22 import org.openstreetmap.josm.data.osm.IRelation; … … 77 78 header(null); 78 79 } 79 80 80 public void header( Booleanupload) {81 public void header(UploadPolicy upload) { 81 82 out.println("<?xml version='1.0' encoding='UTF-8'?>"); 82 83 out.print("<osm version='"); 83 84 out.print(version); 84 if (upload != null) {85 if (upload != UploadPolicy.NORMAL) { 85 86 out.print("' upload='"); 86 out.print(upload );87 out.print(upload.getXmlFlag()); 87 88 } 88 89 out.println("' generator='JOSM'>"); 89 90 } … … 113 114 } 114 115 115 116 public void writeLayer(OsmDataLayer layer) { 116 header( !layer.isUploadDiscouraged());117 header(layer.data.getUploadPolicy()); 117 118 writeDataSources(layer.data); 118 119 writeContent(layer.data); 119 120 footer(); -
src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
156 156 try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 157 157 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion()) 158 158 ) { 159 w.header( Boolean.FALSE);159 w.header(DataSet.UploadPolicy.DISCOURAGED); 160 160 w.writeContent(ds); 161 161 w.footer(); 162 162 } catch (IOException ex) {