Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
 * Populates the list of ContentRenditionInfo objects for this content,
 * content renditions currently can either be in the HDS or HLS format
 *///from   w w w .  j a  va 2 s  .  co m
protected void parseContent() {
    if (getString(entryObject, NAME_CONTENT) == null) {
        return;
    }

    try {
        this.contentRenditionInfoList = new ArrayList<ContentRenditionInfo>();
        JSONArray content = entryObject.getJSONArray(NAME_CONTENT);

        for (int i = 0; i < content.length(); i++) {
            JSONObject contentObject = content.getJSONObject(i);

            ContentFormat contentFormat = null;
            String formatStr = getString(contentObject, NAME_CONTENT_FORMAT);
            if (formatStr.equals(VALUE_CONTENT_FORMAT_M3U8)) {
                contentFormat = ContentFormat.hls;
            } else if (formatStr.equals(VALUE_CONTENT_FORMAT_F4M)) {
                contentFormat = ContentFormat.hds;
            }

            String url = getString(contentObject, NAME_CONTENT_URL);
            String language = getString(contentObject, NAME_CONTENT_LANGUAGE);
            List<SerializableNameValuePair> renditionProperties = new ArrayList<SerializableNameValuePair>();
            renditionProperties.add(new SerializableNameValuePair(NAME_CONTENT_LANGUAGE, language));
            ContentRenditionInfo info = new ContentRenditionInfo(contentFormat, url, renditionProperties);
            this.contentRenditionInfoList.add(info);
        }

    } catch (JSONException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::parseContent",
                "Error parsing content list: " + e.getMessage());
    }
}

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
 * Parses the metadata of the content and populates the MetadatNode object,
 * which contains the key/value pair pointing to a specific MetadataNode
 * type like AuditudeMetadata, direct ad breaks in a JSON metadata string,
 * custom ad markers metadata, or any custom MetadataNode subclass with a
 * custom AdProivder implementation. Currently, this metadata is limited to
 * ad related metadata/*  w w  w .  j  a  v a 2  s  .co  m*/
 */
protected void parseMetadata() {
    if (getString(entryObject, NAME_METADATA) == null) {
        return;
    }

    try {
        this.metadataNode = new MetadataNode();

        AdvertisingMetadata advertisingMetadata = null;
        JSONObject metadataObject = entryObject.getJSONObject(NAME_METADATA);

        try {
            if (metadataObject.has(NAME_METADATA_AD)) {
                JSONObject metadataAdObject = metadataObject.getJSONObject(NAME_METADATA_AD);

                String adType = metadataAdObject.getString(METADATA_AD_TYPE);
                JSONObject adDetailsObject = metadataAdObject.getJSONObject(METADATA_AD_DETAILS);

                if (adType.equals(VALUE_AD_TYPE_PRIMETIME_ADS)) {
                    advertisingMetadata = createAuditudeMetadata(adDetailsObject);
                    metadataNode.setValue(DefaultMetadataKeys.AUDITUDE_METADATA_KEY.getValue(), "");
                } else if (adType.equals(VALUE_AD_TYPE_DIRECT_AD_BREAKS)) {
                    advertisingMetadata = createBasicMetadataFrom(adDetailsObject);
                    metadataNode.setValue(DefaultMetadataKeys.JSON_METADATA_KEY.getValue(), "");

                    overlayAdItems = createOverlayAdItems(adDetailsObject);
                } else if (adType.equals(VALUE_AD_TYPE_CUSTOM_AD_MARKERS)) {
                    advertisingMetadata = createCustomAdMarkers(adDetailsObject);
                    metadataNode.setValue(DefaultMetadataKeys.CUSTOM_AD_MARKERS_METADATA_KEY.getValue(), "");
                } else if (adType.equals(VALUE_AD_TYPE_CUSTOM_AD_PROVIDER)) {
                    advertisingMetadata = createCustomAdProvider(adDetailsObject);
                    metadataNode.setValue(CustomAdProviderMetadata.CUSTOM_AD_PROVIDER_METADATA_KEY, "");
                }

                if (adDetailsObject.has(NODE_NAME_DISABLE_CONTENT_CACHE)) {
                    metadataNode.setValue(DefaultMetadataKeys.DISABLE_CONTENT_CACHING.getValue(),
                            adDetailsObject.getString(NODE_NAME_DISABLE_CONTENT_CACHE));
                }

            }

            if (metadataObject.has(NODE_NAME_METADATA_TIME_RANGES)) {
                advertisingMetadata = parseTimeRangeMetadata(metadataNode,
                        metadataObject.getJSONObject(NODE_NAME_METADATA_TIME_RANGES), advertisingMetadata);
            }

            if (metadataObject.has(NODE_NAME_SIGNALING_MODE)) {
                advertisingMetadata.setSignalingMode(
                        AdSignalingMode.createFrom(metadataObject.getString(NODE_NAME_SIGNALING_MODE)));
            }

            if (advertisingMetadata != null) {
                metadataNode.setNode(DefaultMetadataKeys.ADVERTISING_METADATA.getValue(), advertisingMetadata);
            }

        } catch (JSONException e) {
            AdVideoApplication.logger.w(LOG_TAG + "::parseMetadata",
                    "Error parsing ad metadata list: " + e.getMessage());
        }

        try {
            // add entitlement metadata if present
            JSONObject entitlementObject = metadataObject.getJSONObject(NAME_METADATA_ENTITLEMENT);
            if (entitlementObject != null) {
                String resourceId = entitlementObject.getString(METADATA_ENTITLEMENT_ID);
                if (resourceId != null) {
                    EntitlementMetadata entitlementMetadata = new EntitlementMetadata();
                    entitlementMetadata.setValue(EntitlementMetadata.RESOURCE_ID_KEY, resourceId);

                    metadataNode.setNode(EntitlementMetadata.ENTITLEMENT_METADATA, entitlementMetadata);
                }
            }
        } catch (JSONException e) {
            AdVideoApplication.logger.w(LOG_TAG + "::parseMetadata",
                    "Error parsing entitlement metadata list: " + e.getMessage());
        }

        try {
            if (metadataObject.has(NODE_NAME_METADATA_VIDEO_ANALYTICS)) {
                VideoAnalyticsMetadata videoAnalyticsMetadata = parseVideoAnalyticsMetadata(
                        metadataObject.getJSONObject(NODE_NAME_METADATA_VIDEO_ANALYTICS));
                metadataNode.setNode(DefaultMetadataKeys.VIDEO_ANALYTICS_METADATA_KEY.getValue(),
                        videoAnalyticsMetadata);
            }
        } catch (JSONException e) {
            AdVideoApplication.logger.w(LOG_TAG + "::parseMetadata",
                    "Error parsing video analytics metadata list: " + e.getMessage());
        }

    } catch (JSONException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::parseMetadata",
                "Error parsing metadata list: " + e.getMessage());
    }
}

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
* Creates Custom Ad Provider Metadata from JSON object This is only an
* example of how a customer can have custom ad data in their feeds and
* implement their own AdProvider to resolve the ad data to ad content urls
* and Placement info/*from   www.  ja v a  2  s  .co  m*/
* 
* @param jsonObject
*            - to be parsed
* @return CustomAdProviderMetadata -
*/
protected CustomAdProviderMetadata createCustomAdProvider(JSONObject jsonObject) {
    CustomAdProviderMetadata result = new CustomAdProviderMetadata();

    try {
        String domain = jsonObject.getString(NODE_NAME_CUSTOM_AD_PROVIDER_DOMAIN);
        result.setDomain(domain);

        JSONArray jsonArray = jsonObject.getJSONArray(NODE_NAME_CUSTOM_AD_PROVIDER_AD_PATTERN);

        ArrayList<CustomAdProviderMetadata.AdPattern> adPatternList = new ArrayList<CustomAdProviderMetadata.AdPattern>();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject aJsonObject = jsonArray.getJSONObject(i);
            Long time = Long.parseLong(aJsonObject.getString(NODE_NAME_CUSTOM_AD_PROVIDER_TIME));
            Long count = Long.parseLong(aJsonObject.getString(NODE_NAME_CUSTOM_AD_PROVIDER_COUNT));
            Long duration = Long.parseLong(aJsonObject.getString(NODE_NAME_CUSTOM_AD_PROVIDER_DURATION));

            CustomAdProviderMetadata.AdPattern adPattern = new CustomAdProviderMetadata.AdPattern(time, count,
                    duration);
            adPatternList.add(adPattern);
        }
        result.setAdPatternList(adPatternList);

        Metadata contentMetadata = getMetadataFromJson(jsonObject,
                NODE_NAME_CUSTOM_AD_PROVIDER_CONTENT_METADATA);
        result.setContentMetadata(contentMetadata);
    } catch (JSONException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createCustomAdProvider",
                "Error parsing custom ad provider: " + e.getMessage());
    }

    return result;
}

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
 * Creates and returns an AuditudeSettings object
 * /*from w  w w .  j a  v  a 2 s.co  m*/
 * @param jsonObject
 *            - to be parsed
 * @return AuditudeSettings - set with the Auditude domain, media id, zone
 *         id, targeting parameters, and creative packaging option.
 */
protected AdvertisingMetadata createAuditudeMetadata(JSONObject jsonObject) {
    AuditudeSettings result = new AuditudeSettings();
    String zoneId;

    try {
        String domain = jsonObject.getString(NODE_NAME_AD_DOMAIN);
        result.setDomain(domain);
        String mediaId = jsonObject.getString(NODE_NAME_AD_MEDIAID);
        result.setMediaId(mediaId);
        zoneId = jsonObject.getString(NODE_NAME_AD_ZONEID);
        result.setZoneId(zoneId);

        Metadata targetingParameters = getMetadataFromJson(jsonObject, NODE_NAME_AD_TARGETING);
        if (HotStarApplication.getInstance()
                .getLoginStatus() == HotStarApplication.UserStatusType.STATUS_USER_LOGIN_REGISTERED) {
            HotStarUserInfo userInfo = HotStarApplication.getInstance().getUserInfo();
            targetingParameters.setValue("age", String.valueOf(userInfo.age));
            targetingParameters.setValue("usergender", userInfo.gender);
            targetingParameters.setValue("location", HotStarApplication.getInstance().getLocation());
            targetingParameters.setValue("device", SamsungPhoneInfo.getInstance().modelString());
        }

        result.setTargetingParameters(targetingParameters);

        boolean creativePackagingEnabled = false;
        if (jsonObject.has(NODE_NAME_CREATIVE_REPACKAGING_ENABLED)) {
            creativePackagingEnabled = NumberUtils
                    .parseBoolean(jsonObject.getString(NODE_NAME_CREATIVE_REPACKAGING_ENABLED));
        }
        result.setCreativeRepackagingEnabled(creativePackagingEnabled);
    } catch (JSONException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createAuditudeMetadata",
                "Error parsing auditude metadata: " + e.getMessage());
    } catch (NumberFormatException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createAuditudeMetadata",
                "Error parsing auditude metadata: " + e.getMessage());
    }

    return result;
}

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
 * Creates and returns the overlay ad items from JSON object.
 *
 * @param jsonObject//from   ww w.  j ava  2  s.c o  m
 * @return
 */
protected ArrayList<OverlayAdItem> createOverlayAdItems(JSONObject jsonObject) {

    if (!jsonObject.has(NODE_NAME_ADBREAKS))
        return null;

    ArrayList<OverlayAdItem> list = new ArrayList<OverlayAdItem>();
    try {
        JSONArray arrayObject = jsonObject.getJSONArray(NODE_NAME_ADBREAKS);
        for (int i = 0; i < arrayObject.length(); i++) {
            JSONObject adbreakObject = arrayObject.getJSONObject(i);
            ArrayList<OverlayAdItem> adList = createOverlayAdListItems(adbreakObject);
            if (adList != null) {
                list.addAll(adList);
            }
        }

        if (list.size() == 0)
            return null;
        return list;
    } catch (JSONException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createOverlayAdItems",
                "Error parsing custom overlay ad items: " + e.getMessage());
    } catch (NumberFormatException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createOverlayAdItems",
                "Error parsing custom overlay ad items: " + e.getMessage());
    }

    return null;
}

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
 * Create and returns overlay ad-list items
 *
 * @param jsonObject//from w  w  w.j  a  va  2 s  .c o  m
 * @return
 */
protected ArrayList<OverlayAdItem> createOverlayAdListItems(JSONObject jsonObject) {

    ArrayList<OverlayAdItem> list = new ArrayList<OverlayAdItem>();
    try {
        int adStartTime = jsonObject.getInt("time");
        String adTag = jsonObject.getString("tag");
        int adReplace = jsonObject.getInt("replace");

        if (jsonObject.has("ad-list")) {
            JSONArray adListObjects = jsonObject.getJSONArray("ad-list");

            // iterate all ad-list items
            for (int i = 0; i < adListObjects.length(); i++) {
                JSONObject adListObject = adListObjects.getJSONObject(i);
                int adDuration = adListObject.getInt("duration");
                String adListTag = adListObject.getString("tag");
                String adUrl = adListObject.getString("url");

                if (adUrl.contains("png") || adUrl.contains("jpg")) {
                    OverlayAdItem adItem = new OverlayAdItem();
                    adItem.setAdStartTime(adStartTime);
                    adItem.setAdReplace(adReplace);
                    adItem.setAdTag(adTag);
                    adItem.setAdDuration(adDuration);
                    adItem.setAdListTag(adListTag);
                    adItem.setAdUrl(adUrl);

                    list.add(adItem);
                }

                adStartTime += adDuration;
            }

            if (list.size() == 0)
                return null;
            return list;
        }
    } catch (JSONException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createOverlayAdListItems",
                "Error parsing custom overlay ad-list items: " + e.getMessage());
    } catch (NumberFormatException e) {
        AdVideoApplication.logger.e(LOG_TAG + "::createOverlayAdListItems",
                "Error parsing custom overlay ad-list items: " + e.getMessage());
    }

    return null;
}

From source file:com.pdi.hybridge.HybridgeWebChromeClient.java

@Override
public final boolean onJsPrompt(WebView view, String url, String msg, String defValue, JsPromptResult result) {
    final String action = msg;
    JSONObject json = null;// w ww  .  ja  v a 2s . co m
    Log.v(mTag, "Hybridge action: " + action);
    try {
        json = new JSONObject(defValue);
        Log.v(mTag, "JSON parsed (Action " + action + ") : " + json.toString());
        executeJSONTask(action, json, result, HybridgeBroadcaster.getInstance(view),
                (Activity) view.getContext());
    } catch (final JSONException e) {
        result.cancel();
        Log.e(mTag, e.getMessage());
    }
    return true;
}

From source file:com.phonegap.DirectoryManager.java

/**
 * This method will determine the file properties of the file specified
 * by the filePath.  Creates a JSONObject with name, lastModifiedDate and 
 * size properties.//from   w w  w  .  java  2  s  .  co m
 * 
 * @param filePath the file to get the properties of
 * @return a JSONObject with the files properties
 */
protected static JSONObject getFile(String filePath) {
    File fp = new File(filePath);

    JSONObject obj = new JSONObject();
    try {
        obj.put("name", fp.getAbsolutePath());
        obj.put("lastModifiedDate", new Date(fp.lastModified()).toString());
        obj.put("size", fp.length());
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }

    return obj;
}

From source file:com.dedipower.portal.android.InvoiceLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invoicelanding);
    final ListView list = (ListView) findViewById(R.id.InvoiceList);

    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);/*from w w  w  .  jav  a  2  s.c o m*/
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                InvoiceAdaptor adapter = new InvoiceAdaptor(InvoiceLanding.this, listOfInvoices, API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                InvoiceAPIReturn = API.PortalQueryHack("invoices", "", "");
                Success = InvoiceAPIReturn.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                Success = "false";
            }

            if (Success.equals("false")) {
                Log.i("API", "Success was false");
                try {
                    ErrorMessage = InvoiceAPIReturn.getJSONObject("hackReturn").getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                int InvoiceCount = 0;
                Log.i("APIFuncs", InvoiceAPIReturn.toString());
                try {
                    Invoices = InvoiceAPIReturn.getJSONObject("hackReturn").getJSONArray("data");
                    InvoiceCount = Invoices.length();
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There don't appear to be any invoices for your account.....";
                    InvoiceCount = 0;
                    Log.e("API", "There was an eror parsing the array");
                    Log.e("API", e.getMessage());
                }

                //OK lets actually do something useful

                if (InvoiceCount == 0) {
                    Success = "false";
                    ErrorMessage = "There are no invoices for your account.";
                    handler.sendEmptyMessage(0);
                    return;
                }

                for (int i = 0; i < InvoiceCount; i++) {
                    JSONObject CurrentInvoice = null;
                    try {
                        CurrentInvoice = Invoices.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }
                    try {
                        if (CurrentInvoice.getString("type").equals("invoice"))
                            listOfInvoices.add(new Invoices(CurrentInvoice.getString("ref"),
                                    CurrentInvoice.getDouble("amount"), CurrentInvoice.getString("details"),
                                    CurrentInvoice.getLong("date")));
                    } catch (JSONException e) {
                        Log.e("APIFuncs", e.getMessage());
                    }
                }
            }

            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
}

From source file:org.restcomm.app.utillib.Reporters.WebReporter.RegistrationRequest.java

/**
 * @return String the json representation of the body of the request.
 *//*w w w .  j  a v  a 2  s  .com*/
public static String toJSON(DeviceInfo device, String email, String password, boolean share) {
    String json = "";
    HashMap<String, String> phoneProperties = device.getProperties();
    if (phoneProperties != null) {
        JSONObject data = new JSONObject(phoneProperties);
        try {
            data.put("login", email);
            data.put("share", share);
            if (password != null) {
                data.put("password", password);
            }
            json = data.toString();
        } catch (JSONException e) {
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "toJSON", e.getMessage());
        }
    }
    return json;
}