List of usage examples for org.json JSONException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.facebook.share.ShareApi.java
private void stagePhoto(final SharePhoto photo, final CollectionMapper.OnMapValueCompleteListener onPhotoStagedListener) { final Bitmap bitmap = photo.getBitmap(); final Uri imageUrl = photo.getImageUrl(); if ((bitmap != null) || (imageUrl != null)) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override/*from w w w .j a v a 2 s . c o m*/ public void onCompleted(GraphResponse response) { final FacebookRequestError error = response.getError(); if (error != null) { String message = error.getErrorMessage(); if (message == null) { message = "Error staging photo."; } onPhotoStagedListener.onError(new FacebookGraphResponseException(response, message)); return; } final JSONObject data = response.getJSONObject(); if (data == null) { onPhotoStagedListener.onError(new FacebookException("Error staging photo.")); return; } final String stagedImageUri = data.optString("uri"); if (stagedImageUri == null) { onPhotoStagedListener.onError(new FacebookException("Error staging photo.")); return; } final JSONObject stagedObject = new JSONObject(); try { stagedObject.put("url", stagedImageUri); stagedObject.put("user_generated", photo.getUserGenerated()); } catch (final JSONException ex) { String message = ex.getLocalizedMessage(); if (message == null) { message = "Error staging photo."; } onPhotoStagedListener.onError(new FacebookException(message)); return; } onPhotoStagedListener.onComplete(stagedObject); } }; if (bitmap != null) { ShareInternalUtility.newUploadStagingResourceWithImageRequest(AccessToken.getCurrentAccessToken(), bitmap, requestCallback).executeAsync(); } else { try { ShareInternalUtility.newUploadStagingResourceWithImageRequest( AccessToken.getCurrentAccessToken(), imageUrl, requestCallback).executeAsync(); } catch (final FileNotFoundException ex) { String message = ex.getLocalizedMessage(); if (message == null) { message = "Error staging photo."; } onPhotoStagedListener.onError(new FacebookException(message)); } } } else { onPhotoStagedListener.onError(new FacebookException("Photos must have an imageURL or bitmap.")); } }
From source file:to.networld.fbtosemweb.ws.FOAFExporter.java
@Override public void doGet(HttpServletRequest _request, HttpServletResponse _response) throws ServletException, IOException { String access_token = SessionHandler.getAccessToken(_request); if (access_token == null) { access_token = (String) _request.getParameter("access_token"); if (access_token == null) { _response.sendRedirect("."); return; } else {// w w w .j a v a 2s. co m access_token = "access_token=" + access_token; } } PrintWriter out = _response.getWriter(); try { FacebookAgentHandler currentAgentHandler = new FacebookAgentHandler(access_token); FacebookToFOAF foafFile = new FacebookToFOAF(currentAgentHandler); _response.setCharacterEncoding("UTF-8"); _response.setContentType("application/rdf+xml; charset=UTF-8"); _response.setHeader("Content-Disposition", "attachment; filename=foaf.rdf"); out.println(foafFile); } catch (JSONException e) { out.println(e.getLocalizedMessage()); _response.setStatus(500); } }
From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java
public ScanexSubscriptionItem(GetFiresService c, JSONObject object) { Prepare(c);/*from w w w . j a v a2 s. co m*/ try { this.nID = object.getLong("id"); this.sTitle = object.getString("title"); this.sLayerName = object.getString("layer_name"); this.sWKT = object.getString("wkt"); this.bSMSEnable = object.getBoolean("sms_enabled"); JSONArray jsonArray = object.getJSONArray("items"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); ScanexNotificationItem Item = new ScanexNotificationItem(c, jsonObject); if (Item.GetId() != -1) { mmoItems.put(Item.GetId(), Item); } } } catch (JSONException e) { SendError(e.getLocalizedMessage()); } }
From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java
protected void FillData(int nType, String sData) { String sCleanData = GetFiresService.removeJsonT(sData); try {//ww w. jav a 2 s . c om JSONObject object = new JSONObject(sCleanData); String sStatus = object.getString("Status"); if (sStatus.equals("OK")) { JSONArray jsonArray = object.getJSONArray("Result"); for (int i = 0; i < jsonArray.length(); i++) { JSONArray jsonSubArray = jsonArray.getJSONArray(i); long nID = jsonSubArray.getLong(0); String sPtCoord = jsonSubArray.getString(1); int nConfidence = jsonSubArray.getInt(2); int nPower = jsonSubArray.getInt(3); String sURL1 = jsonSubArray.getString(4); String sURL2 = jsonSubArray.getString(5); String sType = jsonSubArray.getString(6); String sPlace = jsonSubArray.getString(7); String sDate = jsonSubArray.getString(8); String sMap = jsonSubArray.getString(9); if (!mmoItems.containsKey(nID)) { ScanexNotificationItem Item = new ScanexNotificationItem(c, nID, sPtCoord, nConfidence, nPower, sURL1, sURL2, sType, sPlace, sDate, sMap, R.drawable.ic_scan); mmoItems.put(Item.GetId(), Item); //notify changes c.onNewNotifictation(GetId(), Item); setHasNews(true); } } } else { SendError(object.getString("ErrorInfo")); } } catch (JSONException e) { SendError(e.getLocalizedMessage()); } /*44({ "Status": "OK", "ErrorInfo": "", "Result": [[1306601, "61.917, 63.090", 68, 27.4, "\u003ca href=\u0027http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=460&height=460&bbox=6987987,8766592,7058307,8836912\u0027\u003e \u003cimg src=\u0027http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=100&height=100&bbox=6987987,8766592,7058307,8836912\u0027 width=\u0027{4}\u0027 height=\u0027{5}\u0027 /\u003e\u003c/a\u003e", "\u003ca href=\u0027http://fires.kosmosnimki.ru/?x=63.09&y=61.917&z=11&dt=04.10.2013\u0027 target=\"_blank\"\u003eView on the map\u003c/a\u003e", "Fire", "", "\/Date(1380859500000)\/", "http://maps.kosmosnimki.ru/TileService.ashx/apikeyV6IAK16QRG/mapT42E9?SERVICE=WMS&request=GetMap&version=1.3&layers=C7B2E6510209444E80673F3C37519F7E,FFE60CFA7DAF498381F811C08A5E8CF5,T42E9.A78AC25E0D924258B5AF40048C21F7E7_dt04102013&styles=&crs=EPSG:3395&transparent=FALSE&format=image/jpeg&width=460&height=460&bbox=6987987,8766592,7058307,8836912", null]] })*/ }
From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java
public JSONObject getAsJSON() { JSONObject object = new JSONObject(); try {//w w w .j ava2 s . com object.put("id", nID); object.put("title", sTitle); object.put("layer_name", sLayerName); object.put("wkt", sWKT); object.put("sms_enabled", bSMSEnable); JSONArray oJSONItems = new JSONArray(); object.put("items", oJSONItems); for (ScanexNotificationItem Item : mmoItems.values()) { oJSONItems.put(Item.getAsJSON()); } } catch (JSONException e) { SendError(e.getLocalizedMessage()); } return object; }
From source file:com.tapfortap.phonegap.TapForTapPhoneGapPlugin.java
@Override public PluginResult execute(String action, JSONArray arguments, String callbackId) { PluginResult result = null;/* www . ja v a2 s . c o m*/ Object firstArg = null; if (arguments.length() > 0) { try { firstArg = arguments.get(0); } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage(), e); return new PluginResult(Status.ERROR); } } try { Log.d(TAG, "Action " + action + ", arguments: " + arguments); if (action.equals("initializeWithAPIKey")) { result = initialize((String) firstArg); } else if (action.equals("createAdView")) { result = createAdView((JSONObject) firstArg); } else if (action.equals("loadAds")) { result = loadAds((JSONObject) firstArg); } else if (action.equals("moveAdView")) { result = moveAdView((JSONObject) firstArg); } else if (action.equals("removeAdView")) { result = removeAdView(); } else if (action.equals("prepareInterstitial")) { result = prepareInterstitial(); } else if (action.equals("showInterstitial")) { result = showInterstitial(); } else if (action.equals("prepareAppWall")) { result = prepareAppWall(); } else if (action.equals("showAppWall")) { result = showAppWall(); } else { Log.w(TAG, "Unknown action " + action + ", arguments: " + arguments); } } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage(), e); result = new PluginResult(Status.JSON_EXCEPTION); } return result; }
From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java
public static Message performLogin(final UserData userData) { Message message = new Message(); JsonNode result = null;//from w w w .j ava 2 s . c o m JSONObject jsonPOST = new JSONObject(); JSONObject jsonUser = new JSONObject(); try { jsonUser.put("password", userData.getPassword()); jsonUser.put("email", userData.getEmail()); jsonPOST.put("user", jsonUser); result = HttpUtils.postToServer(Config.API_SERVER_LOGIN, jsonPOST); message = HttpUtils.JSONtoMessage(result); } catch (JSONException e) { LOG.e(e.getLocalizedMessage()); } return message; }
From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java
public static Message performFacebookLogin(String fbToken) { Message message = new Message(); try {/*from w w w .j ava 2 s .c om*/ JsonNode result = null; JSONObject jsonPOST = new JSONObject(); JSONObject jsonUser = new JSONObject(); jsonUser.put("fb_token", fbToken); jsonPOST.put("user", jsonUser); result = HttpUtils.postToServer(Config.API_SERVER_LOGIN, jsonPOST); message = HttpUtils.JSONtoMessage(result); } catch (JSONException e) { LOG.e(e.getLocalizedMessage()); } return message; }
From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java
public static Message performRegister(final UserData userData, Context context) { Message message = new Message(); JsonNode result = null;//from w ww .j av a 2 s. c om JSONObject jsonPOST = new JSONObject(); JSONObject jsonUser = new JSONObject(); JSONObject jsonImagePath = new JSONObject(); try { jsonImagePath.put("filename", userData.getImageName()); jsonImagePath.put("original_filename", userData.getImageName()); jsonImagePath.put("file", userData.getBase64Image()); jsonUser.put("name", userData.getName()); jsonUser.put("email", userData.getEmail()); jsonUser.put("email_confirmation", userData.getEmail()); jsonUser.put("password", userData.getPassword()); jsonUser.put("password_confirmation", userData.getPassword()); if (userData.getBase64Image() != null && !userData.getBase64Image().trim().equals("")) jsonUser.put("image_path", jsonImagePath); jsonUser.put("account_source", context.getResources().getString(R.string.account_source)); jsonPOST.put("user", jsonUser); result = HttpUtils.postToServer(Config.API_SERVER_REGISTER, jsonPOST); message = HttpUtils.JSONtoMessage(result); message.getData().putInt("type", REGISTER_USER); } catch (JSONException e) { LOG.e(e.getLocalizedMessage()); message.getData().putInt("type", ERROR); } return message; }
From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java
public static Message performGetUser(final UserData userData) { Message message = new Message(); JsonNode result = null;/*from w ww. j a v a2s . c o m*/ JSONObject jsonPOST = new JSONObject(); try { LOG.d("facebook api token get = " + userData.getAuth_token()); jsonPOST.put("auth_token", userData.getAuth_token()); result = HttpUtils.getFromServer(Config.API_SERVER_REGISTER + "/" + userData.getId() + "?auth_token=" + userData.getAuth_token()); message = HttpUtils.JSONtoUserDataMessage(result, userData); message.getData().putInt("type", GET_USER); } catch (JSONException e) { LOG.e(e.getLocalizedMessage()); message.getData().putInt("type", ERROR); } return message; }