Changeset 1670 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-06-15T20:22:46+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 2 added
- 9 edited
-
BoundingBoxDownloader.java (modified) (3 diffs)
-
OsmApi.java (modified) (14 diffs)
-
OsmConnection.java (modified) (4 diffs)
-
OsmHistoryReader.java (added)
-
OsmServerHistoryReader.java (added)
-
OsmServerLocationReader.java (modified) (3 diffs)
-
OsmServerObjectReader.java (modified) (4 diffs)
-
OsmServerReader.java (modified) (4 diffs)
-
OsmServerWriter.java (modified) (1 diff)
-
OsmWriter.java (modified) (12 diffs)
-
ProgressInputStream.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r1465 r1670 50 50 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000))); 51 51 InputStream in = getInputStream(url+i, Main.pleaseWaitDlg); 52 if (in == null) 52 if (in == null) { 53 53 break; 54 } 54 55 GpxData currentGpx = new GpxReader(in, null).data; 55 56 if (result == null) { … … 89 90 * @return A data set containing all data retrieved from that url 90 91 */ 91 public DataSet parseOsm() throws SAXException, IOException { 92 @Override 93 public DataSet parseOsm() throws OsmTransferException { 92 94 try { 93 95 Main.pleaseWaitDlg.progress.setValue(0); … … 106 108 if (cancel) 107 109 return null; 108 throw e;110 throw new OsmTransferException(e); 109 111 } catch (SAXException e) { 112 throw new OsmTransferException(e); 113 } catch(OsmTransferException e) { 110 114 throw e; 111 115 } catch (Exception e) { 112 116 if (cancel) 113 117 return null; 114 if (e instanceof RuntimeException) 115 throw (RuntimeException)e; 116 throw new RuntimeException(e); 118 throw new OsmTransferException(e); 117 119 } 118 120 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r1667 r1670 29 29 import org.openstreetmap.josm.Main; 30 30 import org.openstreetmap.josm.data.osm.Changeset; 31 import org.openstreetmap.josm.data.osm.Node;32 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 33 import org.openstreetmap.josm.data.osm.Relation; 34 import org.openstreetmap.josm.data.osm.Way; 32 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 35 33 import org.openstreetmap.josm.data.osm.visitor.CreateOsmChangeVisitor; 36 34 import org.xml.sax.Attributes; … … 67 65 if (api == null) { 68 66 api = new OsmApi(serverUrl); 67 instances.put(serverUrl,api); 69 68 } 70 69 return api; … … 80 79 String serverUrl = Main.pref.get("osm-server.url"); 81 80 if (serverUrl == null) 82 throw new IllegalStateException(tr("preference {0}missing. Can't initialize OsmApi", "osm-server.url"));81 throw new IllegalStateException(tr("preference ''{0}'' missing. Can't initialize OsmApi", "osm-server.url")); 83 82 return getOsmApi(serverUrl); 84 83 } … … 96 95 */ 97 96 private String version = null; 98 99 /**100 * Maximum downloadable area from server (degrees squared), from capabilities response101 * FIXME: make download dialog use this, instead of hard-coded default.102 */103 private String maxArea = null;104 97 105 98 /** the api capabilities */ … … 143 136 144 137 /** 145 * creates an instance of the OSM API. Initializes the server URL with the146 * value of the preference <code>osm-server.url</code>147 *148 * @exception IllegalStateException thrown, if the preference <code>osm-server.url</code> is not set149 */150 protected OsmApi() {151 this.serverUrl = Main.pref.get("osm-server.url");152 if (serverUrl == null)153 throw new IllegalStateException(tr("preference {0} missing. Can't initialize OsmApi", "osm-server.url"));154 }155 156 /**157 * Helper that returns the lower-case type name of an OsmPrimitive158 * @param o the primitive159 * @return "node", "way", "relation", or "changeset"160 */161 public static String which(OsmPrimitive o) {162 if (o instanceof Node) return "node";163 if (o instanceof Way) return "way";164 if (o instanceof Relation) return "relation";165 if (o instanceof Changeset) return "changeset";166 return "";167 }168 169 /**170 138 * Returns the OSM protocol version we use to talk to the server. 171 139 * @return protocol version, or null if not yet negotiated. … … 185 153 /** 186 154 * Initializes this component by negotiating a protocol version with the server. 187 * 188 * @exception UnknownHostException thrown, if the API host is unknown 189 * @exception SocketTimeoutException thrown, if the connection to the API host times out 190 * @exception ConnectException throw, if the connection to the API host fails 191 * @exception Exception any other exception 155 * 156 * @exception OsmApiInitializationException thrown, if an exception occurs 192 157 */ 193 158 public void initialize() throws OsmApiInitializationException { … … 238 203 239 204 /** 240 * Helper that makes an int from the first whitespace separated token in a string.241 * @param s the string242 * @return the integer represenation of the first token in the string243 * @throws OsmTransferException if the string is empty or does not represent a number244 */245 public static int parseInt(String s) throws OsmTransferException {246 StringTokenizer t = new StringTokenizer(s);247 try {248 return Integer.parseInt(t.nextToken());249 } catch (Exception x) {250 throw new OsmTransferException(tr("Cannot read numeric value from response"));251 }252 }253 254 /**255 * Helper that makes a long from the first whitespace separated token in a string.256 * @param s the string257 * @return the long represenation of the first token in the string258 * @throws OsmTransferException if the string is empty or does not represent a number259 */260 public static long parseLong(String s) throws OsmTransferException {261 StringTokenizer t = new StringTokenizer(s);262 try {263 return Long.parseLong(t.nextToken());264 } catch (Exception x) {265 throw new OsmTransferException(tr("Cannot read numeric value from response"));266 }267 }268 269 /**270 205 * Returns the base URL for API requests, including the negotiated version number. 271 206 * @return base URL string … … 293 228 public void createPrimitive(OsmPrimitive osm) throws OsmTransferException { 294 229 initialize(); 295 osm.id = parseLong(sendRequest("PUT", which(osm)+"/create", toXml(osm, true))); 296 osm.version = 1; 230 String ret = ""; 231 try { 232 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true)); 233 osm.id = Long.parseLong(ret.trim()); 234 osm.version = 1; 235 } catch(NumberFormatException e){ 236 throw new OsmTransferException(tr("unexpected format of id replied by the server, got ''{0}''", ret)); 237 } 297 238 } 298 239 … … 309 250 if (version.equals("0.5")) { 310 251 // legacy mode does not return the new object version. 311 sendRequest("PUT", which(osm)+"/" + osm.id, toXml(osm, true));252 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.id, toXml(osm, true)); 312 253 } else { 254 String ret = null; 313 255 // normal mode (0.6 and up) returns new object version. 314 osm.version = parseInt(sendRequest("PUT", which(osm)+"/" + osm.id, toXml(osm, true))); 256 try { 257 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.id, toXml(osm, true)); 258 osm.version = Integer.parseInt(ret.trim()); 259 } catch(NumberFormatException e) { 260 throw new OsmTransferException(tr("unexpected format of new version of modified primitive ''{0}'', got ''{1}''", osm.id, ret)); 261 } 315 262 } 316 263 } … … 324 271 initialize(); 325 272 // legacy mode does not require payload. normal mode (0.6 and up) requires payload for version matching. 326 sendRequest("DELETE", which(osm)+"/" + osm.id, version.equals("0.5") ? null : toXml(osm, false));273 sendRequest("DELETE", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.id, version.equals("0.5") ? null : toXml(osm, false)); 327 274 } 328 275 … … 334 281 public void createChangeset(String comment) throws OsmTransferException { 335 282 changeset = new Changeset(); 336 Main.pleaseWaitDlg.currentAction.setText(tr("Opening changeset..."));283 notifyStatusMessage(tr("Opening changeset...")); 337 284 Properties sysProp = System.getProperties(); 338 285 Object ua = sysProp.get("http.agent"); … … 349 296 public void stopChangeset() throws OsmTransferException { 350 297 initialize(); 351 Main.pleaseWaitDlg.currentAction.setText(tr("Closing changeset..."));298 notifyStatusMessage(tr("Closing changeset...")); 352 299 sendRequest("PUT", "changeset" + "/" + changeset.id + "/close", null); 353 300 changeset = null; … … 372 319 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this); 373 320 321 notifyStatusMessage(tr("Preparing...")); 374 322 for (OsmPrimitive osm : list) { 375 int progress = Main.pleaseWaitDlg.progress.getValue();376 Main.pleaseWaitDlg.currentAction.setText(tr("Preparing..."));377 323 osm.visit(duv); 378 Main.pleaseWaitDlg.progress.setValue(progress+1); 379 } 380 381 Main.pleaseWaitDlg.currentAction.setText(tr("Uploading...")); 324 notifyRelativeProgress(1); 325 } 326 notifyStatusMessage(tr("Uploading...")); 382 327 383 328 String diff = duv.getDocument(); … … 517 462 } 518 463 } 464 465 /** 466 * notifies any listeners about the current state of this API. Currently just 467 * displays the message in the global progress dialog, see {@see Main#pleaseWaitDlg} 468 * 469 * @param message a status message. 470 */ 471 protected void notifyStatusMessage(String message) { 472 Main.pleaseWaitDlg.currentAction.setText(message); 473 } 474 475 /** 476 * notifies any listeners about the current about a relative progress. Currently just 477 * increments the progress monitor in the in the global progress dialog, see {@see Main#pleaseWaitDlg} 478 * 479 * @param int the delta 480 */ 481 protected void notifyRelativeProgress(int delta) { 482 int current= Main.pleaseWaitDlg.progress.getValue(); 483 Main.pleaseWaitDlg.progress.setValue(current + delta); 484 } 519 485 } -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r1523 r1670 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.gui.ExtendedDialog; 24 import org.openstreetmap.josm.gui.ExtendedDialog; 25 25 import org.openstreetmap.josm.tools.Base64; 26 26 import org.openstreetmap.josm.tools.GBC; … … 33 33 */ 34 34 public class OsmConnection { 35 36 public static class OsmParseException extends Exception {37 public OsmParseException() {super();}38 public OsmParseException(String message, Throwable cause) {super(message, cause);}39 public OsmParseException(String message) {super(message);}40 public OsmParseException(Throwable cause) {super(cause);}41 }42 35 43 36 protected boolean cancel = false; … … 77 70 if (passwordtried || username.equals("") || password.equals("")) { 78 71 JPanel p = new JPanel(new GridBagLayout()); 79 if (!username.equals("") && !password.equals("")) 72 if (!username.equals("") && !password.equals("")) { 80 73 p.add(new JLabel(tr("Incorrect password or username.")), GBC.eop()); 74 } 81 75 p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,10,0)); 82 76 JTextField usernameField = new JTextField(username, 20); … … 92 86 p.add(savePassword, GBC.eop()); 93 87 94 int choice = new ExtendedDialog(Main.parent, 95 tr("Enter Password"), 88 int choice = new ExtendedDialog(Main.parent, 89 tr("Enter Password"), 96 90 p, 97 new String[] {tr("Login"), tr("Cancel")}, 98 new String[] {"ok.png", "cancel.png"}).getValue(); 99 91 new String[] {tr("Login"), tr("Cancel")}, 92 new String[] {"ok.png", "cancel.png"}).getValue(); 93 100 94 if (choice != 1) { 101 95 authCancelled = true; -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r1523 r1670 22 22 * Method to download OSM files from somewhere 23 23 */ 24 public DataSet parseOsm() throws SAXException, IOException { 24 @Override 25 public DataSet parseOsm() throws OsmTransferException { 25 26 try { 26 27 Main.pleaseWaitDlg.progress.setValue(0); … … 32 33 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 33 34 final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg); 34 // Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2));35 // DataSource src = new DataSource(bounds, origin);36 // data.dataSources.add(src);37 35 in.close(); 38 36 activeConnection = null; … … 41 39 if (cancel) 42 40 return null; 43 throw e;41 throw new OsmTransferException(e); 44 42 } catch (SAXException e) { 43 throw new OsmTransferException(e); 44 } catch(OsmTransferException e) { 45 45 throw e; 46 46 } catch (Exception e) { 47 47 if (cancel) 48 48 return null; 49 if (e instanceof RuntimeException) 50 throw (RuntimeException)e; 51 throw new RuntimeException(e); 49 throw new OsmTransferException(e); 52 50 } 53 51 } -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r1523 r1670 7 7 import java.io.InputStream; 8 8 9 import javax.swing.JOptionPane; 10 9 11 import org.openstreetmap.josm.Main; 10 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 14 import org.xml.sax.SAXException; 12 13 import javax.swing.JOptionPane;14 15 15 16 public class OsmServerObjectReader extends OsmServerReader { 16 17 17 public final static String TYPE_WAY = "way";18 public final static String TYPE_REL = "relation";19 public final static String TYPE_NODE = "node";20 21 18 long id; 22 Stringtype;19 OsmPrimitiveType type; 23 20 boolean full; 24 21 25 public OsmServerObjectReader(long id, Stringtype, boolean full) {22 public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) { 26 23 this.id = id; 27 24 this.type = type; … … 34 31 * @throws IOException 35 32 */ 36 public DataSet parseOsm() throws SAXException, IOException { 33 @Override 34 public DataSet parseOsm() throws OsmTransferException { 37 35 try { 38 36 Main.pleaseWaitDlg.progress.setValue(0); 39 37 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 40 38 StringBuffer sb = new StringBuffer(); 41 sb.append(type); 39 sb.append(type.getAPIName()); 42 40 sb.append("/"); 43 41 sb.append(id); 44 if (full )42 if (full && ! type.equals(OsmPrimitiveType.NODE)) { 45 43 sb.append("/full"); 44 } 46 45 47 46 final InputStream in = getInputStream(sb.toString(), Main.pleaseWaitDlg); … … 52 51 final DataSet data = osm.getDs(); 53 52 54 // Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2));55 // DataSource src = new DataSource(bounds, origin);56 // data.dataSources.add(src);57 53 if (osm.getParseNotes().length() != 0) { 58 54 JOptionPane.showMessageDialog(Main.parent, osm.getParseNotes()); … … 64 60 if (cancel) 65 61 return null; 66 throw e;62 throw new OsmTransferException(e); 67 63 } catch (SAXException e) { 64 throw new OsmTransferException(e); 65 } catch(OsmTransferException e) { 68 66 throw e; 69 67 } catch (Exception e) { 70 68 if (cancel) 71 69 return null; 72 if (e instanceof RuntimeException) 73 throw (RuntimeException)e; 74 throw new RuntimeException(e); 70 throw new OsmTransferException(e); 75 71 } 76 72 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r1664 r1670 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io. IOException;6 import java.io.BufferedReader; 7 7 import java.io.InputStream; 8 import java.io.InputStreamReader; 8 9 import java.net.HttpURLConnection; 10 import java.net.MalformedURLException; 9 11 import java.net.URL; 12 import java.util.zip.GZIPInputStream; 10 13 import java.util.zip.Inflater; 11 14 import java.util.zip.InflaterInputStream; 12 import java.util.zip.GZIPInputStream;13 15 14 16 import javax.swing.JOptionPane; … … 17 19 import org.openstreetmap.josm.data.osm.DataSet; 18 20 import org.openstreetmap.josm.gui.PleaseWaitDialog; 19 import org.xml.sax.SAXException;20 21 21 22 /** … … 39 40 * @return An reader reading the input stream (servers answer) or <code>null</code>. 40 41 */ 41 protected InputStream getInputStream(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws IOException { 42 43 // initialize API. Abort download in case of configuration or network 44 // errors 45 // 46 try { 47 api.initialize(); 48 } catch(Exception e) { 49 JOptionPane.showMessageDialog( 50 null, 51 tr( "Failed to initialize communication with the OSM server {0}.\n" 52 + "Check the server URL in your preferences and your internet connection.", 53 Main.pref.get("osm-server.url") 54 ), 55 tr("Error"), 56 JOptionPane.ERROR_MESSAGE 57 ); 58 e.printStackTrace(); 59 return null; 60 } 61 42 protected InputStream getInputStream(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws OsmTransferException { 43 api.initialize(); 62 44 urlStr = api.getBaseUrl() + urlStr; 63 45 return getInputStreamRaw(urlStr, pleaseWaitDlg); 64 46 } 65 47 66 protected InputStream getInputStreamRaw(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws IOException { 67 68 // System.out.println("download: "+urlStr); 69 URL url = new URL(urlStr); 70 activeConnection = (HttpURLConnection)url.openConnection(); 48 protected InputStream getInputStreamRaw(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws OsmTransferException { 49 URL url = null; 50 try { 51 url = new URL(urlStr); 52 } catch(MalformedURLException e) { 53 throw new OsmTransferException(e); 54 } 55 try { 56 activeConnection = (HttpURLConnection)url.openConnection(); 57 } catch(Exception e) { 58 throw new OsmTransferException(tr("Failed to open connection to API {0}", url.toExternalForm()), e); 59 } 71 60 if (cancel) { 72 61 activeConnection.disconnect(); … … 81 70 82 71 try { 72 System.out.println("GET " + url); 83 73 activeConnection.connect(); 74 } catch (Exception e) { 75 throw new OsmTransferException(tr("Couldn't connect to the osm server. Please check your internet connection."), e); 84 76 } 85 catch (Exception e) { 86 throw new IOException(tr("Couldn't connect to the osm server. Please check your internet connection.")); 77 try { 78 if (isAuthCancelled() && activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) 79 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,null,null); 80 81 if (activeConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { 82 String errorHeader = activeConnection.getHeaderField("Error"); 83 InputStream i = null; 84 i = activeConnection.getErrorStream(); 85 StringBuilder errorBody = new StringBuilder(); 86 if (i != null) { 87 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 88 String s; 89 while((s = in.readLine()) != null) { 90 errorBody.append(s); 91 errorBody.append("\n"); 92 } 93 } 94 95 throw new OsmApiException(activeConnection.getResponseCode(), errorHeader, errorBody.toString()); 96 } 97 98 String encoding = activeConnection.getContentEncoding(); 99 InputStream inputStream = new ProgressInputStream(activeConnection, pleaseWaitDlg); 100 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 101 inputStream = new GZIPInputStream(inputStream); 102 } 103 else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 104 inputStream = new InflaterInputStream(inputStream, new Inflater(true)); 105 } 106 return inputStream; 107 } catch(Exception e) { 108 if (e instanceof OsmTransferException) 109 throw (OsmTransferException)e; 110 else 111 throw new OsmTransferException(e); 112 87 113 } 88 89 if (isAuthCancelled() && activeConnection.getResponseCode() == 401)90 return null;91 if (activeConnection.getResponseCode() == 500)92 throw new IOException(tr("Server returned internal error. Try a reduced area or retry after waiting some time."));93 94 String encoding = activeConnection.getContentEncoding();95 InputStream inputStream = new ProgressInputStream(activeConnection, pleaseWaitDlg);96 if (encoding != null && encoding.equalsIgnoreCase("gzip")) {97 inputStream = new GZIPInputStream(inputStream);98 }99 else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {100 inputStream = new InflaterInputStream(inputStream, new Inflater(true));101 }102 return inputStream;103 114 } 104 115 105 public abstract DataSet parseOsm() throws SAXException, IOException;116 public abstract DataSet parseOsm() throws OsmTransferException; 106 117 107 118 } -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1664 r1670 101 101 boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 102 102 if (useChangeset && ! canUseChangeset) { 103 System.out.println(tr("WARNING: preference ' {0}' or api version {1}of dataset requires to use changesets, but API is not handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion));103 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion)); 104 104 useChangeset = false; 105 105 } -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r1640 r1670 11 11 import org.openstreetmap.josm.data.osm.Node; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 13 14 import org.openstreetmap.josm.data.osm.Relation; 14 15 import org.openstreetmap.josm.data.osm.RelationMember; … … 25 26 26 27 public final String DEFAULT_API_VERSION = "0.6"; 27 28 28 29 /** 29 30 * The counter for newly created objects. Starts at -1 and goes down. 30 31 */ 31 32 private long newIdCounter = -1; 32 33 33 34 /** 34 35 * All newly created ids and their primitive that uses it. This is a back reference … … 41 42 private String version; 42 43 private Changeset changeset; 43 44 44 45 public OsmWriter(PrintWriter out, boolean osmConform, String version) { 45 46 super(out); … … 47 48 this.version = (version == null ? DEFAULT_API_VERSION : version); 48 49 } 49 50 50 51 public void setWithBody(boolean wb) { 51 52 this.withBody = wb; … … 57 58 this.version = v; 58 59 } 59 60 60 61 public void header() { 61 62 out.println("<?xml version='1.0' encoding='UTF-8'?>"); … … 70 71 public void writeContent(DataSet ds) { 71 72 for (Node n : ds.nodes) 72 if (shouldWrite(n)) 73 if (shouldWrite(n)) { 73 74 visit(n); 75 } 74 76 for (Way w : ds.ways) 75 if (shouldWrite(w)) 77 if (shouldWrite(w)) { 76 78 visit(w); 79 } 77 80 for (Relation e : ds.relations) 78 if (shouldWrite(e)) 81 if (shouldWrite(e)) { 79 82 visit(e); 83 } 80 84 } 81 85 … … 100 104 out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'"); 101 105 if (!withBody) { 102 out.println("/>"); 106 out.println("/>"); 103 107 } else { 104 108 addTags(n, "node", true); … … 110 114 addCommon(w, "way"); 111 115 if (!withBody) { 112 out.println("/>"); 116 out.println("/>"); 113 117 } else { 114 118 out.println(">"); 115 for (Node n : w.nodes) 119 for (Node n : w.nodes) { 116 120 out.println(" <nd ref='"+getUsedId(n)+"' />"); 121 } 117 122 addTags(w, "way", false); 118 123 } … … 123 128 addCommon(e, "relation"); 124 129 if (!withBody) { 125 out.println("/>"); 130 out.println("/>"); 126 131 } else { 127 132 out.println(">"); 128 133 for (RelationMember em : e.members) { 129 134 out.print(" <member type='"); 130 out.print(Osm Api.which(em.member));135 out.print(OsmPrimitiveType.from(em.member).getAPIName()); 131 136 out.println("' ref='"+getUsedId(em.member)+"' role='" + 132 137 XmlWriter.encode(em.role == null ? "" : em.role) + "' />"); … … 160 165 private void addTags(OsmPrimitive osm, String tagname, boolean tagOpen) { 161 166 if (osm.keys != null) { 162 if (tagOpen) 167 if (tagOpen) { 163 168 out.println(">"); 164 for (Entry<String, String> e : osm.keys.entrySet()) 169 } 170 for (Entry<String, String> e : osm.keys.entrySet()) { 165 171 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 166 172 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 173 } 167 174 out.println(" </" + tagname + ">"); 168 } else if (tagOpen) 175 } else if (tagOpen) { 169 176 out.println(" />"); 170 else177 } else { 171 178 out.println(" </" + tagname + ">"); 179 } 172 180 } 173 181 … … 180 188 out.print(" <"+tagname); 181 189 if (id != 0) { 182 out.print(" id='"+getUsedId(osm)+"'");190 out.print(" id='"+getUsedId(osm)+"'"); 183 191 } 184 192 if (!osmConform) { 185 193 String action = null; 186 if (osm.deleted) 194 if (osm.deleted) { 187 195 action = "delete"; 188 else if (osm.modified) 196 } else if (osm.modified) { 189 197 action = "modify"; 190 if (action != null) 198 } 199 if (action != null) { 191 200 out.print(" action='"+action+"'"); 201 } 192 202 } 193 203 if (!osm.isTimestampEmpty()) { … … 199 209 } 200 210 out.print(" visible='"+osm.visible+"'"); 201 if (osm.version != -1) 211 if (osm.version != -1) { 202 212 out.print(" version='"+osm.version+"'"); 203 if (this.changeset != null && this.changeset.id != 0) 213 } 214 if (this.changeset != null && this.changeset.id != 0) { 204 215 out.print(" changeset='"+this.changeset.id+"'" ); 205 } 206 216 } 217 } 218 207 219 public void close() { 208 220 out.close(); 209 221 } 210 222 211 223 public void flush() { 212 224 out.flush(); -
trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java
r1169 r1670 22 22 private PleaseWaitDialog pleaseWaitDlg; 23 23 24 public class OsmServerException extends IOException { 25 private OsmServerException(String e) { 26 super(e); 27 } 28 } 29 30 public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws IOException, OsmServerException { 24 public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws OsmTransferException { 31 25 this.connection = con; 32 26 … … 35 29 } catch (IOException e) { 36 30 if (con.getHeaderField("Error") != null) 37 throw new Osm ServerException(tr(con.getHeaderField("Error")));38 throw e;31 throw new OsmTransferException(tr(con.getHeaderField("Error"))); 32 throw new OsmTransferException(e); 39 33 } 40 34 … … 43 37 if (pleaseWaitDlg == null) 44 38 return; 45 if (contentLength > 0) 39 if (contentLength > 0) { 46 40 pleaseWaitDlg.progress.setMaximum(contentLength); 47 else41 } else { 48 42 pleaseWaitDlg.progress.setMaximum(0); 43 } 49 44 pleaseWaitDlg.progress.setValue(0); 50 45 } … … 56 51 @Override public int read(byte[] b, int off, int len) throws IOException { 57 52 int read = in.read(b, off, len); 58 if (read != -1) 53 if (read != -1) { 59 54 advanceTicker(read); 55 } 60 56 return read; 61 57 } … … 63 59 @Override public int read() throws IOException { 64 60 int read = in.read(); 65 if (read != -1) 61 if (read != -1) { 66 62 advanceTicker(1); 63 } 67 64 return read; 68 65 } … … 76 73 return; 77 74 78 if (pleaseWaitDlg.progress.getMaximum() == 0 && connection.getContentLength() != -1) 75 if (pleaseWaitDlg.progress.getMaximum() == 0 && connection.getContentLength() != -1) { 79 76 pleaseWaitDlg.progress.setMaximum(connection.getContentLength()); 77 } 80 78 81 79 readSoFar += amount; … … 89 87 String cur = pleaseWaitDlg.currentAction.getText(); 90 88 int i = cur.indexOf(' '); 91 if (i != -1) 89 if (i != -1) { 92 90 cur = cur.substring(0, i) + progStr; 93 else91 } else { 94 92 cur += progStr; 93 } 95 94 pleaseWaitDlg.currentAction.setText(cur); 96 95 }
Note:
See TracChangeset
for help on using the changeset viewer.
