Example usage for org.json JSONObject getBoolean

List of usage examples for org.json JSONObject getBoolean

Introduction

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

Prototype

public boolean getBoolean(String key) throws JSONException 

Source Link

Document

Get the boolean value associated with a key.

Usage

From source file:com.roiland.crm.sm.core.service.impl.ProjectAPIImpl.java

/**
 * @see com.roiland.crm.core.service.ProjectAPI#getProjectInfo(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 *///from  ww  w .  ja  va  2 s. co m
@Override
public Project getProjectInfo(String userID, String dealerOrgID, String projectID, String customerID)
        throws ResponseException {
    Project project = null;
    try {
        if (userID == null || dealerOrgID == null) {
            throw new ResponseException("userID or dealerOrgID is null.");
        }
        JSONObject params = new JSONObject();
        params.put("userID", userID);
        params.put("dealerOrgID", dealerOrgID);
        params.put("projectID", projectID);
        params.put("customerID", customerID);

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_PROJECT_INFO), params, null);
        if (response.isSuccess()) {
            project = new Project();
            JSONObject result = new JSONObject(getSimpleString(response)).getJSONObject("result");
            JSONObject customerEntityresult = result.getJSONObject("customerEntity");
            JSONObject purchaseCarIntentionresult = result.getJSONObject("purchaseCarIntention");

            Customer customerEntity = new Customer();
            PurchaseCarIntention purchaseCarIntention = new PurchaseCarIntention();
            if (StringUtils.isEmpty(projectID)) {
                customerEntity.setProjectID(projectID);
            }
            customerEntity.setCustomerID(parsingString(customerEntityresult.get("customerID")));
            customerEntity.setCustName(parsingString(customerEntityresult.get("custName")));
            customerEntity.setCustFromCode(parsingString(customerEntityresult.get("custFromCode")));
            customerEntity.setCustFrom(parsingString(customerEntityresult.get("custFrom")));
            customerEntity.setCustTypeCode(parsingString(customerEntityresult.get("custTypeCode")));
            customerEntity.setCustType(parsingString(customerEntityresult.get("custType")));
            customerEntity.setInfoFromCode(parsingString(customerEntityresult.get("infoFromCode")));
            customerEntity.setInfoFrom(parsingString(customerEntityresult.get("infoFrom")));
            customerEntity.setCollectFromCode(parsingString(customerEntityresult.get("collectFromCode")));
            customerEntity.setCollectFrom(parsingString(customerEntityresult.get("collectFrom")));
            customerEntity.setCustMobile(parsingString(customerEntityresult.get("custMobile")));
            customerEntity.setCustOtherPhone(parsingString(customerEntityresult.get("custOtherPhone")));
            customerEntity.setGenderCode(parsingString(customerEntityresult.get("genderCode")));
            customerEntity.setGender(parsingString(customerEntityresult.get("gender")));
            customerEntity.setBirthday(parsingString(customerEntityresult.get("birthday")));
            customerEntity.setIdTypeCode((parsingString(customerEntityresult.get("idTypeCode"))));
            customerEntity.setIdType(parsingString(customerEntityresult.get("idType")));
            customerEntity.setIdNumber(parsingString(customerEntityresult.get("idNumber")));
            customerEntity.setProvinceCode(parsingString(customerEntityresult.get("provinceCode")));
            customerEntity.setProvince(parsingString(customerEntityresult.get("province")));
            customerEntity.setCityCode(parsingString(customerEntityresult.get("cityCode")));
            customerEntity.setCity(parsingString(customerEntityresult.get("city")));
            customerEntity.setDistrictCode(parsingString(customerEntityresult.get("districtCode")));
            customerEntity.setDistrict(parsingString(customerEntityresult.get("district")));
            customerEntity.setQq(parsingString(customerEntityresult.get("qq")));
            customerEntity.setAddress(parsingString(customerEntityresult.get("address")));
            customerEntity.setPostcode(parsingString(customerEntityresult.get("postcode")));
            customerEntity.setEmail(parsingString(customerEntityresult.get("email")));
            customerEntity.setConvContactTime(parsingString(customerEntityresult.get("convContactTime")));
            //              customerEntity.setConvContactTimeCode((customerEntityresult
            //                              .get("convContactTimeCode")));
            customerEntity
                    .setExpectContactWayCode(parsingString(customerEntityresult.get("expectContactWayCode")));
            customerEntity.setExpectContactWay((parsingString(customerEntityresult.get("expectContactWay"))));
            customerEntity.setFax(parsingString(customerEntityresult.get("fax")));
            //              customerEntity.setExistingCarCode(String
            //                      .valueOf(parsingString(customerEntityresult
            //                              .get("existingCarCode"))));
            customerEntity.setExistingCarBrand(parsingString(customerEntityresult.get("existingCarBrand")));
            customerEntity.setIndustryCode(parsingString(customerEntityresult.get("industryCode")));
            customerEntity.setPositionCode(parsingString(customerEntityresult.get("positionCode")));
            customerEntity.setEducationCode(parsingString(customerEntityresult.get("educationCode")));
            customerEntity.setExistingCar(parsingString(customerEntityresult.get("existingCar")));
            customerEntity.setIndustry(parsingString(customerEntityresult.get("industry")));
            customerEntity.setPosition(parsingString(customerEntityresult.get("position")));
            customerEntity.setEducation(parsingString(customerEntityresult.get("education")));
            customerEntity.setCustInterestCode1(parsingString(customerEntityresult.get("custInterestCode1")));
            customerEntity.setCustInterest1((parsingString(customerEntityresult.get("custInterest1"))));
            customerEntity.setCustInterestCode2((parsingString(customerEntityresult.get("custInterestCode2"))));
            customerEntity.setCustInterest2(parsingString(customerEntityresult.get("custInterest2")));
            customerEntity.setCustInterestCode3(parsingString(customerEntityresult.get("custInterestCode3")));
            customerEntity.setCustInterest3(parsingString(customerEntityresult.get("custInterest3")));
            customerEntity.setExistLisenPlate(parsingString(customerEntityresult.get("existLisenPlate")));
            customerEntity.setEnterpTypeCode(parsingString(customerEntityresult.get("enterpTypeCode")));
            customerEntity.setEnterpType(parsingString(customerEntityresult.get("enterpType")));
            customerEntity
                    .setEnterpPeopleCountCode(parsingString(customerEntityresult.get("enterpPeopleCountCode")));
            customerEntity.setEnterpPeopleCount(parsingString(customerEntityresult.get("enterpPeopleCount")));
            customerEntity
                    .setRegisteredCapitalCode(parsingString(customerEntityresult.get("registeredCapitalCode")));
            customerEntity.setRegisteredCapital(parsingString(customerEntityresult.get("registeredCapital")));
            //              customerEntity.setCompeCarModelCode(String
            //                      .valueOf(parsingString(customerEntityresult
            //                              .get("compeCarModelCode"))));
            customerEntity.setCompeCarModel(parsingString(customerEntityresult.get("compeCarModel")));
            customerEntity.setRebuyStoreCustTag(
                    Boolean.parseBoolean((parsingString(customerEntityresult.get("rebuyStoreCustTag")))));
            customerEntity.setRebuyOnlineCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("rebuyOnlineCustTag"))));
            customerEntity.setChangeCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("changeCustTag"))));
            customerEntity.setLoanCustTag(
                    Boolean.parseBoolean((parsingString(customerEntityresult.get("loanCustTag")))));
            customerEntity.setHeaderQuartCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("headerQuartCustTag"))));
            customerEntity.setRegularCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("regularCustTag"))));
            customerEntity.setRegularCustCode(parsingString(customerEntityresult.get("regularCustCode")));
            customerEntity.setRegularCust(parsingString(customerEntityresult.get("regularCust")));
            customerEntity
                    .setBigCustTag(Boolean.parseBoolean(parsingString(customerEntityresult.get("bigCustTag"))));
            customerEntity.setBigCustsCode(parsingString(customerEntityresult.get("bigCustsCode")));
            customerEntity.setBigCusts(parsingString(customerEntityresult.get("bigCusts")));
            customerEntity.setCustComment(parsingString(customerEntityresult.get("custComment")));
            //customerEntity.setHasUnexePlan(parsingString(customerEntityresult.get("hasUnexePlan")));

            purchaseCarIntention.setBrandCode(parsingString(purchaseCarIntentionresult.get("brandCode")));
            purchaseCarIntention.setBrand(parsingString(purchaseCarIntentionresult.get("brand")));

            purchaseCarIntention.setModelCode(parsingString(purchaseCarIntentionresult.get("modelCode")));
            purchaseCarIntention.setModel(parsingString(purchaseCarIntentionresult.get("model")));
            purchaseCarIntention
                    .setOutsideColorCode(parsingString(purchaseCarIntentionresult.get("outsideColorCode")));
            purchaseCarIntention.setOutsideColor(parsingString(purchaseCarIntentionresult.get("outsideColor")));
            purchaseCarIntention
                    .setInsideColorCode(parsingString(purchaseCarIntentionresult.get("insideColorCode")));
            purchaseCarIntention.setInsideColor(parsingString(purchaseCarIntentionresult.get("insideColor")));
            purchaseCarIntention.setInsideColorCheck(
                    purchaseCarIntentionresult.getBoolean("insideColorCheck") ? true : false);
            purchaseCarIntention.setCarConfigurationCode(
                    parsingString(purchaseCarIntentionresult.get("carConfigurationCode")));
            purchaseCarIntention
                    .setCarConfiguration(parsingString(purchaseCarIntentionresult.get("carConfiguration")));
            purchaseCarIntention.setSalesQuote(parsingString(purchaseCarIntentionresult.get("salesQuote")));
            purchaseCarIntention.setDealPriceIntervalCode(
                    parsingString(purchaseCarIntentionresult.get("dealPriceIntervalCode")));
            purchaseCarIntention
                    .setDealPriceInterval(parsingString(purchaseCarIntentionresult.get("dealPriceInterval")));
            purchaseCarIntention.setPaymentCode(parsingString(purchaseCarIntentionresult.get("paymentCode")));
            purchaseCarIntention.setPayment(parsingString(purchaseCarIntentionresult.get("payment")));
            purchaseCarIntention
                    .setPreorderCount(parsingString(purchaseCarIntentionresult.get("preorderCount")));
            purchaseCarIntention.setPreorderDate(purchaseCarIntentionresult.isNull("preorderDate") ? 0L
                    : purchaseCarIntentionresult.getLong("preorderDate"));
            purchaseCarIntention
                    .setFlowStatusCode(parsingString(purchaseCarIntentionresult.get("flowStatusCode")));
            purchaseCarIntention.setFlowStatus(parsingString(purchaseCarIntentionresult.get("flowStatus")));
            purchaseCarIntention.setDealPossibility(purchaseCarIntentionresult.isNull("dealPossibility") ? ""
                    : parsingString(purchaseCarIntentionresult.get("dealPossibility")));
            purchaseCarIntention.setPurchMotivationCode(
                    parsingString(purchaseCarIntentionresult.get("purchMotivationCode")));
            purchaseCarIntention
                    .setPurchMotivation(parsingString(purchaseCarIntentionresult.get("purchMotivation")));
            purchaseCarIntention.setChassisNo(parsingString(purchaseCarIntentionresult.get("chassisNo")));
            purchaseCarIntention.setEngineNo(parsingString(purchaseCarIntentionresult.get("engineNo")));
            purchaseCarIntention.setLicensePlate(parsingString(purchaseCarIntentionresult.get("licensePlate")));
            purchaseCarIntention.setLicenseProp(parsingString(purchaseCarIntentionresult.get("licenseProp")));
            purchaseCarIntention
                    .setLicensePropCode(parsingString(purchaseCarIntentionresult.get("licensePropCode")));
            purchaseCarIntention.setPickupDate(parsingString(purchaseCarIntentionresult.get("pickupDate")));
            purchaseCarIntention.setPreorderTag(parsingString(purchaseCarIntentionresult.get("preorderTag")));
            purchaseCarIntention.setGiveupTag(purchaseCarIntentionresult.getBoolean("giveupTag"));
            purchaseCarIntention.setGiveupReason(parsingString(purchaseCarIntentionresult.get("giveupReason")));
            //              purchaseCarIntention.setGiveupReasonCode(String
            //                      .valueOf(parsingString(purchaseCarIntentionresult
            //                              .get("giveupReasonCode")));
            purchaseCarIntention.setInvoiceTitle(parsingString(purchaseCarIntentionresult.get("invoiceTitle")));
            purchaseCarIntention
                    .setProjectComment(parsingString(purchaseCarIntentionresult.get("projectComment")));
            // ??
            purchaseCarIntention.setHasActiveOrder(purchaseCarIntentionresult.getBoolean("hasActiveOrder"));
            // ?
            purchaseCarIntention.setHasActiveDrive(purchaseCarIntentionresult.getBoolean("hasActiveDrive"));
            //?
            purchaseCarIntention.setHasUnexePlan(purchaseCarIntentionresult.getBoolean("hasUnexePlan"));
            //???
            purchaseCarIntention.setOrderStatus(parsingString(purchaseCarIntentionresult.get("orderStatus")));
            project.setCustomer(customerEntity);
            project.setPurchaseCarIntention(purchaseCarIntention);

            return project;
        }
        throw new ResponseException();
    } catch (IOException e) {
        Log.e(tag, "Connection network error.", e);
        throw new ResponseException(e);
    } catch (JSONException e) {
        Log.e(tag, "Parsing data error.", e);
        throw new ResponseException(e);
    }
}

From source file:com.roiland.crm.sm.core.service.impl.ProjectAPIImpl.java

/**
 * @see com.roiland.crm.core.service.ProjectAPI#syncContacter(java.lang.String, java.lang.String, java.lang.String, com.roiland.crm.core.model.Customer)
 *///from   www  .  j  a v a 2 s  . c o  m
@Override
public boolean syncContacter(String userID, String dealerOrgID, String projectID, Customer customer)
        throws ResponseException {
    // ?
    boolean success;
    try {
        JSONObject params = new JSONObject();
        params.put("userID", userID);
        params.put("dealerOrgID", dealerOrgID);
        params.put("projectID", projectID);
        //params.put("projectID", customer.getProjectID());
        params.put("customerID", customer.getCustomerID());

        params.put("custName", customer.getCustName());
        params.put("custFromCode", StringUtils.convertNull(customer.getCustFromCode()));
        params.put("custTypeCode", StringUtils.convertNull(customer.getCustTypeCode()));
        params.put("infoFromCode", StringUtils.convertNull(customer.getInfoFromCode()));
        params.put("collectFromCode", StringUtils.convertNull(customer.getCollectFromCode()));
        params.put("custMobile", StringUtils.convertNull(customer.getCustMobile()));
        params.put("custOtherPhone", StringUtils.convertNull(customer.getCustOtherPhone()));
        params.put("genderCode", StringUtils.convertNull(customer.getGenderCode()));
        Log.d(tag, "updateProjectInfo() >> birthday ================== " + customer.getBirthday());
        params.put("birthday", DateFormatUtils.parseDateToLong(customer.getBirthday()));
        params.put("idTypeCode", StringUtils.convertNull(customer.getIdTypeCode()));
        params.put("idNumber", StringUtils.convertNull(customer.getIdNumber()));
        params.put("provinceCode", StringUtils.convertNull(customer.getProvinceCode()));
        params.put("cityCode", StringUtils.convertNull(customer.getCityCode()));
        params.put("districtCode", StringUtils.convertNull(customer.getDistrictCode()));
        params.put("qq", StringUtils.convertNull(customer.getQq()));
        params.put("address", StringUtils.convertNull(customer.getAddress()));
        params.put("postcode", StringUtils.convertNull(customer.getPostcode()));
        params.put("email", StringUtils.convertNull(customer.getEmail()));
        params.put("convContactTime", StringUtils.convertNull(customer.getConvContactTime()));
        params.put("convContactTimeCode", StringUtils.convertNull(customer.getConvContactTimeCode()));
        params.put("expectContactWayCode", StringUtils.convertNull(customer.getExpectContactWayCode()));
        params.put("fax", StringUtils.convertNull(customer.getFax()));
        params.put("existingCarCode", StringUtils.convertNull(customer.getExistingCarCode()));
        params.put("existingCar", StringUtils.convertNull(customer.getExistingCar()));
        params.put("existingCarBrand", StringUtils.convertNull(customer.getExistingCarBrand()));
        params.put("industryCode", StringUtils.convertNull(customer.getIndustryCode()));
        params.put("positionCode", StringUtils.convertNull(customer.getPositionCode()));
        params.put("educationCode", StringUtils.convertNull(customer.getEducationCode()));
        params.put("industry", StringUtils.convertNull(customer.getIndustry()));
        params.put("position", StringUtils.convertNull(customer.getPosition()));
        params.put("education", StringUtils.convertNull(customer.getEducation()));
        params.put("custInterestCode1", StringUtils.convertNull(customer.getCustInterestCode1()));
        params.put("custInterestCode2", StringUtils.convertNull(customer.getCustInterestCode2()));
        params.put("custInterestCode3", StringUtils.convertNull(customer.getCustInterestCode3()));
        params.put("existLisenPlate", StringUtils.convertNull(customer.getExistLisenPlate()));
        params.put("enterpTypeCode", StringUtils.convertNull(customer.getEnterpTypeCode()));
        params.put("enterpPeopleCountCode", StringUtils.convertNull(customer.getEnterpPeopleCountCode()));
        params.put("registeredCapitalCode", StringUtils.convertNull(customer.getRegisteredCapitalCode()));
        params.put("compeCarModelCode", customer.getCompeCarModelCode());
        params.put("rebuyStoreCustTag", customer.getRebuyStoreCustTag());
        params.put("rebuyOnlineCustTag", customer.getRebuyOnlineCustTag());
        params.put("changeCustTag", customer.getChangeCustTag());
        params.put("loanCustTag", customer.getLoanCustTag());
        params.put("headerQuartCustTag", customer.getHeaderQuartCustTag());
        params.put("regularCustTag", customer.getRegularCustTag());
        params.put("regularCustCode", StringUtils.convertNull(customer.getRegularCustCode()));
        params.put("regularCust", StringUtils.convertNull(customer.getRegularCust()));
        params.put("bigCustTag", customer.getBigCustTag());
        params.put("bigCustsCode", StringUtils.convertNull(customer.getBigCustsCode()));
        params.put("custComment", StringUtils.convertNull(customer.getCustComment()));
        params.put("dormancy", (customer.getDormancy() != null ? customer.getDormancy() : false));

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_SYNC_CONTACTER), params, null);

        if (response.isSuccess()) {
            JSONObject jsonBean = new JSONObject(getSimpleString(response));
            success = jsonBean.getBoolean("success");
            return success;
        }
        throw new ResponseException(response.getStatusCode());
    } catch (IOException e) {
        Log.e(tag, "Connection network error.", e);
        throw new ResponseException(e);
    } catch (JSONException e) {
        Log.e(tag, "Parsing data error.", e);
        throw new ResponseException(e);
    } catch (Exception e) {
        throw new ResponseException(e);
    }
}

From source file:com.neuron.trafikanten.dataProviders.trafikanten.TrafikantenDevi.java

@Override
public void run() {
    try {/*from   w  w w .j ava 2s .c  o  m*/
        //String urlString = "http://devi.trafikanten.no/devirest.svc/json/linenames/";
        String urlString = "http://devi.trafikanten.no/devirest.svc/json/lineids/";
        if (lines.length() > 0) {
            urlString = urlString + URLEncoder.encode(lines, "UTF-8");
        } else {
            urlString = urlString + "null";
        }
        urlString = urlString + "/stopids/" + stationId + "/";
        urlString = urlString + "from/" + dateFormater.format(System.currentTimeMillis()) + "/to/2030-12-31";
        Log.i(TAG, "Loading devi data : " + urlString);

        final InputStream stream = HelperFunctions.executeHttpRequest(context, new HttpGet(urlString),
                false).stream;

        /*
         * Parse json
         */
        final JSONArray jsonArray = new JSONArray(HelperFunctions.InputStreamToString(stream));
        final int arraySize = jsonArray.length();
        for (int i = 0; i < arraySize; i++) {
            final JSONObject json = jsonArray.getJSONObject(i);
            DeviData deviData = new DeviData();

            {
                /*
                 * Grab validFrom and check if we should show it or not.
                 */
                deviData.validFrom = HelperFunctions.jsonToDate(json.getString("validFrom"));
                final long dateDiffHours = (deviData.validFrom - Calendar.getInstance().getTimeInMillis())
                        / HelperFunctions.HOUR;
                if (dateDiffHours > 3) {
                    /*
                     * This data starts more than 3 hours into the future, hide it.
                     */
                    continue;
                }
            }
            {
                /*
                 * Grab published, and see if this should be visible yet.
                 */
                final long publishDate = HelperFunctions.jsonToDate(json.getString("published"));
                if (System.currentTimeMillis() < publishDate) {
                    continue;
                }
            }
            {
                /*
                 * Check validto, and see if this should be visible yet.
                 */
                final long validToDate = HelperFunctions.jsonToDate(json.getString("validTo"));
                if (System.currentTimeMillis() > validToDate) {
                    continue;
                }
            }

            /*
             * Grab the easy data
             */
            deviData.title = json.getString("header");
            deviData.description = json.getString("lead");
            deviData.body = json.getString("body");
            deviData.validTo = HelperFunctions.jsonToDate(json.getString("validTo"));
            deviData.important = json.getBoolean("important");
            deviData.id = json.getInt("id");

            {
                /*
                 * Grab lines array
                 */
                final JSONArray jsonLines = json.getJSONArray("lines");
                final int jsonLinesSize = jsonLines.length();
                for (int j = 0; j < jsonLinesSize; j++) {
                    deviData.lines.add(jsonLines.getJSONObject(j).getInt("lineID"));
                }
            }

            {
                /*
                 * Grab stops array
                 */
                final JSONArray jsonLines = json.getJSONArray("stops");
                final int jsonLinesSize = jsonLines.length();
                for (int j = 0; j < jsonLinesSize; j++) {
                    deviData.stops.add(jsonLines.getJSONObject(j).getInt("stopID"));
                }
            }

            ThreadHandlePostData(deviData);
        }

    } catch (Exception e) {
        if (e.getClass() == InterruptedException.class) {
            ThreadHandlePostExecute(null);
            return;
        }
        ThreadHandlePostExecute(e);
        return;
    }
    ThreadHandlePostExecute(null);
}

From source file:com.imaginary.home.cloud.device.Light.java

static void mapLight(@Nonnull ControllerRelay relay, @Nonnull JSONObject json,
        @Nonnull Map<String, Object> state) throws JSONException {
    mapPoweredDevice(relay, json, state);
    state.put("deviceType", "light");
    if (json.has("color")) {
        JSONObject color = json.getJSONObject("color");
        ColorMode colorMode = null;/*ww  w  .  j  a  v a  2s . c  o  m*/
        float[] components = null;

        if (color.has("colorMode") && !color.isNull("colorMode")) {
            try {
                colorMode = ColorMode.valueOf(color.getString("colorMode"));
            } catch (IllegalArgumentException e) {
                throw new JSONException("Invalid color mode: " + color.getString("colorMode"));
            }
        }
        if (color.has("components") && !color.isNull("components")) {
            JSONArray arr = color.getJSONArray("components");
            components = new float[arr.length()];

            for (int i = 0; i < arr.length(); i++) {
                components[i] = (float) arr.getDouble(i);
            }
        }
        if (colorMode != null || components != null) {
            state.put("colorMode", colorMode);
            state.put("colorValues", components);
        }
    }
    if (json.has("brightness") && !json.isNull("brightness")) {
        state.put("brightness", (float) json.getDouble("brightness"));
    }
    if (json.has("supportsColorChanges")) {
        state.put("colorChangeSupported",
                !json.isNull("supportsColorChanges") && json.getBoolean("supportsColorChanges"));
    }
    if (json.has("supportsBrightnessChanges")) {
        state.put("dimmable",
                !json.isNull("supportsBrightnessChanges") && json.getBoolean("supportsBrightnessChanges"));
    }
    if (json.has("colorModes")) {
        JSONArray arr = json.getJSONArray("colorModes");
        ColorMode[] modes = new ColorMode[arr.length()];

        for (int i = 0; i < arr.length(); i++) {
            try {
                modes[i] = ColorMode.valueOf(arr.getString(i));
            } catch (IllegalArgumentException e) {
                throw new JSONException("Invalid color mode: " + arr.getString(i));
            }
        }
        state.put("colorModesSupported", modes);
    }
}

From source file:org.eclipse.orion.internal.server.servlets.xfer.TransferResourceDecorator.java

public void addAtributesFor(HttpServletRequest request, URI resource, JSONObject representation) {

    String servlet = request.getServletPath();
    if (!"/file".equals(servlet) && !"/workspace".equals(servlet))
        return;/*from  www.j  a  va  2 s .co  m*/
    try {
        //don't add import/export directly on a workspace at this point
        if ("/file".equals(servlet))
            addTransferLinks(request, resource, representation);
        JSONArray children = representation.optJSONArray(ProtocolConstants.KEY_CHILDREN);
        if (children != null) {
            for (int i = 0; i < children.length(); i++) {
                JSONObject child = children.getJSONObject(i);
                if (child.getBoolean(ProtocolConstants.KEY_DIRECTORY)) {
                    addTransferLinks(request, resource, child);
                }
            }
        }
    } catch (Exception e) {
        //log and continue
        LogHelper.log(e);
    }
}

From source file:nl.hnogames.domoticz.Domoticz.UpdateParser.java

@Override
public void parseResult(String result) {
    try {/*from  www.jav  a2s . c  om*/
        JSONObject response = new JSONObject(result);
        String version = "";
        if (response.has("revision"))
            version = response.getString("revision");
        if (response.has("HaveUpdate") && !response.getBoolean("HaveUpdate"))
            version = "";

        receiver.onReceiveUpdate(version);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.t2.compassionMeditation.MeditationActivity.java

/**
 * Receives a json string containing data about all of the paired sensors
 * the adds a new BioSensor for each one to the mBioSensors collection
 * //from  w w  w  . j  a  va2 s.  com
 * @param jsonString String containing info on all paired devices
 */
private void populateBioSensors(String jsonString) {

    Log.d(TAG, this.getClass().getSimpleName() + " populateBioSensors");
    // Now clear it out and populate it. The only difference is that
    // if a sensor previously existed, then 
    mBioSensors.clear();
    try {
        JSONArray jsonArray = new JSONArray(jsonString);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Boolean enabled = jsonObject.getBoolean("enabled");
            String name = jsonObject.getString("name");
            String address = jsonObject.getString("address");
            int connectionStatus = jsonObject.getInt("connectionStatus");

            if (name.equalsIgnoreCase("system")) {
                mBluetoothEnabled = enabled;
            } else {

                Log.i(TAG, "Adding sensor " + name + ", " + address + (enabled ? ", enabled" : ", disabled")
                        + " : " + Util.connectionStatusToString(connectionStatus));
                BioSensor bioSensor = new BioSensor(name, address, enabled);
                bioSensor.mConnectionStatus = connectionStatus;
                mBioSensors.add(bioSensor);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
    }
}

From source file:com.t2.compassionMeditation.Graphs1Activity.java

/**
 * Receives a json string containing data about all of the paired sensors
 * the adds a new BioSensor for each one to the mBioSensors collection
 * //  ww w.jav a  2 s . c  o  m
 * @param jsonString String containing info on all paired devices
 */
private void populateBioSensors(String jsonString) {

    Log.d(TAG, this.getClass().getSimpleName() + " populateBioSensors");
    // Now clear it out and populate it. The only difference is that
    // if a sensor previously existed, then 
    mBioSensors.clear();
    try {
        JSONArray jsonArray = new JSONArray(jsonString);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Boolean enabled = jsonObject.getBoolean("enabled");
            String name = jsonObject.getString("name");
            String address = jsonObject.getString("address");
            int connectionStatus = jsonObject.getInt("connectionStatus");

            if (name.equalsIgnoreCase("system")) {
                mBluetoothEnabled = enabled;
            } else {

                Log.d(TAG, "Adding sensor " + name + ", " + address + (enabled ? ", enabled" : ", disabled")
                        + " : " + Util.connectionStatusToString(connectionStatus));
                BioSensor bioSensor = new BioSensor(name, address, enabled);
                bioSensor.mConnectionStatus = connectionStatus;
                mBioSensors.add(bioSensor);
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
    }
}

From source file:com.phonegap.ContactAccessorSdk3_4.java

@Override
/** //from  ww  w. j a v a2 s  .c  om
 * This method takes the fields required and search options in order to produce an 
 * array of contacts that matches the criteria provided.
 * @param fields an array of items to be used as search criteria
 * @param options that can be applied to contact searching
 * @return an array of contacts 
 */
public JSONArray search(JSONArray fields, JSONObject options) {
    String searchTerm = "";
    int limit = Integer.MAX_VALUE;
    boolean multiple = true;

    if (options != null) {
        searchTerm = options.optString("filter");
        if (searchTerm.length() == 0) {
            searchTerm = "%";
        } else {
            searchTerm = "%" + searchTerm + "%";
        }
        try {
            multiple = options.getBoolean("multiple");
            if (!multiple) {
                limit = 1;
            }
        } catch (JSONException e) {
            // Multiple was not specified so we assume the default is true.
        }
    } else {
        searchTerm = "%";
    }

    ContentResolver cr = mApp.getContentResolver();

    Set<String> contactIds = buildSetOfContactIds(fields, searchTerm);
    HashMap<String, Boolean> populate = buildPopulationSet(fields);

    Iterator<String> it = contactIds.iterator();

    JSONArray contacts = new JSONArray();
    JSONObject contact;
    String contactId;
    int pos = 0;
    while (it.hasNext() && (pos < limit)) {
        contact = new JSONObject();
        try {
            contactId = it.next();
            contact.put("id", contactId);

            // Do query for name and note
            Cursor cur = cr.query(People.CONTENT_URI, new String[] { People.DISPLAY_NAME, People.NOTES },
                    PEOPLE_ID_EQUALS, new String[] { contactId }, null);
            cur.moveToFirst();

            if (isRequired("displayName", populate)) {
                contact.put("displayName", cur.getString(cur.getColumnIndex(People.DISPLAY_NAME)));
            }
            if (isRequired("phoneNumbers", populate)) {
                contact.put("phoneNumbers", phoneQuery(cr, contactId));
            }
            if (isRequired("emails", populate)) {
                contact.put("emails", emailQuery(cr, contactId));
            }
            if (isRequired("addresses", populate)) {
                contact.put("addresses", addressQuery(cr, contactId));
            }
            if (isRequired("organizations", populate)) {
                contact.put("organizations", organizationQuery(cr, contactId));
            }
            if (isRequired("ims", populate)) {
                contact.put("ims", imQuery(cr, contactId));
            }
            if (isRequired("note", populate)) {
                contact.put("note", cur.getString(cur.getColumnIndex(People.NOTES)));
            }
            // nickname
            // urls
            // relationship
            // birthdays
            // anniversary

            pos++;
            cur.close();
        } catch (JSONException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        }
        contacts.put(contact);
    }
    return contacts;
}

From source file:com.owncloud.android.lib.resources.status.GetRemoteStatusOperation.java

private boolean tryConnection(OwnCloudClient client) {
    boolean retval = false;
    GetMethod get = null;//  w  ww .  java2s  .co m
    String baseUrlSt = client.getBaseUri().toString();
    try {
        get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);

        HttpParams params = get.getParams().getDefaultParams();
        params.setParameter(HttpMethodParams.USER_AGENT, OwnCloudClientManagerFactory.getUserAgent());
        get.getParams().setDefaults(params);

        client.setFollowRedirects(false);
        boolean isRedirectToNonSecureConnection = false;
        int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
        mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), status,
                get.getResponseHeaders());

        String redirectedLocation = mLatestResult.getRedirectedLocation();
        while (redirectedLocation != null && redirectedLocation.length() > 0 && !mLatestResult.isSuccess()) {

            isRedirectToNonSecureConnection |= (baseUrlSt.startsWith("https://")
                    && redirectedLocation.startsWith("http://"));
            get.releaseConnection();
            get = new GetMethod(redirectedLocation);
            status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT);
            mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), status,
                    get.getResponseHeaders());
            redirectedLocation = mLatestResult.getRedirectedLocation();
        }

        String response = get.getResponseBodyAsString();
        if (status == HttpStatus.SC_OK) {
            JSONObject json = new JSONObject(response);
            if (!json.getBoolean(NODE_INSTALLED)) {
                mLatestResult = new RemoteOperationResult(
                        RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
            } else {
                String version = json.getString(NODE_VERSION);
                OwnCloudVersion ocVersion = new OwnCloudVersion(version);
                if (!ocVersion.isVersionValid()) {
                    mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION);

                } else {
                    // success
                    if (isRedirectToNonSecureConnection) {
                        mLatestResult = new RemoteOperationResult(
                                RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION);
                    } else {
                        mLatestResult = new RemoteOperationResult(
                                baseUrlSt.startsWith("https://") ? RemoteOperationResult.ResultCode.OK_SSL
                                        : RemoteOperationResult.ResultCode.OK_NO_SSL);
                    }

                    ArrayList<Object> data = new ArrayList<Object>();
                    data.add(ocVersion);
                    mLatestResult.setData(data);
                    retval = true;
                }
            }

        } else {
            mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders());
        }

    } catch (JSONException e) {
        mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);

    } catch (Exception e) {
        mLatestResult = new RemoteOperationResult(e);

    } finally {
        if (get != null)
            get.releaseConnection();
    }

    if (mLatestResult.isSuccess()) {
        Log_OC.i(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage());

    } else if (mLatestResult.getException() != null) {
        Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(),
                mLatestResult.getException());

    } else {
        Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage());
    }

    return retval;
}