Ignore:
Timestamp:
2005-12-28T01:29:01+01:00 (18 years ago)
Author:
imi
Message:
  • fixed bug in UTM
  • upload of nodes and segments
  • fixed bugs in display the selection
File:
1 edited

Legend:

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

    r34 r35  
    2727 * Class that uploades all changes to the osm server.
    2828 *
    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.
    3432 *
    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.
    3735 *
    3836 * @author imi
     
    4139
    4240        /**
    43          * Send the dataset to the server. Ask the user first and does nothing if
    44          * he does 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.
    4543         */
    4644        public void uploadOsm(Collection<OsmPrimitive> list) throws JDOMException {
     
    4846
    4947                try {
    50 //                      for (OsmPrimitive osm : list)
    51 //                              osm.visit(this);
     48                        for (OsmPrimitive osm : list)
     49                                osm.visit(this);
    5250                } catch (RuntimeException e) {
    5351                        throw new JDOMException("An error occoured: ", e);
     
    6058        @SuppressWarnings("unchecked")
    6159        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);
    6664                } else {
    67                         sendRequest("PUT", "node/"+n.id, n);
     65                        sendRequest("PUT", "node/" + n.id, n, true);
    6866                }
    6967        }
    7068
    7169        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                }
    7277        }
    7378
    7479        public void visit(Track t) {
     80                // not implemented in server
    7581        }
    7682
    7783        public void visit(Key k) {
     84                // not implemented in server
    7885        }
    7986
     
    8289         */
    8390        private long readId(InputStream inputStream) throws IOException {
    84                 BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
     91                BufferedReader in = new BufferedReader(new InputStreamReader(
     92                                inputStream));
    8593                String s = in.readLine();
    8694                if (s == null)
     
    92100                }
    93101        }
    94        
     102
    95103        @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) {
    97106                try {
    98107                        URL url = new URL(Main.pref.osmDataServer + "/" + urlSuffix);
    99                         HttpURLConnection con = (HttpURLConnection)url.openConnection();
     108                        HttpURLConnection con = (HttpURLConnection) url.openConnection();
    100109                        con.setConnectTimeout(20000);
    101110                        con.setRequestMethod(requestMethod);
    102                         con.setDoOutput(true);
     111                        if (addBody)
     112                                con.setDoOutput(true);
    103113                        con.connect();
    104114
    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
    117129                        int retCode = con.getResponseCode();
    118                         System.out.println(retCode+" "+con.getResponseMessage());
    119130                        if (retCode == 200 && osm.id == 0)
    120131                                osm.id = readId(con.getInputStream());
Note: See TracChangeset for help on using the changeset viewer.