Changeset 35 in josm for src/org/openstreetmap/josm/io/OsmServerWriter.java
- Timestamp:
- 2005-12-28T01:29:01+01:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 * on the 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());
Note:
See TracChangeset
for help on using the changeset viewer.