Example usage for org.json JSONObject isNull

List of usage examples for org.json JSONObject isNull

Introduction

In this page you can find the example usage for org.json JSONObject isNull.

Prototype

public boolean isNull(String key) 

Source Link

Document

Determine if the value associated with the key is null or if there is no value.

Usage

From source file:org.jboss.aerogear.cordova.push.PushPlugin.java

private JSONObject parseConfig(JSONArray data) throws JSONException {
    JSONObject pushConfig = data.getJSONObject(0);
    if (!pushConfig.isNull("android")) {
        final JSONObject android = pushConfig.getJSONObject("android");
        for (Iterator iterator = android.keys(); iterator.hasNext();) {
            String key = (String) iterator.next();
            pushConfig.put(key, android.get(key));
        }//from  w w  w  . j a  v a2 s  . c om

        pushConfig.remove("android");
    }
    return pushConfig;
}

From source file:org.uiautomation.ios.server.command.web.ScrollHandler.java

public ScrollHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();

    Point fromPoint;//from   w  w  w  .  j  av a2 s  .  c  om
    if (!payload.isNull("element") && !elementId.equals("")) {
        RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver()
                .createElement(elementId);
        fromPoint = element.getLocation();
    } else {
        fromPoint = new Point(screenSize.getWidth() / 2, screenSize.getHeight() / 2);
    }
    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    Point toPoint = new Point(fromPoint.getX() + payload.getInt("xoffset"),
            fromPoint.getY() + payload.getInt("yoffset"));
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    String js = scrollTemplate.replace(":sessionId", request.getSession())
            .replace("fromX", Integer.toString(fromPoint.getX()))
            .replace("fromY", Integer.toString(fromPoint.getY()))
            .replace("toX", Integer.toString(toPoint.getX())).replace("toY", Integer.toString(toPoint.getY()));

    setJS(js);
}

From source file:net.dv8tion.jda.core.handle.GuildUpdateHandler.java

@Override
protected Long handleInternally(JSONObject content) {
    final long id = content.getLong("id");
    if (api.getGuildLock().isLocked(id))
        return id;

    GuildImpl guild = (GuildImpl) api.getGuildMap().get(id);
    Member owner = guild.getMembersMap().get(content.getLong("owner_id"));
    String name = content.getString("name");
    String iconId = !content.isNull("icon") ? content.getString("icon") : null;
    String splashId = !content.isNull("splash") ? content.getString("splash") : null;
    Region region = Region.fromKey(content.getString("region"));
    Guild.VerificationLevel verificationLevel = Guild.VerificationLevel
            .fromKey(content.getInt("verification_level"));
    Guild.NotificationLevel notificationLevel = Guild.NotificationLevel
            .fromKey(content.getInt("default_message_notifications"));
    Guild.MFALevel mfaLevel = Guild.MFALevel.fromKey(content.getInt("mfa_level"));
    Guild.ExplicitContentLevel explicitContentLevel = Guild.ExplicitContentLevel
            .fromKey(content.getInt("explicit_content_filter"));
    Guild.Timeout afkTimeout = Guild.Timeout.fromKey(content.getInt("afk_timeout"));
    VoiceChannel afkChannel = !content.isNull("afk_channel_id")
            ? guild.getVoiceChannelMap().get(content.getLong("afk_channel_id"))
            : null;//  w  w  w. j a v  a2  s .co m

    if (!Objects.equals(owner, guild.getOwner())) {
        Member oldOwner = guild.getOwner();
        guild.setOwner(owner);
        api.getEventManager().handle(new GuildUpdateOwnerEvent(api, responseNumber, guild, oldOwner));
    }
    if (!Objects.equals(name, guild.getName())) {
        String oldName = guild.getName();
        guild.setName(name);
        api.getEventManager().handle(new GuildUpdateNameEvent(api, responseNumber, guild, oldName));
    }
    if (!Objects.equals(iconId, guild.getIconId())) {
        String oldIconId = guild.getIconId();
        guild.setIconId(iconId);
        api.getEventManager().handle(new GuildUpdateIconEvent(api, responseNumber, guild, oldIconId));
    }
    if (!Objects.equals(splashId, guild.getSplashId())) {
        String oldSplashId = guild.getSplashId();
        guild.setSplashId(splashId);
        api.getEventManager().handle(new GuildUpdateSplashEvent(api, responseNumber, guild, oldSplashId));
    }
    if (!Objects.equals(region, guild.getRegion())) {
        Region oldRegion = guild.getRegion();
        guild.setRegion(region);
        api.getEventManager().handle(new GuildUpdateRegionEvent(api, responseNumber, guild, oldRegion));
    }
    if (!Objects.equals(verificationLevel, guild.getVerificationLevel())) {
        Guild.VerificationLevel oldVerificationLevel = guild.getVerificationLevel();
        guild.setVerificationLevel(verificationLevel);
        api.getEventManager().handle(
                new GuildUpdateVerificationLevelEvent(api, responseNumber, guild, oldVerificationLevel));
    }
    if (!Objects.equals(notificationLevel, guild.getDefaultNotificationLevel())) {
        Guild.NotificationLevel oldNotificationLevel = guild.getDefaultNotificationLevel();
        guild.setDefaultNotificationLevel(notificationLevel);
        api.getEventManager().handle(
                new GuildUpdateNotificationLevelEvent(api, responseNumber, guild, oldNotificationLevel));
    }
    if (!Objects.equals(mfaLevel, guild.getRequiredMFALevel())) {
        Guild.MFALevel oldMfaLevel = guild.getRequiredMFALevel();
        guild.setRequiredMFALevel(mfaLevel);
        api.getEventManager().handle(new GuildUpdateMFALevelEvent(api, responseNumber, guild, oldMfaLevel));
    }
    if (!Objects.equals(explicitContentLevel, guild.getExplicitContentLevel())) {
        Guild.ExplicitContentLevel oldExplicitContentLevel = guild.getExplicitContentLevel();
        guild.setExplicitContentLevel(explicitContentLevel);
        api.getEventManager().handle(
                new GuildUpdateExplicitContentLevelEvent(api, responseNumber, guild, oldExplicitContentLevel));
    }
    if (!Objects.equals(afkTimeout, guild.getAfkTimeout())) {
        Guild.Timeout oldAfkTimeout = guild.getAfkTimeout();
        guild.setAfkTimeout(afkTimeout);
        api.getEventManager().handle(new GuildUpdateAfkTimeoutEvent(api, responseNumber, guild, oldAfkTimeout));
    }
    if (!Objects.equals(afkChannel, guild.getAfkChannel())) {
        VoiceChannel oldAfkChannel = guild.getAfkChannel();
        guild.setAfkChannel(afkChannel);
        api.getEventManager().handle(new GuildUpdateAfkChannelEvent(api, responseNumber, guild, oldAfkChannel));
    }
    return null;
}

From source file:de.btobastian.javacord.utils.handler.message.MessageReactionAddHandler.java

@Override
public void handle(JSONObject packet) {
    String userId = packet.getString("user_id");
    String messageId = packet.getString("message_id");

    JSONObject emoji = packet.getJSONObject("emoji");
    boolean isCustomEmoji = !emoji.isNull("id");

    Message message = api.getMessageById(messageId);
    if (message == null) {
        return;// w  w w .j a va  2  s.  c  o m
    }

    Reaction reaction = null;
    if (isCustomEmoji) {
        String emojiId = emoji.getString("id");
        if (message.isPrivateMessage()) {
            // Private messages with custom emoji? Maybe with Nitro, but there's no documentation so far.
            return;
        }
        CustomEmoji customEmoji = message.getChannelReceiver().getServer().getCustomEmojiById(emojiId);
        if (customEmoji == null) {
            // We don't know this emoji
            return;
        }
        reaction = ((ImplMessage) message).addCustomEmojiReactionToCache(customEmoji,
                api.getYourself().getId().equals(userId));
    } else {
        reaction = ((ImplMessage) message).addUnicodeReactionToCache(emoji.getString("name"),
                api.getYourself().getId().equals(userId));
    }

    if (reaction != null) {
        final User user = api.getCachedUserById(userId);
        if (user != null) {
            final Reaction reactionFinal = reaction;
            listenerExecutorService.submit(new Runnable() {
                @Override
                public void run() {
                    List<ReactionAddListener> listeners = api.getListeners(ReactionAddListener.class);
                    synchronized (listeners) {
                        for (ReactionAddListener listener : listeners) {
                            try {
                                listener.onReactionAdd(api, reactionFinal, user);
                            } catch (Throwable t) {
                                logger.warn("Uncaught exception in ReactionAddListener!", t);
                            }
                        }
                    }
                }
            });
        }
    }
}

From source file:fr.pasteque.pos.customers.DiscountProfile.java

public DiscountProfile(JSONObject o) {
    if (!o.isNull("id")) {
        this.id = o.getInt("id");
    }//from  w  ww. j  ava  2 s.c o  m
    this.name = o.getString("label");
    this.rate = o.getDouble("rate");
}

From source file:com.clearcenter.mobile_demo.mdStatusActivity.java

public List<JSONObject> sortedSamplesList(String data) {
    SortedMap<String, JSONObject> map = new TreeMap<String, JSONObject>();

    try {//from w w  w  .  j av a 2 s.c om
        int version = 0;
        JSONObject json_data = new JSONObject(data);
        if (json_data.has("version"))
            version = json_data.getInt("version");
        if (version < 1 && json_data.has("time")) {
            String key = json_data.getString("time");
            map.put(key, json_data);
        } else if (version >= 1 && json_data.has("samples") && !json_data.isNull("samples")) {
            json_data = json_data.getJSONObject("samples");
            Iterator i = json_data.keys();
            while (i.hasNext()) {
                String key = i.next().toString();
                JSONObject sample = json_data.getJSONObject(key);
                sample.put("time", key);
                map.put(key, sample);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSONException", e);
    }

    return new LinkedList<JSONObject>(map.values());
}

From source file:org.melato.bus.otp.OTPParser.java

static JSONObject getObject(JSONObject json, String key) throws JSONException {
    if (json.has(key) && !json.isNull(key)) {
        return json.getJSONObject(key);
    }//from   ww  w  .j  av  a2 s .  co  m
    return null;
}

From source file:com.morpho.android.data.GeoPoint.java

/** {@inheritDoc} */
@Override/*from   w ww.  j  a va  2s.  co m*/
public void fromJSON(String json) {
    try {
        JSONObject src = new JSONObject(json);
        latitude = src.isNull("latitude") ? null : src.getDouble("latitude");
        longitude = src.isNull("longitude") ? null : src.getDouble("longitude");
    } catch (JSONException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.wso2.emm.agent.services.PolicyComplianceChecker.java

/**
 * Checks install app policy on the device (Particular app in the policy should be installed).
 *
 * @param operation - Operation object.// w  ww. ja v  a 2 s . co m
 * @return policy - ComplianceFeature object.
 */
private ComplianceFeature checkInstallAppPolicy(org.wso2.emm.agent.beans.Operation operation)
        throws AndroidAgentException {

    String appIdentifier = null;
    String name = null;

    try {
        JSONObject appData = new JSONObject(operation.getPayLoad().toString());

        if (!appData.isNull(resources.getString(R.string.app_identifier))) {
            appIdentifier = appData.getString(resources.getString(R.string.app_identifier));
        }

        if (!appData.isNull(resources.getString(R.string.app_identifier))) {
            name = appData.getString(resources.getString(R.string.intent_extra_name));
        }

        if (isAppInstalled(appIdentifier)) {
            policy.setCompliance(true);
        } else {
            policy.setCompliance(false);
            policy.setMessage(resources.getString(R.string.error_app_install_policy) + name);
        }

    } catch (JSONException e) {
        policy.setCompliance(false);
        throw new AndroidAgentException("Invalid JSON format.", e);
    }
    return policy;
}

From source file:org.wso2.emm.agent.services.PolicyComplianceChecker.java

/**
 * Checks uninstall app policy on the device (Particular app in the policy should be removed).
 *
 * @param operation - Operation object.//from  w w w . j  a  v  a 2s . co  m
 * @return policy - ComplianceFeature object.
 */
private ComplianceFeature checkUninstallAppPolicy(org.wso2.emm.agent.beans.Operation operation)
        throws AndroidAgentException {

    String appIdentifier = null;
    String name = null;

    try {
        JSONObject appData = new JSONObject(operation.getPayLoad().toString());

        if (!appData.isNull(resources.getString(R.string.app_identifier))) {
            appIdentifier = appData.getString(resources.getString(R.string.app_identifier));
        }

        if (!appData.isNull(resources.getString(R.string.app_identifier))) {
            name = appData.getString(resources.getString(R.string.intent_extra_name));
        }

        if (!isAppInstalled(appIdentifier)) {
            policy.setCompliance(true);
        } else {
            policy.setCompliance(false);
            policy.setMessage(resources.getString(R.string.error_app_uninstall_policy) + name);
        }

    } catch (JSONException e) {
        policy.setCompliance(false);
        throw new AndroidAgentException("Invalid JSON format.", e);
    }
    return policy;
}