Changeset 30234 in osm for applications/editors/josm
- Timestamp:
- 2014-01-27T00:58:04+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/build.xml
r30131 r30234 5 5 <property name="commit.message" value="[josm_geochat] copypaste from keyboard, font size advanced parameters"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="6 484"/>7 <property name="plugin.main.version" value="6756"/> 8 8 9 9 <property name="plugin.author" value="Ilya Zverev"/> -
applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java
r29854 r30234 15 15 import java.util.Set; 16 16 17 import org.json.JSONArray; 18 import org.json.JSONException; 19 import org.json.JSONObject; 17 import javax.json.JsonArray; 18 import javax.json.JsonException; 19 import javax.json.JsonObject; 20 20 21 import org.openstreetmap.josm.Main; 21 22 import org.openstreetmap.josm.data.coor.CoordinateFormat; … … 92 93 String query = "whoami&uid=" + uid; 93 94 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 94 public void processJson( J SONObject json ) {95 if( json != null && json. has("name"))95 public void processJson( JsonObject json ) { 96 if( json != null && json.get("name") != null ) 96 97 login(uid, json.getString("name")); 97 98 else if( userName != null && userName.length() > 1 ) … … 143 144 + nameAttr; 144 145 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 145 public void processJson( J SONObject json ) {146 public void processJson( JsonObject json ) { 146 147 if( json == null ) 147 148 fireLoginFailed(tr("Could not get server response, check logs")); 148 else if( json. has("error"))149 else if( json.get("error") != null ) 149 150 fireLoginFailed(tr("Failed to login as {0}:", userName) + "\n" + json.getString("error")); 150 else if( !json.has("uid"))151 else if( json.get("uid") == null) 151 152 fireLoginFailed(tr("The server did not return user ID")); 152 153 else { 153 String name = json. has("name")? json.getString("name") : userName;154 String name = json.get("name") != null ? json.getString("name") : userName; 154 155 login(json.getInt("uid"), name); 155 156 } … … 190 191 String query = "logout&uid=" + userId; 191 192 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 192 public void processJson( J SONObject json ) {193 if( json != null && json. has("message")) {193 public void processJson( JsonObject json ) { 194 if( json != null && json.get("message") != null) { 194 195 logoutIntl(); 195 196 } … … 245 246 query += "&to=" + URLEncoder.encode(targetUser, "UTF8"); 246 247 JsonQueryUtil.queryAsync(query, new JsonQueryCallback() { 247 public void processJson( J SONObject json ) {248 public void processJson( JsonObject json ) { 248 249 if( json == null ) 249 250 fireMessageFailed(tr("Could not get server response, check logs")); 250 else if( json. has("error"))251 else if( json.get("error") != null ) 251 252 fireMessageFailed(tr("Failed to send message:") + "\n" + json.getString("error")); 252 253 } … … 356 357 + "&lon=" + pos.lonToString(CoordinateFormat.DECIMAL_DEGREES) 357 358 + "&uid=" + userId + "&last=" + lastId; 358 J SONObject json;359 JsonObject json; 359 360 try { 360 361 json = JsonQueryUtil.query(query); … … 366 367 // fireLoginFailed(tr("Could not get server response, check logs")); 367 368 // logoutIntl(); // todo: uncomment? 368 } else if( json. has("error")) {369 } else if( json.get("error") != null) { 369 370 fireLoginFailed(tr("Failed to get messages as {0}:", userName) + "\n" + json.getString("error")); 370 371 logoutIntl(); 371 372 } else { 372 if( json. has("users")) {373 Map<String, LatLon> users = parseUsers(json.getJ SONArray("users"));373 if( json.get("users") != null) { 374 Map<String, LatLon> users = parseUsers(json.getJsonArray("users")); 374 375 for( ChatServerConnectionListener listener : listeners ) 375 376 listener.updateUsers(users); 376 377 } 377 if( json. has("messages")) {378 List<ChatMessage> messages = parseMessages(json.getJ SONArray("messages"), false);378 if( json.get("messages") != null) { 379 List<ChatMessage> messages = parseMessages(json.getJsonArray("messages"), false); 379 380 for( ChatMessage m : messages ) 380 381 if( m.getId() > lastId ) … … 383 384 listener.receivedMessages(needReset, messages); 384 385 } 385 if( json. has("private")) {386 List<ChatMessage> messages = parseMessages(json.getJ SONArray("private"), true);386 if( json.get("private") != null) { 387 List<ChatMessage> messages = parseMessages(json.getJsonArray("private"), true); 387 388 for( ChatMessage m : messages ) 388 389 if( m.getId() > lastId ) … … 396 397 } 397 398 398 private List<ChatMessage> parseMessages( J SONArray messages, boolean priv ) {399 private List<ChatMessage> parseMessages( JsonArray messages, boolean priv ) { 399 400 List<ChatMessage> result = new ArrayList<ChatMessage>(); 400 for( int i = 0; i < messages. length(); i++ ) {401 for( int i = 0; i < messages.size(); i++ ) { 401 402 try { 402 JSONObject msg = messages.getJSONObject(i);403 long id = msg.get Long("id");404 double lat = msg.get Double("lat");405 double lon = msg.get Double("lon");406 long timeStamp = msg.get Long("timestamp");403 JsonObject msg = messages.getJsonObject(i); 404 long id = msg.getJsonNumber("id").longValue(); 405 double lat = msg.getJsonNumber("lat").doubleValue(); 406 double lon = msg.getJsonNumber("lon").doubleValue(); 407 long timeStamp = msg.getJsonNumber("timestamp").longValue(); 407 408 String author = msg.getString("author"); 408 409 String message = msg.getString("message"); … … 411 412 incoming, message, new Date(timeStamp * 1000)); 412 413 cm.setPrivate(priv); 413 if( msg. has("recipient")&& !incoming )414 if( msg.get("recipient") != null && !incoming ) 414 415 cm.setRecipient(msg.getString("recipient")); 415 416 result.add(cm); 416 } catch( J SONException e ) {417 } catch( JsonException e ) { 417 418 // do nothing, just skip this message 418 419 } … … 421 422 } 422 423 423 private Map<String, LatLon> parseUsers( J SONArray users ) {424 private Map<String, LatLon> parseUsers( JsonArray users ) { 424 425 Map<String, LatLon> result = new HashMap<String, LatLon>(); 425 for( int i = 0; i < users. length(); i++ ) {426 for( int i = 0; i < users.size(); i++ ) { 426 427 try { 427 JSONObject user = users.getJSONObject(i);428 JsonObject user = users.getJsonObject(i); 428 429 String name = user.getString("user"); 429 double lat = user.get Double("lat");430 double lon = user.get Double("lon");430 double lat = user.getJsonNumber("lat").doubleValue(); 431 double lon = user.getJsonNumber("lon").doubleValue(); 431 432 result.put(name, new LatLon(lat, lon)); 432 } catch( J SONException e ) {433 } catch( JsonException e ) { 433 434 // do nothing, just skip this user 434 435 } -
applications/editors/josm/plugins/geochat/src/geochat/JsonQueryCallback.java
r29584 r30234 2 2 package geochat; 3 3 4 import org.json.JSONObject;4 import javax.json.JsonObject; 5 5 6 6 /** … … 17 17 * @param json JSON parsed response or null if the query was unsuccessful. 18 18 */ 19 void processJson( J SONObject json );19 void processJson( JsonObject json ); 20 20 } -
applications/editors/josm/plugins/geochat/src/geochat/JsonQueryUtil.java
r29584 r30234 8 8 import java.net.MalformedURLException; 9 9 import java.net.URL; 10 import org.json.JSONException; 11 import org.json.JSONObject; 12 import org.json.JSONTokener; 10 11 import javax.json.Json; 12 import javax.json.JsonException; 13 import javax.json.JsonObject; 14 13 15 import org.openstreetmap.josm.Main; 14 16 … … 23 25 * Query the server synchronously. 24 26 * @param query Query string, starting with action. Example: <tt>get&lat=1.0&lon=-2.0&uid=12345</tt> 25 * @return Parsed J SONObject if the query was successful, <tt>null</tt> otherwise.27 * @return Parsed JsonObject if the query was successful, <tt>null</tt> otherwise. 26 28 * @throws IOException There was a problem connecting to the server or parsing JSON. 27 29 */ 28 public static J SONObject query( String query ) throws IOException {30 public static JsonObject query( String query ) throws IOException { 29 31 try { 30 32 String serverURL = Main.pref.get("geochat.server", "http://zverik.dev.openstreetmap.org/osmochat.php?action="); … … 40 42 throw new IOException("Empty response"); 41 43 try { 42 JSONTokener tokener = new JSONTokener(inp); 43 JSONObject result = new JSONObject(tokener); 44 return result; 45 } catch( JSONException e ) { 44 return Json.createReader(inp).readObject(); 45 } catch( JsonException e ) { 46 46 throw new IOException("Failed to parse JSON: " + e.getMessage()); 47 47 } finally { … … 75 75 76 76 private void doRealRun() { 77 JSONObject obj;77 JsonObject obj; 78 78 try { 79 79 obj = query(query); -
applications/editors/josm/plugins/livegps/build.xml
r30131 r30234 2 2 <project name="livegps" default="dist" basedir="."> 3 3 <property name="commit.message" value="Changed the constructor signature of the plugin main class"/> 4 <property name="plugin.main.version" value="6 484"/>4 <property name="plugin.main.version" value="6756"/> 5 5 6 6 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r29769 r30234 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 4 6 5 import java.beans.PropertyChangeEvent; … … 9 8 import java.io.IOException; 10 9 import java.io.InputStreamReader; 10 import java.io.StringReader; 11 11 import java.net.InetAddress; 12 12 import java.net.Socket; … … 14 14 import java.util.List; 15 15 16 import javax.json.Json; 17 import javax.json.JsonException; 18 import javax.json.JsonNumber; 19 import javax.json.JsonObject; 20 16 21 import org.openstreetmap.josm.Main; 17 18 import org.json.JSONObject;19 import org.json.JSONException;20 22 21 23 public class LiveGpsAcquirer implements Runnable { … … 41 43 */ 42 44 public LiveGpsAcquirer() { 43 super();44 45 45 46 gpsdHost = Main.pref.get(C_HOST, DEFAULT_HOST); … … 77 78 * @param statusMessage the status message. 78 79 */ 79 public void fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus status, 80 String statusMessage) { 80 public void fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus status, String statusMessage) { 81 81 PropertyChangeEvent event = new PropertyChangeEvent(this, "gpsstatus", 82 82 null, new LiveGpsStatus(status, statusMessage)); … … 97 97 */ 98 98 public void fireGpsDataChangeEvent(LiveGpsData oldData, LiveGpsData newData) { 99 PropertyChangeEvent event = new PropertyChangeEvent(this, "gpsdata", 100 oldData, newData); 99 PropertyChangeEvent event = new PropertyChangeEvent(this, "gpsdata", oldData, newData); 101 100 102 101 if (!event.equals(lastDataEvent)) { … … 124 123 while (!shutdownFlag) { 125 124 126 127 125 while (!connected) { 126 try { 128 127 connect(); 129 } catch (IOException iox) { 130 fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed")); 131 try { 132 Thread.sleep(1000); 133 } catch (InterruptedException ignore) {} 134 } 135 } 136 137 assert (connected); 138 139 try { 140 String line; 141 142 // <FIXXME date="23.06.2007" author="cdaller"> 143 // TODO this read is blocking if gps is connected but has no 144 // fix, so gpsd does not send positions 145 line = gpsdReader.readLine(); 146 // </FIXXME> 147 if (line == null) 148 throw new IOException(); 149 150 if (JSONProtocol == true) 151 gpsData = ParseJSON(line); 152 else 153 gpsData = ParseOld(line); 154 155 if (gpsData == null) 156 continue; 157 158 fireGpsDataChangeEvent(oldGpsData, gpsData); 159 oldGpsData = gpsData; 128 } catch (IOException iox) { 129 fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed")); 130 try { 131 Thread.sleep(1000); 132 } catch (InterruptedException ignore) { 133 134 } 135 } 136 } 137 138 assert (connected); 139 140 try { 141 String line; 142 143 // <FIXXME date="23.06.2007" author="cdaller"> 144 // TODO this read is blocking if gps is connected but has no 145 // fix, so gpsd does not send positions 146 line = gpsdReader.readLine(); 147 // </FIXXME> 148 if (line == null) 149 throw new IOException(); 150 151 if (JSONProtocol == true) 152 gpsData = ParseJSON(line); 153 else 154 gpsData = ParseOld(line); 155 156 if (gpsData == null) 157 continue; 158 159 fireGpsDataChangeEvent(oldGpsData, gpsData); 160 oldGpsData = gpsData; 160 161 } catch (IOException iox) { 161 System.out.println("LiveGps: lost connection to gpsd");162 Main.warn("LiveGps: lost connection to gpsd"); 162 163 fireGpsStatusChangeEvent( 163 164 LiveGpsStatus.GpsStatus.CONNECTION_FAILED, 164 165 tr("Connection Failed")); 165 166 disconnect(); 166 167 try { 167 168 Thread.sleep(1000); … … 171 172 } 172 173 173 System.out.println("LiveGps: Disconnected from gpsd");174 Main.info("LiveGps: Disconnected from gpsd"); 174 175 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.DISCONNECTED, 175 176 tr("Not connected")); 176 177 disconnect(); 177 178 } 178 179 … … 182 183 183 184 private void connect() throws IOException { 184 J SONObject greeting;185 JsonObject greeting; 185 186 String line, type, release; 186 187 187 System.out.println("LiveGps: trying to connect to gpsd at " + gpsdHost + ":" + gpsdPort);188 Main.info("LiveGps: trying to connect to gpsd at " + gpsdHost + ":" + gpsdPort); 188 189 fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 189 190 … … 194 195 break; 195 196 } catch (IOException e) { 196 System.out.println("LiveGps: Could not open connection to gpsd: " + e);197 Main.warn("LiveGps: Could not open connection to gpsd: " + e); 197 198 gpsdSocket = null; 198 199 } … … 213 214 214 215 try { 215 greeting = new JSONObject(line);216 greeting = Json.createReader(new StringReader(line)).readObject(); 216 217 type = greeting.getString("class"); 217 218 if (type.equals("VERSION")) { 218 219 release = greeting.getString("release"); 219 System.out.println("LiveGps: Connected to gpsd " + release);220 Main.info("LiveGps: Connected to gpsd " + release); 220 221 } else 221 System.out.println("LiveGps: Unexpected JSON in gpsd greeting: " + line);222 } catch (J SONException jex) {222 Main.info("LiveGps: Unexpected JSON in gpsd greeting: " + line); 223 } catch (JsonException jex) { 223 224 if (line.startsWith("GPSD,")) { 224 225 connected = true; 225 226 JSONProtocol = false; 226 System.out.println("LiveGps: Connected to old gpsd protocol version.");227 Main.info("LiveGps: Connected to old gpsd protocol version."); 227 228 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTED, tr("Connected")); 228 229 } … … 230 231 231 232 if (JSONProtocol == true) { 232 JSONObject Watch = new JSONObject(); 233 try { 234 Watch.put("enable", true); 235 Watch.put("json", true); 236 } catch (JSONException je) {} 233 JsonObject Watch = Json.createObjectBuilder() 234 .add("enable", true) 235 .add("json", true) 236 .build(); 237 237 238 238 String Request = "?WATCH=" + Watch.toString() + ";\n"; … … 245 245 246 246 private void disconnect() { 247 248 249 247 assert(gpsdSocket != null); 248 249 connected = false; 250 250 251 251 try { 252 253 254 255 System.out.println("LiveGps: Unable to close socket; reconnection may not be possible");256 252 gpsdSocket.close(); 253 gpsdSocket = null; 254 } catch (Exception e) { 255 Main.warn("LiveGps: Unable to close socket; reconnection may not be possible"); 256 } 257 257 } 258 258 259 259 private LiveGpsData ParseJSON(String line) { 260 J SONObject report;260 JsonObject report; 261 261 String type; 262 262 double lat = 0; … … 268 268 269 269 try { 270 report = new JSONObject(line);270 report = Json.createReader(new StringReader(line)).readObject(); 271 271 type = report.getString("class"); 272 } catch (J SONException jex) {273 System.out.println("LiveGps: line read from gpsd is not a JSON object:" + line);272 } catch (JsonException jex) { 273 Main.warn("LiveGps: line read from gpsd is not a JSON object:" + line); 274 274 return null; 275 275 } … … 278 278 279 279 try { 280 lat = report.getDouble("lat"); 281 lon = report.getDouble("lon"); 282 speed = (new Float(report.getDouble("speed"))).floatValue(); 283 course = (new Float(report.getDouble("track"))).floatValue(); 284 if (report.has("epx")) 285 epx = (new Float(report.getDouble("epx"))).floatValue(); 286 if (report.has("epy")) 287 epy = (new Float(report.getDouble("epy"))).floatValue(); 280 lat = report.getJsonNumber("lat").doubleValue(); 281 lon = report.getJsonNumber("lon").doubleValue(); 282 speed = (new Float(report.getJsonNumber("speed").doubleValue())).floatValue(); 283 course = (new Float(report.getJsonNumber("track").doubleValue())).floatValue(); 284 JsonNumber epxJson = report.getJsonNumber("epx"); 285 if (epxJson != null) 286 epx = (new Float(epxJson.doubleValue())).floatValue(); 287 JsonNumber epyJson = report.getJsonNumber("epy"); 288 if (epyJson != null) 289 epy = (new Float(epyJson.doubleValue())).floatValue(); 288 290 289 291 return new LiveGpsData(lat, lon, course, speed, epx, epy); 290 } catch (JSONException je) {} 292 } catch (JsonException je) { 293 Main.debug(je.getMessage()); 294 } 291 295 292 296 return null;
Note:
See TracChangeset
for help on using the changeset viewer.