Example usage for org.json JSONObject has

List of usage examples for org.json JSONObject has

Introduction

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

Prototype

public boolean has(String key) 

Source Link

Document

Determine if the JSONObject contains a specific key.

Usage

From source file:de.kp.ames.office.xml.ImpressBuilder.java

private IPage buildTablePage(OdfDrawPage officePage, JSONObject jPage) throws Exception {

    // provide new impress page
    BriefingTable tablePage = new BriefingTable(impressFile, officePage);

    //********************** header *************************************

    // set title and optionally a subtitle
    tablePage.setTitle(jPage.getString(J_HEADER_TITLE));
    if (jPage.has(J_HEADER_SUBTITLE))
        tablePage.setSubTitle(jPage.getString(J_HEADER_SUBTITLE));

    //********************** content ************************************

    if (jPage.has(J_CONTENT_ISSUE_TABLE))
        tablePage.setTable(jPage.getString(J_CONTENT_ISSUE_TABLE));

    return tablePage;

}

From source file:de.kp.ames.office.xml.ImpressBuilder.java

private IPage buildOneTextPage(OdfDrawPage officePage, JSONObject jPage) throws Exception {

    // provide new impress page
    BriefingOneText textPage = new BriefingOneText(impressFile, officePage);

    //********************** header *************************************

    // set title and optionally a subtitle
    textPage.setTitle(jPage.getString(J_HEADER_TITLE));
    if (jPage.has(J_HEADER_SUBTITLE))
        textPage.setSubTitle(jPage.getString(J_HEADER_SUBTITLE));

    //********************** content ************************************

    // there are three different source to fill the content part
    if (jPage.has(J_CONTENT_ISSUE_TEXT))
        textPage.setOutline(jPage.getString(J_CONTENT_ISSUE_TEXT));

    else if (jPage.has(J_CONTENT_EVALUATION_TEXT))
        textPage.setOutline(jPage.getString(J_CONTENT_EVALUATION_TEXT));

    else if (jPage.has(J_CONTENT_CONCLUSION_TEXT))
        textPage.setOutline(jPage.getString(J_CONTENT_CONCLUSION_TEXT));

    return textPage;

}

From source file:de.kp.ames.office.xml.ImpressBuilder.java

private IPage buildDoubleTextTablePage(OdfDrawPage officePage, JSONObject jPage) throws Exception {

    // provide new impress page

    // tables are actually not supported
    //XDoubleTextTablePage tablePage = new XDoubleTextTablePage(product, officePage);

    BriefingDoubleTextTable tablePage = new BriefingDoubleTextTable(impressFile, officePage);

    //********************** header *************************************

    // set title and optionally a subtitle
    tablePage.setTitle(jPage.getString(J_HEADER_TITLE));
    if (jPage.has(J_HEADER_SUBTITLE))
        tablePage.setSubTitle(jPage.getString(J_HEADER_SUBTITLE));

    //********************** content ************************************

    // there are three different source to fill the content part
    if (jPage.has(J_CONTENT_ISSUE_TABLE))
        tablePage.setLeftTable(jPage.getString(J_CONTENT_ISSUE_TABLE));

    if (jPage.has(J_CONTENT_EVALUATION_TEXT))
        tablePage.setRightText(jPage.getString(J_CONTENT_EVALUATION_TEXT));

    if (jPage.has(J_CONTENT_CONCLUSION_TEXT))
        tablePage.setBottomText(jPage.getString(J_CONTENT_CONCLUSION_TEXT));

    return tablePage;

}

From source file:de.kp.ames.office.xml.ImpressBuilder.java

private IPage buildThreeTextPage(OdfDrawPage officePage, JSONObject jPage) throws Exception {

    // provide new impress page
    BusinessThreeText textPage = new BusinessThreeText(impressFile, officePage);

    //********************** header *************************************

    // set title and optionally a subtitle
    textPage.setTitle(jPage.getString(J_HEADER_TITLE));
    if (jPage.has(J_HEADER_SUBTITLE))
        textPage.setSubTitle(jPage.getString(J_HEADER_SUBTITLE));

    //********************** content ************************************

    // there are three different source to fill the content part
    if (jPage.has(J_CONTENT_ISSUE_TEXT))
        textPage.setLeftText(jPage.getString(J_CONTENT_ISSUE_TEXT));

    if (jPage.has(J_CONTENT_EVALUATION_TEXT))
        textPage.setRightText(jPage.getString(J_CONTENT_EVALUATION_TEXT));

    if (jPage.has(J_CONTENT_CONCLUSION_TEXT))
        textPage.setBottomText(jPage.getString(J_CONTENT_CONCLUSION_TEXT));

    return textPage;

}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes a bean from the JSON body content in the specified HTTP request.
 * /*  w w  w.  j ava2 s . c o  m*/
 * @param request the HTTP request
 * @return the deserialized bean
 * @throws SerializerException if unable to deserialize bean
 */
public E deserialize(HttpRequest request) throws SerializerException {
    if (request.getContentLength() == 0) {
        return null;
    }

    try {
        BufferedReader reader = request.getReader();
        StringBuffer jsonText = new StringBuffer();
        char[] buf = new char[1024];
        int len = 0;

        while ((len = reader.read(buf)) > 0) {
            jsonText.append(buf, 0, len);
        }

        JSONObject object = new JSONObject(jsonText.toString());

        if (!object.has(this.name)) {
            throw new SerializerException("Can't find object " + this.name + " in JSON data");
        }

        object = object.getJSONObject(this.name);
        return deserialize(object);
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize object", e);
    } catch (IOException e) {
        throw new SerializerException("Can't deserialize object", e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes a bean from the JSON body content in the specified message.
 * //from w w w  .  j  a  v a 2  s.c  o  m
 * @param message the message
 * @return the deserialized bean
 * @throws SerializerException if unable to deserialize bean
 */
public E deserialize(String message) throws SerializerException {
    if (message.length() == 0) {
        return null;
    }

    try {
        JSONObject object = new JSONObject(message);

        if (!object.has(this.name)) {
            throw new SerializerException("Can't find object " + this.name + " in JSON data");
        }

        object = object.getJSONObject(this.name);
        return deserialize(object);
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize object", e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a boolean array.
 * /*w w w . j a  v a2s.  c  o  m*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected boolean[] deserializeBooleanArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            boolean[] outArray = new boolean[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = array.getBoolean(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize boolean array property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name from the specified json object into a boolean value.
 * /*  ww w  .j  a  v a 2s. co  m*/
 * @param object the given json object
 * @param name the given property name
 * @return the deserialized boolean value or <code>false</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize boolean property
 */
protected boolean deserializeBoolean(JSONObject object, String name) throws SerializerException {
    if (!object.has(name)) {
        return false;
    }

    try {
        return object.getBoolean(name);
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize boolean property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name from the specified json object into a calendar object.
 * The serialized date must be in 'yyyy-MM-dd'T'HH:mm:ssZ' format.
 * //w ww .j a v a 2s  .com
 * @param object the given json object
 * @param name the given property name
 * @return the deserialized calendar or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize calendar
 */
protected Calendar deserializeCalendar(JSONObject object, String name) throws SerializerException {
    if (!object.has(name)) {
        return null;
    }

    try {
        String value = object.getString(name);

        if (value == null) {
            return null;
        }

        if (value.matches(".*[+-][0-9]{2}:[0-9]{2}$")) {
            int lastIndex = value.lastIndexOf(':');
            value = value.substring(0, lastIndex) + value.substring(lastIndex + 1);
        }

        Date date = parseDate(value);
        String tz = value.substring(value.length() - 5, value.length() - 2);
        TimeZone zone = TimeZone.getTimeZone("GMT" + tz);
        Calendar cal = Calendar.getInstance(zone);
        cal.setTime(date);
        return cal;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize calendar property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name from the specified json object into a data object.
 * The serialized date must be in 'yyyy-MM-dd'T'HH:mm:ssZ' format.
 * /*w  w w  .  j  a  v  a2  s . c o m*/
 * @param object the given json object
 * @param name the given property name
 * @return the deserialized data or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize date
 */
protected Date deserializeDate(JSONObject object, String name) throws SerializerException {
    if (!object.has(name)) {
        return null;
    }

    try {
        String value = object.getString(name);

        if (value.matches(".*[+-][0-9]{2}:[0-9]{2}$")) {
            int lastIndex = value.lastIndexOf(':');
            value = value.substring(0, lastIndex) + value.substring(lastIndex + 1);
        }

        return parseDate(value);
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize date property " + name, e);
    }
}