Changeset 58 in josm for src/org/openstreetmap
- Timestamp:
- 2006-03-14T01:47:55+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 deleted
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r55 r58 43 43 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; 44 44 import org.openstreetmap.josm.io.OsmServerReader; 45 import org.xml.sax.SAXException; 45 46 46 47 /** … … 254 255 else 255 256 Main.main.getMapFrame().mapView.addLayer(layer); 257 } catch (SAXException x) { 258 closeDialog(); 259 x.printStackTrace(); 260 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 256 261 } catch (JDOMException x) { 257 262 closeDialog(); -
src/org/openstreetmap/josm/actions/OpenAction.java
r54 r58 24 24 import org.openstreetmap.josm.io.GpxReader; 25 25 import org.openstreetmap.josm.io.OsmReader; 26 import org.openstreetmap.josm.io.OsmReaderOld; 26 27 import org.openstreetmap.josm.io.RawCsvReader; 27 28 import org.openstreetmap.josm.io.RawGpsReader; 29 import org.xml.sax.SAXException; 28 30 29 31 /** … … 75 77 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) 76 78 dataSet = new GpxReader(new FileReader(filename)).parse(); 77 else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) 78 dataSet = new OsmReader(new FileReader(filename)).parse(); 79 else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 79 else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { 80 try { 81 // temporary allow loading of old xml format. 82 dataSet = OsmReader.parseDataSet(new FileReader(filename)); 83 } catch (SAXException x) { 84 if (x.getMessage().equals("Unknown version: null")) { 85 int answer = JOptionPane.showConfirmDialog(Main.main, 86 "This seems to be an old 0.2 API XML file.\n" + 87 "JOSM can try to open it with the old parser. This option\n" + 88 "will not be available in future JOSM version. You should\n" + 89 "immediatly save the file, if successfull imported.", 90 "Load as 0.2 API file?", 91 JOptionPane.YES_NO_OPTION); 92 if (answer != JOptionPane.YES_OPTION) 93 return; 94 dataSet = new OsmReaderOld(new FileReader(filename)).parse(); 95 } else 96 throw x; 97 } 98 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 80 99 JOptionPane.showMessageDialog(Main.main, "CSV Data import for non-GPS data is not implemented yet."); 81 100 return; … … 92 111 Main.main.getMapFrame().mapView.addLayer(layer); 93 112 113 } catch (SAXException x) { 114 x.printStackTrace(); 115 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 94 116 } catch (JDOMException x) { 95 117 x.printStackTrace(); -
src/org/openstreetmap/josm/actions/SaveAction.java
r54 r58 68 68 new GpxWriter(fileWriter = new FileWriter(file), Main.main.ds).output(); 69 69 else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) 70 new OsmWriter(fileWriter = new FileWriter(file), Main.main.ds).output();70 OsmWriter.output(fileWriter = new FileWriter(file), Main.main.ds, false); 71 71 else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 72 72 JOptionPane.showMessageDialog(Main.main, "CSV output not supported yet."); -
src/org/openstreetmap/josm/actions/UploadAction.java
r52 r58 17 17 import org.jdom.JDOMException; 18 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.Preferences.PreferencesException; 19 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 import org.openstreetmap.josm.data.osm.Track;21 21 import org.openstreetmap.josm.gui.GBC; 22 22 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 39 39 40 40 public void actionPerformed(ActionEvent e) { 41 42 //TODO: Remove this in later versions (temporary only) 43 if (Main.pref.osmDataServer.endsWith("/0.2") || Main.pref.osmDataServer.endsWith("/0.2/")) { 44 int answer = JOptionPane.showConfirmDialog(Main.main, 45 "You seem to have an outdated server entry in your preferences.\n" + 46 "\n" + 47 "As of JOSM Release 1.2, you must no longer specify the API version in\n" + 48 "the osm url. For the OSM standard server, use http://www.openstreetmap.org/api" + 49 "\n" + 50 "Fix settings and continue?", "Outdated server url detected.", JOptionPane.YES_NO_OPTION); 51 if (answer != JOptionPane.YES_OPTION) 52 return; 53 int cutPos = Main.pref.osmDataServer.endsWith("/0.2") ? 4 : 5; 54 Main.pref.osmDataServer = Main.pref.osmDataServer.substring(0, Main.pref.osmDataServer.length()-cutPos); 55 try { 56 Main.pref.save(); 57 } catch (PreferencesException x) { 58 x.printStackTrace(); 59 JOptionPane.showMessageDialog(Main.main, "Could not save the preferences chane:\n" + 60 x.getMessage()); 61 } 62 } 63 41 64 final Collection<OsmPrimitive> add = new LinkedList<OsmPrimitive>(); 42 65 final Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 43 66 final Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 44 boolean acceptedTracks = false;45 67 for (OsmPrimitive osm : Main.main.ds.allPrimitives()) { 46 boolean doSomething = true;47 68 if (osm.id == 0 && !osm.isDeleted()) 48 69 add.add(osm); … … 51 72 else if (osm.isDeleted() && osm.id != 0) 52 73 delete.add(osm); 53 else54 doSomething = false;55 56 if (osm instanceof Track && doSomething && !acceptedTracks) {57 int answer = JOptionPane.showConfirmDialog(Main.main,58 "The server currently does not understand the concept of Tracks.\n" +59 "All tracks will be ignored on upload. Continue anyway?",60 "No Track support", JOptionPane.YES_NO_OPTION);61 if (answer != JOptionPane.YES_OPTION)62 return;63 acceptedTracks = true;64 }65 74 } 66 75 … … 88 97 }).start(); 89 98 } 90 99 91 100 /** 92 101 * Displays a screen where the actions that would be taken are displayed and -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r31 r58 46 46 */ 47 47 public AddTrackAction(MapFrame mapFrame) { 48 super("Add Track", "addtrack", "Combine line segments to a new track.", KeyEvent.VK_T, mapFrame);48 super("Add Way", "addtrack", "Combine line segments to a new way.", KeyEvent.VK_W, mapFrame); 49 49 this.selectionManager = new SelectionManager(this, false, mv); 50 50 } -
src/org/openstreetmap/josm/data/Preferences.java
r43 r58 54 54 * Base URL to the osm data server 55 55 */ 56 public String osmDataServer = "http://www.openstreetmap.org/api /0.2";56 public String osmDataServer = "http://www.openstreetmap.org/api"; 57 57 /** 58 58 * The username to the osm server -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r35 r58 1 1 package org.openstreetmap.josm.data.osm; 2 2 3 import java.util.HashMap; 3 4 import java.util.Map; 4 5 … … 10 11 * An OSM primitive can be associated with a key/value pair. It can be created, deleted 11 12 * and updated within the OSM-Server. 12 * 13 * 14 * Although OsmPrimitive is designed as a base class, it is not to be meant to subclass 15 * it by any other than from the package org.openstreetmap.josm.data.osm (thus the 16 * visibility of the constructor). The available primitives are a fixed set that are given 17 * by the server environment and not an extendible data stuff. 18 * 13 19 * @author imi 14 20 */ 15 21 abstract public class OsmPrimitive { 16 17 22 18 23 /** … … 129 134 return id == 0 ? super.hashCode() : (int)id; 130 135 } 136 137 /** 138 * Set the given value to the given key 139 * @param key The key, for which the value is to be set. 140 * @param value The value for the key. 141 */ 142 public void put(Key key, String value) { 143 if (keys == null) 144 keys = new HashMap<Key, String>(); 145 keys.put(key, value); 146 } 131 147 } -
src/org/openstreetmap/josm/data/projection/Projection.java
r51 r58 13 13 public static double MAX_LAT = 85; 14 14 public static double MAX_LON = 180; 15 public static final double MAX_SERVER_PRECISION = 1e1 3;15 public static final double MAX_SERVER_PRECISION = 1e12; 16 16 17 17 /** -
src/org/openstreetmap/josm/io/OsmReaderOld.java
r57 r58 20 20 21 21 /** 22 * Reads an osm xml stream and construct a DataSet out of it.22 * Reads the old osm 0.2 format. 23 23 * 24 24 * @author imi 25 25 */ 26 public class OsmReader {26 public class OsmReaderOld { 27 27 28 28 /** … … 35 35 * @param source The data source, as example a FileReader to read from a file. 36 36 */ 37 public OsmReader (Reader source) {37 public OsmReaderOld(Reader source) { 38 38 this.source = source; 39 39 } 40 static int i; 40 41 41 /** 42 42 * Read the input stream and return a DataSet from the stream. -
src/org/openstreetmap/josm/io/OsmServerReader.java
r47 r58 13 13 import org.openstreetmap.josm.data.GeoPoint; 14 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.xml.sax.SAXException; 15 16 16 17 /** … … 47 48 */ 48 49 public Collection<Collection<GeoPoint>> parseRawGps() throws IOException, JDOMException { 49 String url = Main.pref.osmDataServer+"/ trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";50 String url = Main.pref.osmDataServer+"/0.3/trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 50 51 Collection<Collection<GeoPoint>> data = new LinkedList<Collection<GeoPoint>>(); 51 52 Collection<GeoPoint> list = new LinkedList<GeoPoint>(); … … 78 79 * @return A data set containing all data retrieved from that url 79 80 */ 80 public DataSet parseOsm() throws JDOMException, IOException {81 Reader r = getReader(Main.pref.osmDataServer+"/ map?bbox="+lon1+","+lat1+","+lon2+","+lat2);81 public DataSet parseOsm() throws SAXException, IOException { 82 Reader r = getReader(Main.pref.osmDataServer+"/0.3/map?bbox="+lon1+","+lat1+","+lon2+","+lat2); 82 83 if (r == null) 83 84 return null; 84 DataSet data = new OsmReader(r).parse();85 DataSet data = OsmReader.parseDataSet(r); 85 86 r.close(); 86 87 return data; … … 95 96 */ 96 97 private Reader getReader(String urlStr) throws IOException { 98 System.out.println("download: "+urlStr); 97 99 initAuthentication(); 98 100 URL url = new URL(urlStr); -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r52 r58 5 5 import java.io.InputStream; 6 6 import java.io.InputStreamReader; 7 import java.io.OutputStream; 7 import java.io.OutputStreamWriter; 8 import java.io.Writer; 8 9 import java.net.HttpURLConnection; 9 10 import java.net.URL; … … 13 14 import java.util.LinkedList; 14 15 15 import org.jdom.Document;16 import org.jdom.Element;17 16 import org.jdom.JDOMException; 18 import org.jdom.output.Format;19 import org.jdom.output.XMLOutputter;20 17 import org.openstreetmap.josm.Main; 21 18 import org.openstreetmap.josm.data.osm.Key; … … 24 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 22 import org.openstreetmap.josm.data.osm.Track; 26 import org.openstreetmap.josm.data.osm.visitor.OsmXmlVisitor;27 23 import org.openstreetmap.josm.data.osm.visitor.Visitor; 28 24 … … 72 68 if (n.id == 0 && !n.isDeleted()) { 73 69 setCredits(n); 74 sendRequest("PUT", "n ewnode", n, true);70 sendRequest("PUT", "node", n, true); 75 71 } else if (n.isDeleted()) { 76 sendRequest("DELETE", "node /" + n.id, n, false);72 sendRequest("DELETE", "node", n, false); 77 73 } else { 78 sendRequest("PUT", "node /" + n.id, n, true);74 sendRequest("PUT", "node", n, true); 79 75 } 80 76 processed.add(n); … … 87 83 if (ls.id == 0 && !ls.isDeleted()) { 88 84 setCredits(ls); 89 sendRequest("PUT", " newsegment", ls, true);85 sendRequest("PUT", "segment", ls, true); 90 86 } else if (ls.isDeleted()) { 91 sendRequest("DELETE", "segment /" + ls.id, ls, false);87 sendRequest("DELETE", "segment", ls, false); 92 88 } else { 93 sendRequest("PUT", "segment /" + ls.id, ls, true);89 sendRequest("PUT", "segment", ls, true); 94 90 } 95 91 processed.add(ls); 92 } 93 94 /** 95 * Upload a whole way with the complete line segment id list. 96 */ 97 public void visit(Track w) { 98 if (w.id == 0 && !w.isDeleted()) { 99 setCredits(w); 100 sendRequest("PUT", "way", w, true); 101 } else if (w.isDeleted()) { 102 sendRequest("DELETE", "way", w, false); 103 } else { 104 sendRequest("PUT", "way", w, true); 105 } 106 processed.add(w); 96 107 } 97 108 … … 107 118 } 108 119 109 public void visit(Track t) {110 // not implemented in server111 }112 120 113 121 public void visit(Key k) { … … 145 153 OsmPrimitive osm, boolean addBody) { 146 154 try { 147 URL url = new URL(Main.pref.osmDataServer + "/" + urlSuffix); 155 URL url = new URL(Main.pref.osmDataServer + "/0.3/" + urlSuffix + "/" + osm.id); 156 System.out.println("upload to: "+url); 148 157 HttpURLConnection con = (HttpURLConnection) url.openConnection(); 149 158 con.setConnectTimeout(20000); … … 154 163 155 164 if (addBody) { 156 OsmXmlVisitor visitor = new OsmXmlVisitor(false); 157 osm.visit(visitor); 158 Element root = new Element("osm"); 159 root.setAttribute("version", "0.2"); 160 root.getChildren().add(visitor.element); 161 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 162 OutputStream out = con.getOutputStream(); 163 Document doc = new Document(root); 164 xmlOut.output(doc, out); 165 Writer out = new OutputStreamWriter(con.getOutputStream()); 166 OsmWriter.outputSingle(out, osm, true); 165 167 out.close(); 166 168 } … … 169 171 if (retCode == 200 && osm.id == 0) 170 172 osm.id = readId(con.getInputStream()); 173 System.out.println("got return: "+retCode+" with id "+osm.id); 171 174 con.disconnect(); 172 175 } catch (UnknownHostException e) { 173 176 throw new RuntimeException("Unknown host: "+e.getMessage(), e); 174 177 } catch (Exception e) { 178 if (e instanceof RuntimeException) 179 throw (RuntimeException)e; 175 180 throw new RuntimeException(e.getMessage(), e); 176 181 }
Note:
See TracChangeset
for help on using the changeset viewer.