Example usage for org.json JSONException getLocalizedMessage

List of usage examples for org.json JSONException getLocalizedMessage

Introduction

In this page you can find the example usage for org.json JSONException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.soomla.levelup.LevelUp.java

private static void applyGatesStateToJSON(JSONObject modelJSON, JSONObject stateJSON) {
    JSONObject gatesStateJSON = new JSONObject();
    HashMap<String, JSONObject> gates = getGates(modelJSON);
    for (JSONObject gateJSON : gates.values()) {
        JSONObject gateValuesJSON = new JSONObject();
        try {//  w  w  w .jav  a 2 s  .  c o  m
            String gateId = gateJSON.getString("itemId");
            gateValuesJSON.put("open", GateStorage.isOpen(gateId));

            gatesStateJSON.put(gateId, gateValuesJSON);
        } catch (JSONException e) {
            SoomlaUtils.LogDebug(TAG, "Unable to get Gates state: " + e.getLocalizedMessage());
        }
    }

    try {
        stateJSON.put("gates", gatesStateJSON);
    } catch (JSONException e) {
        SoomlaUtils.LogDebug(TAG, "Unable to set Gates state: " + e.getLocalizedMessage());
    }
}

From source file:com.soomla.levelup.LevelUp.java

private static void applyWorldsStateToJSON(JSONObject modelJSON, JSONObject stateJSON) {
    JSONObject worldsStateJSON = new JSONObject();
    JSONObject levelsStateJSON = new JSONObject();

    HashMap<String, JSONObject> worlds = getWorlds(modelJSON);
    for (JSONObject worldJSON : worlds.values()) {
        JSONObject worldValuesJSON = new JSONObject();
        try {/*w ww . j av a 2 s .co m*/
            String worldId = worldJSON.getString("itemId");
            worldValuesJSON.put("completed", WorldStorage.isCompleted(worldId));
            worldValuesJSON.put("assignedReward", WorldStorage.getAssignedReward(worldId));

            worldsStateJSON.put(worldId, worldValuesJSON);

            if (worldJSON.getString("className").equals("Level")) {
                JSONObject levelValuesJSON = new JSONObject();
                levelValuesJSON.put("started", LevelStorage.getTimesStarted(worldId));
                levelValuesJSON.put("played", LevelStorage.getTimesPlayed(worldId));
                levelValuesJSON.put("timesCompleted", LevelStorage.getTimesCompleted(worldId));
                levelValuesJSON.put("slowest", LevelStorage.getSlowestDurationMillis(worldId));
                levelValuesJSON.put("fastest", LevelStorage.getFastestDurationMillis(worldId));

                levelsStateJSON.put(worldId, levelValuesJSON);
            }
        } catch (JSONException e) {
            SoomlaUtils.LogDebug(TAG, "Unable to get Worlds state: " + e.getLocalizedMessage());
        }
    }

    try {
        stateJSON.put("worlds", worldsStateJSON);
        stateJSON.put("levels", levelsStateJSON);
    } catch (JSONException e) {
        SoomlaUtils.LogDebug(TAG, "Unable to set Worlds state: " + e.getLocalizedMessage());
    }
}

From source file:com.soomla.levelup.LevelUp.java

private static void applyMissionsStateToJSON(JSONObject modelJSON, JSONObject stateJSON) {
    JSONObject missionsStateJSON = new JSONObject();
    HashMap<String, JSONObject> missions = getMissions(modelJSON);
    for (JSONObject missionJSON : missions.values()) {
        JSONObject missionValuesJSON = new JSONObject();
        try {/*w ww .ja v a 2  s .c  o m*/
            String missionId = missionJSON.getString("itemId");
            missionValuesJSON.put("timesCompleted", MissionStorage.getTimesCompleted(missionId));

            missionsStateJSON.put(missionId, missionValuesJSON);
        } catch (JSONException e) {
            SoomlaUtils.LogDebug(TAG, "Unable to get Missions state: " + e.getLocalizedMessage());
        }
    }

    try {
        stateJSON.put("missions", missionsStateJSON);
    } catch (JSONException e) {
        SoomlaUtils.LogDebug(TAG, "Unable to set Missions state: " + e.getLocalizedMessage());
    }
}

From source file:com.soomla.levelup.LevelUp.java

private static void applyScoresStateToJSON(JSONObject modelJSON, JSONObject stateJSON) {
    JSONObject scoresStateJSON = new JSONObject();
    HashMap<String, JSONObject> scores = getScores(modelJSON);
    for (JSONObject scoreJSON : scores.values()) {
        JSONObject scoreValuesJSON = new JSONObject();
        try {// ww w. j a  va2s  . c om
            String scoreId = scoreJSON.getString("itemId");
            scoreValuesJSON.put("latest", ScoreStorage.getLatestScore(scoreId));
            scoreValuesJSON.put("record", ScoreStorage.getRecordScore(scoreId));

            scoresStateJSON.put(scoreId, scoreValuesJSON);
        } catch (JSONException e) {
            SoomlaUtils.LogDebug(TAG, "Unable to get Scores state: " + e.getLocalizedMessage());
        }
    }

    try {
        stateJSON.put("scores", scoresStateJSON);
    } catch (JSONException e) {
        SoomlaUtils.LogDebug(TAG, "Unable to set Scores state: " + e.getLocalizedMessage());
    }
}

From source file:com.soomla.levelup.LevelUp.java

private static boolean resetStateFromJSON(JSONObject state, String targetListName,
        IItemStateApplier stateApplier) {
    if (!state.has(targetListName)) {
        return true;
    }/*from w  ww. ja  v  a2s .  c  om*/

    SoomlaUtils.LogDebug(TAG, "Resetting state for " + targetListName);

    try {
        JSONObject itemsJSON = state.getJSONObject(targetListName);
        Iterator keysIter = itemsJSON.keys();
        while (keysIter.hasNext()) {
            String itemId = (String) keysIter.next();
            JSONObject itemValuesJSON = itemsJSON.getJSONObject(itemId);
            if (!stateApplier.applyState(itemId, itemValuesJSON)) {
                return false;
            }
        }
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG,
                "Unable to set state for " + targetListName + ". error: " + e.getLocalizedMessage());
        return false;
    }

    return true;
}

From source file:com.soomla.levelup.LevelUp.java

private static boolean resetGatesStateFromJSON(JSONObject state) {
    return resetStateFromJSON(state, "gates", new IItemStateApplier() {
        @Override// ww w  .  ja  v a2  s. co  m
        public boolean applyState(String itemId, JSONObject itemValuesJSON) {
            if (itemValuesJSON.has("open")) {
                try {
                    boolean openState = itemValuesJSON.getBoolean("open");
                    GateStorage.setOpen(itemId, openState, false);
                } catch (JSONException e) {
                    SoomlaUtils.LogError(TAG,
                            "Unable to set state for gate " + itemId + ". error: " + e.getLocalizedMessage());
                    return false;
                }
            }
            return true;
        }
    });
}

From source file:com.soomla.levelup.LevelUp.java

private static boolean resetWorldsStateFromJSON(JSONObject state) {
    boolean worldsApplyState = resetStateFromJSON(state, "worlds", new IItemStateApplier() {
        @Override/* w w  w  . j  a v  a  2  s .co  m*/
        public boolean applyState(String itemId, JSONObject itemValuesJSON) {
            try {
                if (itemValuesJSON.has("completed")) {
                    boolean completedState = itemValuesJSON.getBoolean("completed");
                    WorldStorage.setCompleted(itemId, completedState, false);
                }

                if (itemValuesJSON.has("assignedReward")) {
                    String assignedRewardId = itemValuesJSON.getString("assignedReward");
                    WorldStorage.setReward(itemId, assignedRewardId, false);
                }
            } catch (JSONException e) {
                SoomlaUtils.LogError(TAG,
                        "Unable to set state for world " + itemId + ". error: " + e.getLocalizedMessage());
                return false;
            }

            return true;
        }
    });

    boolean levelsApplyState = resetStateFromJSON(state, "levels", new IItemStateApplier() {
        @Override
        public boolean applyState(String itemId, JSONObject itemValuesJSON) {
            try {
                if (itemValuesJSON.has("started")) {
                    int timesStarted = itemValuesJSON.getInt("started");
                    LevelStorage.setTimesStarted(itemId, timesStarted);
                }

                if (itemValuesJSON.has("played")) {
                    int timesPlayed = itemValuesJSON.getInt("played");
                    LevelStorage.setTimesPlayed(itemId, timesPlayed);
                }

                if (itemValuesJSON.has("timesCompleted")) {
                    int timesCompleted = itemValuesJSON.getInt("timesCompleted");
                    LevelStorage.setTimesCompleted(itemId, timesCompleted);
                }

                if (itemValuesJSON.has("slowest")) {
                    long slowest = itemValuesJSON.getLong("slowest");
                    LevelStorage.setSlowestDurationMillis(itemId, slowest);
                }

                if (itemValuesJSON.has("fastest")) {
                    long fastest = itemValuesJSON.getLong("fastest");
                    LevelStorage.setFastestDurationMillis(itemId, fastest);
                }
            } catch (JSONException e) {
                SoomlaUtils.LogError(TAG,
                        "Unable to set state for level " + itemId + ". error: " + e.getLocalizedMessage());
                return false;
            }

            return true;
        }
    });

    return worldsApplyState && levelsApplyState;
}

From source file:com.soomla.levelup.LevelUp.java

private static boolean resetMissionsStateFromJSON(JSONObject state) {
    return resetStateFromJSON(state, "missions", new IItemStateApplier() {
        @Override//from ww  w. j av a2s  .  co  m
        public boolean applyState(String itemId, JSONObject itemValuesJSON) {
            try {
                if (itemValuesJSON.has("timesCompleted")) {
                    int timesCompleted = itemValuesJSON.getInt("timesCompleted");
                    MissionStorage.setTimesCompleted(itemId, timesCompleted);
                }
            } catch (JSONException e) {
                SoomlaUtils.LogError(TAG,
                        "Unable to set state for level " + itemId + ". error: " + e.getLocalizedMessage());
                return false;
            }

            return true;
        }
    });
}

From source file:com.soomla.levelup.LevelUp.java

private static boolean resetScoresStateFromJSON(JSONObject state) {
    return resetStateFromJSON(state, "scores", new IItemStateApplier() {
        @Override//w w w.j ava2s.  c  o  m
        public boolean applyState(String itemId, JSONObject itemValuesJSON) {
            try {
                if (itemValuesJSON.has("latest")) {
                    double latestScore = itemValuesJSON.getInt("latest");
                    ScoreStorage.setLatestScore(itemId, latestScore, false);
                }

                if (itemValuesJSON.has("record")) {
                    double recordScore = itemValuesJSON.getInt("record");
                    ScoreStorage.setRecordScore(itemId, recordScore, false);
                }
            } catch (JSONException e) {
                SoomlaUtils.LogError(TAG,
                        "Unable to set state for level " + itemId + ". error: " + e.getLocalizedMessage());
                return false;
            }

            return true;
        }
    });
}

From source file:com.nextgis.firereporter.GetFiresService.java

protected void FillScanexData(int nType, String sJSON) {
    GetDataStoped();/*from w w  w  .ja  v  a2 s  . c o  m*/
    try {
        String sSubData = removeJsonT(sJSON);
        JSONObject rootobj = new JSONObject(sSubData);
        String sStatus = rootobj.getString("Status");
        if (sStatus.equals("OK")) {
            //6. store data to db and in map
            List<Long> naIDs = new ArrayList<Long>();
            JSONArray oResults = rootobj.getJSONArray("Result");
            for (int i = 0; i < oResults.length(); i++) {
                JSONObject jsonObject = oResults.getJSONObject(i);
                long nID = jsonObject.getLong("ID");
                naIDs.add(nID);

                // Add new items

                if (!mmoSubscriptions.containsKey(nID)) {
                    String sTitle = jsonObject.getString("Title");
                    String sLayerName = jsonObject.getString("LayerName");
                    String sWKT = jsonObject.getString("wkt");
                    boolean bSMSEnable = jsonObject.getBoolean("SMSEnable");

                    ScanexSubscriptionItem Item = new ScanexSubscriptionItem(this, nID, sTitle, sLayerName,
                            sWKT, bSMSEnable);
                    mmoSubscriptions.put(nID, Item);
                    SendScanexItem(Item);

                    mbHasChanges = true;
                }

                mmoSubscriptions.get(nID).UpdateFromRemote(msScanexLoginCookie);

            }

            // Remove deleted items
            for (Long id : mmoSubscriptions.keySet()) {
                if (!naIDs.contains(id)) {
                    mmoSubscriptions.remove(id);
                }
            }
            StoreScanexData();
        } else {
            SendError(rootobj.getString("ErrorInfo"));
        }
    } catch (JSONException e) {
        SendError(e.getLocalizedMessage());
        e.printStackTrace();
    }
}