- Timestamp:
- 2005-12-28T01:29:01+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r34 r35 7 7 import java.awt.event.InputEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.io.FileNotFoundException; 9 10 import java.io.IOException; 10 11 … … 169 170 x.printStackTrace(); 170 171 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 172 } catch (FileNotFoundException x) { 173 x.printStackTrace(); 174 JOptionPane.showMessageDialog(Main.main, "URL nicht gefunden: "+x.getMessage()); 171 175 } catch (IOException x) { 172 176 x.printStackTrace(); -
src/org/openstreetmap/josm/actions/UploadAction.java
r34 r35 18 18 import org.openstreetmap.josm.Main; 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 import org.openstreetmap.josm.data.osm.Track; 20 21 import org.openstreetmap.josm.gui.GBC; 21 22 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 41 42 Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 42 43 Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 43 for (OsmPrimitive osm : Main.main.ds.nodes) 44 if (osm.id == 0) 44 for (OsmPrimitive osm : Main.main.ds.allPrimitives()) { 45 if (osm instanceof Track) { 46 int answer = JOptionPane.showConfirmDialog(Main.main, 47 "The server currently does not understand the concept of Tracks.\n" + 48 "All tracks will be ignored on upload. Continue anyway?", 49 "No Track support", JOptionPane.YES_NO_OPTION); 50 if (answer != JOptionPane.YES_OPTION) 51 return; 52 } 53 if (osm.id == 0 && !osm.isDeleted()) 45 54 add.add(osm); 46 else if (osm.modified) 55 else if ((osm.modified || osm.modifiedProperties) && !osm.isDeleted()) 47 56 update.add(osm); 48 for (OsmPrimitive osm : Main.main.ds.lineSegments) 49 if (osm.id == 0) 50 add.add(osm); 51 else if (osm.modified) 52 update.add(osm); 53 for (OsmPrimitive osm : Main.main.ds.tracks) 54 if (osm.id == 0) 55 add.add(osm); 56 else if (osm.modified) 57 update.add(osm); 58 for (OsmPrimitive osm : Main.main.ds.deleted) 59 if (osm.id != 0) 57 else if (osm.isDeleted() && osm.id != 0) 60 58 delete.add(osm); 59 } 61 60 62 61 if (!displayUploadScreen(add, update, delete)) 63 62 return; 64 63 65 64 OsmServerWriter server = new OsmServerWriter(); 66 65 try { … … 70 69 all.addAll(delete); 71 70 server.uploadOsm(all); 71 // finished without errors -> clean dataset 72 Main.main.getMapFrame().mapView.editLayer().cleanData(); 72 73 } catch (JDOMException x) { 73 74 x.printStackTrace(); … … 87 88 return false; 88 89 } 89 90 90 91 JPanel p = new JPanel(new GridBagLayout()); 91 92 -
src/org/openstreetmap/josm/command/AddCommand.java
r31 r35 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 7 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 8 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;9 8 10 9 /** … … 39 38 40 39 public void undoCommand() { 41 osm. visit(new DeleteVisitor(ds));40 osm.setDeleted(true); 42 41 } 43 42 -
src/org/openstreetmap/josm/command/ChangeKeyValueCommand.java
r33 r35 55 55 for (OsmPrimitive osm : objects) { 56 56 oldProperties.add(osm.keys == null ? null : new HashMap<Key, String>(osm.keys)); 57 oldModified.add(osm.modified); 58 osm.modified = true; 57 oldModified.add(osm.modifiedProperties); 58 osm.modifiedProperties = true; 59 59 } 60 60 … … 81 81 for (OsmPrimitive osm : objects) { 82 82 osm.keys = it.next(); 83 osm.modified = itMod.next(); 83 osm.modifiedProperties = itMod.next(); 84 84 } 85 85 } -
src/org/openstreetmap/josm/command/DeleteCommand.java
r31 r35 8 8 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 9 9 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 10 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor;11 10 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 11 … … 35 34 36 35 public void executeCommand() { 37 Visitor v = new DeleteVisitor(ds);38 36 for (OsmPrimitive osm : data) 39 osm. visit(v);37 osm.setDeleted(true); 40 38 } 41 39 -
src/org/openstreetmap/josm/data/osm/DataSet.java
r32 r35 2 2 3 3 import java.util.Collection; 4 import java.util.HashMap;5 4 import java.util.HashSet; 6 5 import java.util.LinkedList; 7 import java.util.Map;8 6 9 7 import org.openstreetmap.josm.data.Bounds; … … 44 42 45 43 /** 46 * All deleted objects goes here. 44 * @return A collection containing all primitives (except keys) of the 45 * dataset. 47 46 */ 48 public Collection<OsmPrimitive> deleted = new LinkedList<OsmPrimitive>(); 49 47 public Collection<OsmPrimitive> allPrimitives() { 48 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>(); 49 o.addAll(nodes); 50 o.addAll(lineSegments); 51 o.addAll(tracks); 52 return o; 53 } 54 50 55 /** 51 56 * Return the bounds of this DataSet, depending on X/Y values. … … 133 138 134 139 /** 135 * Import the given dataset by merging all data with this dataset.136 * The objects imported are not cloned, so from now on, these data belong137 * to both datasets. So use mergeFrom only if you are about to abandon the138 * other dataset.139 *140 * Elements are tried to merged.141 * Nodes are merged first, if their lat/lon are equal.142 * Line segments are merged, if they have the same nodes.143 * Tracks are merged, if they consist of the same line segments.144 *145 * TODO Additional to that, every two objects with the same id are merged.146 *147 * @param ds The DataSet to merge into this one.148 */149 public void mergeFrom(DataSet ds) {150 // merge nodes151 152 Map<Node, Node> nodeMap = new HashMap<Node, Node>();153 154 // find mergable155 for (Node otherNode : ds.nodes)156 for (Node myNode : nodes)157 if (otherNode.coor.equalsLatLon(myNode.coor))158 nodeMap.put(otherNode, myNode);159 // add160 for (Node n : ds.nodes)161 if (!nodeMap.containsKey(n))162 nodes.add(n);163 // reassign164 for (LineSegment ls : ds.lineSegments) {165 Node n = nodeMap.get(ls.start);166 if (n != null)167 ls.start = n;168 n = nodeMap.get(ls.end);169 if (n != null)170 ls.end = n;171 }172 173 174 // merge line segments175 176 Map<LineSegment, LineSegment> lsMap = new HashMap<LineSegment, LineSegment>();177 // find mergable178 for (LineSegment otherLS : ds.lineSegments)179 for (LineSegment myLS : lineSegments)180 if (otherLS.start == myLS.start && otherLS.end == myLS.end)181 lsMap.put(otherLS, myLS);182 // add ls183 for (LineSegment ls : ds.lineSegments)184 if (!lsMap.containsKey(ls))185 lineSegments.add(ls);186 // reassign187 for (Track t : ds.tracks) {188 for (int i = 0; i < t.segments.size(); ++i) {189 LineSegment newLS = lsMap.get(t.segments.get(i));190 if (newLS != null)191 t.segments.set(i, newLS);192 }193 }194 195 196 // merge tracks197 198 LinkedList<Track> trackToAdd = new LinkedList<Track>();199 for (Track otherTrack : ds.tracks) {200 boolean found = false;201 for (Track myTrack : tracks) {202 if (myTrack.segments.equals(otherTrack.segments)) {203 found = true;204 break;205 }206 }207 if (!found)208 trackToAdd.add(otherTrack);209 }210 tracks.addAll(trackToAdd);211 }212 213 /**214 140 * Remove the selection from every value in the collection. 215 141 * @param list The collection to remove the selection from. … … 234 160 return sel; 235 161 for (OsmPrimitive osm : list) { 236 if (osm.isSelected()) 162 if (osm.isSelected() && !osm.isDeleted()) 237 163 sel.add(osm); 238 164 if (osm.keys != null) -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r33 r35 15 15 abstract public class OsmPrimitive { 16 16 17 17 18 /** 18 19 * The key/value list for this primitive. … … 28 29 29 30 /** 30 * <code>true</code>, if the object has been modified since it was loaded from 31 * the server. In this case, on next upload, this object will be updated. Deleted 32 * objects are deleted from the server, even if they are modified. If the objects 33 * are added (id=0), the modified is ignored and the object is added to the server. 31 * <code>true</code>, if the objects content (not the properties) has been 32 * modified since it was loaded from the server. In this case, on next upload, 33 * this object will be updated. Deleted objects are deleted from the server. 34 * If the objects are added (id=0), the modified is ignored and the object is 35 * added to the server. 34 36 */ 35 37 public boolean modified = false; 38 39 /** 40 * <code>true</code>, if the object's keys has been changed by JOSM since 41 * last update. 42 */ 43 public boolean modifiedProperties = false; 36 44 45 /** 46 * <code>true</code>, if the object has been deleted. 47 */ 48 private boolean deleted = false; 49 37 50 /** 38 51 * If set to true, this object is currently selected. … … 89 102 90 103 104 public void setDeleted(boolean deleted) { 105 this.deleted = deleted; 106 setSelected(false); 107 } 108 109 public boolean isDeleted() { 110 return deleted; 111 } 112 91 113 /** 92 * Equal, if the id is equal. If both ids are 0, use the super classes equal93 * instead. 114 * Equal, if the id (and class) is equal. If both ids are 0, use the super classes 115 * equal instead. 94 116 */ 95 117 @Override 96 118 public boolean equals(Object obj) { 97 if (!(obj instanceof OsmPrimitive)) 98 return false; 99 OsmPrimitive osm = (OsmPrimitive)obj; 100 if (id == 0 && osm.id == 0) 119 if (getClass() != obj.getClass() || id == 0 || obj == null || ((OsmPrimitive)obj).id == 0) 101 120 return super.equals(obj); 102 return id == osm.id;121 return id == ((OsmPrimitive)obj).id; 103 122 } 104 123 -
src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java
r32 r35 26 26 public void visit(Node n) { 27 27 ds.nodes.add(n); 28 ds.deleted.remove(n); // remove if there.28 n.setDeleted(false); 29 29 } 30 30 public void visit(LineSegment ls) { 31 31 ds.lineSegments.add(ls); 32 ds.deleted.remove(ls); // remove if there.32 ls.setDeleted(false); 33 33 } 34 34 public void visit(Track t) { 35 35 ds.tracks.add(t); 36 ds.deleted.remove(t); // remove if there.36 t.setDeleted(false); 37 37 } 38 38 public void visit(Key k) {} -
src/org/openstreetmap/josm/data/osm/visitor/BoundingVisitor.java
r23 r35 21 21 * Calculate regarding lat/lon or x/y? 22 22 */ 23 public static enum Type {LATLON, XY} ;23 public static enum Type {LATLON, XY} 24 24 private Type type; 25 26 25 26 27 27 public BoundingVisitor(Type type) { 28 28 this.type = type; -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r30 r35 30 30 */ 31 31 private final MapView mv; 32 /**33 * Can be set to non-<code>null</code> and then replace every other color.34 */35 private final Color forceColor;36 32 37 33 /** … … 39 35 * @param g The graphics to draw to. 40 36 * @param mv The view to get screen coordinates from. 41 * @param forceColor If non-<code>null</code>, always draw with this color.42 37 */ 43 public SimplePaintVisitor(Graphics g, MapView mv , Color forceColor) {38 public SimplePaintVisitor(Graphics g, MapView mv) { 44 39 this.g = g; 45 40 this.mv = mv; 46 this.forceColor = forceColor;47 41 } 48 42 … … 70 64 */ 71 65 public void visit(Track t) { 66 // only to overwrite with blue 72 67 for (LineSegment ls : t.segments) 73 drawLineSegment(ls, darkblue); 68 if (!ls.isSelected()) // selected already in good color 69 drawLineSegment(ls, t.isSelected() ? Color.WHITE : darkblue); 74 70 } 75 71 … … 88 84 private void drawNode(Node n, Color color) { 89 85 Point p = mv.getScreenPoint(n.coor); 90 g.setColor( forceColor != null ? forceColor :color);86 g.setColor(color); 91 87 g.drawRect(p.x-1, p.y-1, 2, 2); 92 88 } … … 96 92 */ 97 93 private void drawLineSegment(LineSegment ls, Color col) { 98 if (forceColor != null) 99 col = forceColor; 100 else if (ls.isSelected()) 94 if (ls.isSelected()) 101 95 col = Color.WHITE; 102 96 g.setColor(col); -
src/org/openstreetmap/josm/data/projection/UTM.java
r23 r35 39 39 public final static double RAD_TO_DEG = 180 / Math.PI; 40 40 41 public final static double k0 = 0.9996012717; 42 41 43 /** 42 44 * A reference ellipsoid used in Projections … … 116 118 // Written by Chuck Gantz- chuck.gantz@globalstar.com 117 119 // ported to Ruby by Ben Gimpert- ben@somethingmodern.com 118 double k0 = 0.9996012717;119 120 120 double lat_rad = p.lat * DEG_TO_RAD; 121 121 double long_temp = (p.lon + 180) - (Math.floor((p.lon + 180) / 360) * 360) - 180; … … 150 150 // Written by Chuck Gantz- chuck.gantz@globalstar.com 151 151 // ported to Ruby by Ben Gimpert- ben@somethingmodern.com 152 double k0 = 0.9996;153 152 double e1 = (1-Math.sqrt(1-ellipsoid.ecc_squared))/(1+Math.sqrt(1-ellipsoid.ecc_squared)); 154 153 double x = p.x - 500000.0; -
src/org/openstreetmap/josm/gui/MapView.java
r30 r35 253 253 return minPrimitive; 254 254 255 // pending line segments 255 // for whole tracks, try the tracks first 256 minDistanceSq = Double.MAX_VALUE; 257 if (wholeTrack) { 258 for (Track t : Main.main.ds.tracks) { 259 for (LineSegment ls : t.segments) { 260 Point A = getScreenPoint(ls.start.coor); 261 Point B = getScreenPoint(ls.end.coor); 262 double c = A.distanceSq(B); 263 double a = p.distanceSq(B); 264 double b = p.distanceSq(A); 265 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared 266 if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) { 267 minDistanceSq = perDist; 268 minPrimitive = t; 269 } 270 } 271 } 272 if (minPrimitive != null) 273 return minPrimitive; 274 } 275 276 minDistanceSq = Double.MAX_VALUE; 277 // line segments 256 278 for (LineSegment ls : Main.main.ds.lineSegments) { 257 279 Point A = getScreenPoint(ls.start.coor); … … 267 289 } 268 290 269 // tracks & line segments 270 minDistanceSq = Double.MAX_VALUE; 271 for (Track t : Main.main.ds.tracks) { 272 for (LineSegment ls : t.segments) { 273 Point A = getScreenPoint(ls.start.coor); 274 Point B = getScreenPoint(ls.end.coor); 275 double c = A.distanceSq(B); 276 double a = p.distanceSq(B); 277 double b = p.distanceSq(A); 278 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared 279 if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) { 280 minDistanceSq = perDist; 281 minPrimitive = wholeTrack ? t : ls; 282 } 283 } 284 } 285 if (minPrimitive != null) 286 return minPrimitive; 287 288 // TODO areas 289 290 return null; // nothing found 291 return minPrimitive; 291 292 } 292 293 -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r32 r35 2 2 3 3 import java.awt.Graphics; 4 import java.util.Iterator; 4 5 import java.util.LinkedList; 5 6 import java.util.Stack; … … 13 14 import org.openstreetmap.josm.data.osm.LineSegment; 14 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 17 import org.openstreetmap.josm.data.osm.Track; 16 18 import org.openstreetmap.josm.data.osm.visitor.BoundingVisitor; 19 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 17 20 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 18 21 import org.openstreetmap.josm.data.projection.Projection; … … 70 73 @Override 71 74 public void paint(Graphics g, MapView mv) { 72 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv, null); 73 74 for (LineSegment ls : data.lineSegments) 75 visitor.visit(ls); 76 for (Track t : data.tracks) 77 visitor.visit(t); 78 for (Node n : data.nodes) 79 visitor.visit(n); 75 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv); 76 for (OsmPrimitive osm : data.lineSegments) 77 if (!osm.isDeleted()) 78 osm.visit(visitor); 79 for (OsmPrimitive osm : data.tracks) 80 if (!osm.isDeleted()) 81 osm.visit(visitor); 82 for (OsmPrimitive osm : data.nodes) 83 if (!osm.isDeleted()) 84 osm.visit(visitor); 80 85 } 81 86 … … 87 92 @Override 88 93 public void mergeFrom(Layer from) { 89 data.mergeFrom(((OsmDataLayer)from).data); 94 MergeVisitor visitor = new MergeVisitor(data); 95 for (OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) 96 osm.visit(visitor); 90 97 } 91 98 … … 163 170 Main.main.redoAction.setEnabled(!redoCommands.isEmpty()); 164 171 } 172 173 /** 174 * Clean out the data behind the layer. This means clearing the redo/undo lists, 175 * really deleting all deleted objects and reset the modified flags. This is done 176 * after a successfull upload. 177 */ 178 public void cleanData() { 179 redoCommands.clear(); 180 commands.clear(); 181 for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 182 cleanIterator(it); 183 for (Iterator<LineSegment> it = data.lineSegments.iterator(); it.hasNext();) 184 cleanIterator(it); 185 for (Iterator<Track> it = data.tracks.iterator(); it.hasNext();) 186 cleanIterator(it); 187 } 188 189 private void cleanIterator(Iterator<? extends OsmPrimitive> it) { 190 OsmPrimitive osm = it.next(); 191 osm.modified = false; 192 osm.modifiedProperties = false; 193 if (osm.isDeleted()) 194 it.remove(); 195 } 165 196 } -
src/org/openstreetmap/josm/io/GpxReader.java
r33 r35 190 190 osm.id = Long.parseLong(idElement.getText()); 191 191 osm.modified = e.getChild("modified", JOSM) != null; 192 osm.modifiedProperties = e.getChild("modifiedProperties", JOSM) != null; 192 193 } 193 194 } -
src/org/openstreetmap/josm/io/GpxWriter.java
r33 r35 242 242 @SuppressWarnings("unchecked") 243 243 private void addPropertyExtensions(Element e, Map<Key, String> keys, OsmPrimitive osm) { 244 if ((keys == null || keys.isEmpty()) && osm.id == 0 && !osm.modified) 244 if ((keys == null || keys.isEmpty()) && osm.id == 0 && !osm.modified && !osm.modifiedProperties) 245 245 return; 246 246 Element extensions = e.getChild("extensions", GPX); … … 255 255 } 256 256 } 257 // id258 257 if (osm.id != 0) { 259 258 Element propElement = new Element("uid", JOSM); … … 261 260 extensions.getChildren().add(propElement); 262 261 } 263 // modified264 262 if (osm.modified) { 265 263 Element modElement = new Element("modified", JOSM); 266 264 extensions.getChildren().add(modElement); 267 265 } 266 if (osm.modifiedProperties) { 267 Element modElement = new Element("modifiedProperties", JOSM); 268 extensions.getChildren().add(modElement); 269 } 268 270 } 269 271 } -
src/org/openstreetmap/josm/io/OsmReader.java
r33 r35 104 104 for (Object o : e.getChildren()) { 105 105 Element child = (Element)o; 106 if (child.getName().equals("deleted")) 107 for (Object delObj : child.getChildren()) 108 data.deleted.add(parseObject((Element)delObj, data)); 109 else { 106 if (child.getName().equals("deleted")) { 107 for (Object delObj : child.getChildren()) { 108 OsmPrimitive osm = parseObject((Element)delObj, data); 109 if (osm != null) { 110 osm.visit(visitor); 111 osm.setDeleted(true); 112 } 113 } 114 } else { 110 115 OsmPrimitive osm = parseObject(child, data); 111 116 if (osm != null) … … 200 205 OsmPrimitive osm = findObject(data, id); 201 206 Key key = Key.get(e.getAttributeValue("key")); 202 String value =e.getAttributeValue("value"); 207 String value = e.getAttributeValue("value"); 203 208 if (value != null) { 204 209 if (osm.keys == null) … … 221 226 if (osm.id == id) 222 227 return osm; 223 for (OsmPrimitive osm : data.deleted)224 if (osm.id == id)225 return osm;226 228 throw new JDOMException("Unknown object reference: "+id); 227 229 } -
src/org/openstreetmap/josm/io/OsmServerReader.java
r34 r35 93 93 private Reader getReader(String urlStr) throws IOException { 94 94 initAuthentication(); 95 System.out.println(urlStr);96 95 URL url = new URL(urlStr); 97 96 HttpURLConnection con = (HttpURLConnection)url.openConnection(); -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r34 r35 27 27 * Class that uploades all changes to the osm server. 28 28 * 29 * This is done like this: 30 * - All objects with id = 0 are uploaded as new, except those in deleted, 31 * which are ignored 32 * - All objects in deleted list are deleted. 33 * - All remaining objects with modified flag set are updated. 29 * This is done like this: - All objects with id = 0 are uploaded as new, except 30 * those in deleted, which are ignored - All objects in deleted list are 31 * deleted. - All remaining objects with modified flag set are updated. 34 32 * 35 * This class implements visitor and will perform the correct upload action 36 * onthe visited element.33 * This class implements visitor and will perform the correct upload action on 34 * the visited element. 37 35 * 38 36 * @author imi … … 41 39 42 40 /** 43 * Send the dataset to the server. Ask the user first and does nothing if 44 * hedoes not want to send the data.41 * Send the dataset to the server. Ask the user first and does nothing if he 42 * does not want to send the data. 45 43 */ 46 44 public void uploadOsm(Collection<OsmPrimitive> list) throws JDOMException { … … 48 46 49 47 try { 50 //for (OsmPrimitive osm : list)51 //osm.visit(this);48 for (OsmPrimitive osm : list) 49 osm.visit(this); 52 50 } catch (RuntimeException e) { 53 51 throw new JDOMException("An error occoured: ", e); … … 60 58 @SuppressWarnings("unchecked") 61 59 public void visit(Node n) { 62 if (n.id == 0) { 63 sendRequest("PUT", "newnode", n); 64 } else if ( Main.main.ds.deleted.contains(n)) {65 sendRequest("DELETE", "node/" +n.id, n);60 if (n.id == 0 && !n.isDeleted()) { 61 sendRequest("PUT", "newnode", n, true); 62 } else if (n.isDeleted()) { 63 sendRequest("DELETE", "node/" + n.id, n, false); 66 64 } else { 67 sendRequest("PUT", "node/" +n.id, n);65 sendRequest("PUT", "node/" + n.id, n, true); 68 66 } 69 67 } 70 68 71 69 public void visit(LineSegment ls) { 70 if (ls.id == 0 && !ls.isDeleted()) { 71 sendRequest("PUT", "newsegment", ls, true); 72 } else if (ls.isDeleted()) { 73 sendRequest("DELETE", "segment/" + ls.id, ls, false); 74 } else { 75 sendRequest("PUT", "segment/" + ls.id, ls, true); 76 } 72 77 } 73 78 74 79 public void visit(Track t) { 80 // not implemented in server 75 81 } 76 82 77 83 public void visit(Key k) { 84 // not implemented in server 78 85 } 79 86 … … 82 89 */ 83 90 private long readId(InputStream inputStream) throws IOException { 84 BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); 91 BufferedReader in = new BufferedReader(new InputStreamReader( 92 inputStream)); 85 93 String s = in.readLine(); 86 94 if (s == null) … … 92 100 } 93 101 } 94 102 95 103 @SuppressWarnings("unchecked") 96 private void sendRequest(String requestMethod, String urlSuffix, OsmPrimitive osm) { 104 private void sendRequest(String requestMethod, String urlSuffix, 105 OsmPrimitive osm, boolean addBody) { 97 106 try { 98 107 URL url = new URL(Main.pref.osmDataServer + "/" + urlSuffix); 99 HttpURLConnection con = (HttpURLConnection)url.openConnection(); 108 HttpURLConnection con = (HttpURLConnection) url.openConnection(); 100 109 con.setConnectTimeout(20000); 101 110 con.setRequestMethod(requestMethod); 102 con.setDoOutput(true); 111 if (addBody) 112 con.setDoOutput(true); 103 113 con.connect(); 104 114 105 OsmXmlVisitor visitor = new OsmXmlVisitor(false); 106 osm.visit(visitor); 107 Element root = new Element("osm"); 108 root.setAttribute("version", "0.2"); 109 root.getChildren().add(visitor.element); 110 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 111 OutputStream out = con.getOutputStream(); 112 Document doc = new Document(root); 113 xmlOut.output(doc, out); 114 xmlOut.output(doc, System.out); 115 out.close(); 116 115 if (addBody) { 116 OsmXmlVisitor visitor = new OsmXmlVisitor(false); 117 osm.visit(visitor); 118 Element root = new Element("osm"); 119 root.setAttribute("version", "0.2"); 120 root.getChildren().add(visitor.element); 121 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 122 OutputStream out = con.getOutputStream(); 123 Document doc = new Document(root); 124 xmlOut.output(doc, out); 125 xmlOut.output(doc, System.out); 126 out.close(); 127 } 128 117 129 int retCode = con.getResponseCode(); 118 System.out.println(retCode+" "+con.getResponseMessage());119 130 if (retCode == 200 && osm.id == 0) 120 131 osm.id = readId(con.getInputStream()); -
src/org/openstreetmap/josm/io/OsmWriter.java
r33 r35 63 63 List<Element> list = root.getChildren(); 64 64 properties = new LinkedList<Element>(); 65 for (Node n : ds.nodes) { 66 visit(n); 67 list.add(element); 68 } 69 for (LineSegment ls : ds.lineSegments) { 70 visit(ls); 71 list.add(element); 72 } 73 for (Track t : ds.tracks) { 74 visit(t); 75 list.add(element); 65 for (OsmPrimitive osm : ds.allPrimitives()) { 66 if (!osm.isDeleted()) { 67 osm.visit(this); 68 list.add(element); 69 } 76 70 } 77 71 list.addAll(properties); … … 79 73 Element deleted = new Element("deleted"); 80 74 Collection<Element> allDeleted = deleted.getChildren(); 81 for (OsmPrimitive osm : ds.deleted) { 82 osm.visit(this); 83 allDeleted.add(element); 75 for (OsmPrimitive osm : ds.allPrimitives()) { 76 if (osm.isDeleted()) { 77 osm.visit(this); 78 allDeleted.add(element); 79 } 84 80 } 85 81 allDeleted.addAll(properties);
Note:
See TracChangeset
for help on using the changeset viewer.