Ignore:
Timestamp:
2014-01-27T00:58:04+01:00 (11 years ago)
Author:
donvip
Message:

[josm_geochat, josm_livegps] update to JOSM 6756

Location:
applications/editors/josm/plugins/geochat/src/geochat
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java

    r29854 r30234  
    1515import java.util.Set;
    1616
    17 import org.json.JSONArray;
    18 import org.json.JSONException;
    19 import org.json.JSONObject;
     17import javax.json.JsonArray;
     18import javax.json.JsonException;
     19import javax.json.JsonObject;
     20
    2021import org.openstreetmap.josm.Main;
    2122import org.openstreetmap.josm.data.coor.CoordinateFormat;
     
    9293            String query = "whoami&uid=" + uid;
    9394            JsonQueryUtil.queryAsync(query, new JsonQueryCallback() {
    94                 public void processJson( JSONObject json ) {
    95                     if( json != null && json.has("name") )
     95                public void processJson( JsonObject json ) {
     96                    if( json != null && json.get("name") != null )
    9697                        login(uid, json.getString("name"));
    9798                    else if( userName != null && userName.length() > 1 )
     
    143144                    + nameAttr;
    144145            JsonQueryUtil.queryAsync(query, new JsonQueryCallback() {
    145                 public void processJson( JSONObject json ) {
     146                public void processJson( JsonObject json ) {
    146147                    if( json == null )
    147148                        fireLoginFailed(tr("Could not get server response, check logs"));
    148                     else if( json.has("error") )
     149                    else if( json.get("error") != null )
    149150                        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)
    151152                        fireLoginFailed(tr("The server did not return user ID"));
    152153                    else {
    153                         String name = json.has("name") ? json.getString("name") : userName;
     154                        String name = json.get("name") != null ? json.getString("name") : userName;
    154155                        login(json.getInt("uid"), name);
    155156                    }
     
    190191        String query = "logout&uid=" + userId;
    191192        JsonQueryUtil.queryAsync(query, new JsonQueryCallback() {
    192             public void processJson( JSONObject json ) {
    193                 if( json != null && json.has("message") ) {
     193            public void processJson( JsonObject json ) {
     194                if( json != null && json.get("message") != null) {
    194195                    logoutIntl();
    195196                }
     
    245246                    query += "&to=" + URLEncoder.encode(targetUser, "UTF8");
    246247            JsonQueryUtil.queryAsync(query, new JsonQueryCallback() {
    247                 public void processJson( JSONObject json ) {
     248                public void processJson( JsonObject json ) {
    248249                    if( json == null )
    249250                        fireMessageFailed(tr("Could not get server response, check logs"));
    250                     else if( json.has("error") )
     251                    else if( json.get("error") != null )
    251252                        fireMessageFailed(tr("Failed to send message:") + "\n" + json.getString("error"));
    252253                }
     
    356357                    + "&lon=" + pos.lonToString(CoordinateFormat.DECIMAL_DEGREES)
    357358                    + "&uid=" + userId + "&last=" + lastId;
    358             JSONObject json;
     359            JsonObject json;
    359360            try {
    360361                json = JsonQueryUtil.query(query);
     
    366367//              fireLoginFailed(tr("Could not get server response, check logs"));
    367368//              logoutIntl(); // todo: uncomment?
    368             } else if( json.has("error") ) {
     369            } else if( json.get("error") != null) {
    369370                fireLoginFailed(tr("Failed to get messages as {0}:", userName) + "\n" + json.getString("error"));
    370371                logoutIntl();
    371372            } else {
    372                 if( json.has("users") ) {
    373                     Map<String, LatLon> users = parseUsers(json.getJSONArray("users"));
     373                if( json.get("users") != null) {
     374                    Map<String, LatLon> users = parseUsers(json.getJsonArray("users"));
    374375                    for( ChatServerConnectionListener listener : listeners )
    375376                        listener.updateUsers(users);
    376377                }
    377                 if( json.has("messages") ) {
    378                     List<ChatMessage> messages = parseMessages(json.getJSONArray("messages"), false);
     378                if( json.get("messages") != null) {
     379                    List<ChatMessage> messages = parseMessages(json.getJsonArray("messages"), false);
    379380                    for( ChatMessage m : messages )
    380381                        if( m.getId() > lastId )
     
    383384                        listener.receivedMessages(needReset, messages);
    384385                }
    385                 if( json.has("private") ) {
    386                     List<ChatMessage> messages = parseMessages(json.getJSONArray("private"), true);
     386                if( json.get("private") != null) {
     387                    List<ChatMessage> messages = parseMessages(json.getJsonArray("private"), true);
    387388                    for( ChatMessage m : messages )
    388389                        if( m.getId() > lastId )
     
    396397        }
    397398
    398         private List<ChatMessage> parseMessages( JSONArray messages, boolean priv ) {
     399        private List<ChatMessage> parseMessages( JsonArray messages, boolean priv ) {
    399400            List<ChatMessage> result = new ArrayList<ChatMessage>();
    400             for( int i = 0; i < messages.length(); i++ ) {
     401            for( int i = 0; i < messages.size(); i++ ) {
    401402                try {
    402                     JSONObject msg = messages.getJSONObject(i);
    403                     long id = msg.getLong("id");
    404                     double lat = msg.getDouble("lat");
    405                     double lon = msg.getDouble("lon");
    406                     long timeStamp = msg.getLong("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();
    407408                    String author = msg.getString("author");
    408409                    String message = msg.getString("message");
     
    411412                            incoming, message, new Date(timeStamp * 1000));
    412413                    cm.setPrivate(priv);
    413                     if( msg.has("recipient") && !incoming )
     414                    if( msg.get("recipient") != null && !incoming )
    414415                        cm.setRecipient(msg.getString("recipient"));
    415416                    result.add(cm);
    416                 } catch( JSONException e ) {
     417                } catch( JsonException e ) {
    417418                    // do nothing, just skip this message
    418419                }
     
    421422        }
    422423
    423         private Map<String, LatLon> parseUsers( JSONArray users ) {
     424        private Map<String, LatLon> parseUsers( JsonArray users ) {
    424425            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++ ) {
    426427                try {
    427                     JSONObject user = users.getJSONObject(i);
     428                        JsonObject user = users.getJsonObject(i);
    428429                    String name = user.getString("user");
    429                     double lat = user.getDouble("lat");
    430                     double lon = user.getDouble("lon");
     430                    double lat = user.getJsonNumber("lat").doubleValue();
     431                    double lon = user.getJsonNumber("lon").doubleValue();
    431432                    result.put(name, new LatLon(lat, lon));
    432                 } catch( JSONException e ) {
     433                } catch( JsonException e ) {
    433434                    // do nothing, just skip this user
    434435                }
  • applications/editors/josm/plugins/geochat/src/geochat/JsonQueryCallback.java

    r29584 r30234  
    22package geochat;
    33
    4 import org.json.JSONObject;
     4import javax.json.JsonObject;
    55
    66/**
     
    1717     * @param json JSON parsed response or null if the query was unsuccessful.
    1818     */
    19     void processJson( JSONObject json );
     19    void processJson( JsonObject json );
    2020}
  • applications/editors/josm/plugins/geochat/src/geochat/JsonQueryUtil.java

    r29584 r30234  
    88import java.net.MalformedURLException;
    99import java.net.URL;
    10 import org.json.JSONException;
    11 import org.json.JSONObject;
    12 import org.json.JSONTokener;
     10
     11import javax.json.Json;
     12import javax.json.JsonException;
     13import javax.json.JsonObject;
     14
    1315import org.openstreetmap.josm.Main;
    1416
     
    2325     * Query the server synchronously.
    2426     * @param query Query string, starting with action. Example: <tt>get&lat=1.0&lon=-2.0&uid=12345</tt>
    25      * @return Parsed JSONObject if the query was successful, <tt>null</tt> otherwise.
     27     * @return Parsed JsonObject if the query was successful, <tt>null</tt> otherwise.
    2628     * @throws IOException There was a problem connecting to the server or parsing JSON.
    2729     */
    28     public static JSONObject query( String query ) throws IOException {
     30    public static JsonObject query( String query ) throws IOException {
    2931        try {
    3032            String serverURL = Main.pref.get("geochat.server", "http://zverik.dev.openstreetmap.org/osmochat.php?action=");
     
    4042                throw new IOException("Empty response");
    4143            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 ) {
    4646                throw new IOException("Failed to parse JSON: " + e.getMessage());
    4747            } finally {
     
    7575
    7676    private void doRealRun() {
    77         JSONObject obj;
     77        JsonObject obj;
    7878        try {
    7979            obj = query(query);
Note: See TracChangeset for help on using the changeset viewer.