Example usage for org.json JSONObject optString

List of usage examples for org.json JSONObject optString

Introduction

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

Prototype

public String optString(String key) 

Source Link

Document

Get an optional string associated with a key.

Usage

From source file:org.cruxframework.crux.widgets.rebind.deviceadaptivegrid.DeviceAdaptiveGridFactory.java

/**
 * @param gridElem//from   w  w w  . ja v  a  2 s. co  m
 * @return
 */
protected boolean getStretchColumns(JSONObject gridElem) {
    String stretchColumns = gridElem.optString("stretchColumns");

    if (stretchColumns != null && stretchColumns.trim().length() > 0) {
        return Boolean.parseBoolean(stretchColumns);
    }

    return false;
}

From source file:org.cruxframework.crux.widgets.rebind.deviceadaptivegrid.DeviceAdaptiveGridFactory.java

/**
 * @param gridElem//from w ww. j a  va  2 s. c  o m
 * @return
 */
protected int getCellSpacing(JSONObject gridElem) {
    String spacing = gridElem.optString("cellSpacing");

    if (spacing != null && spacing.trim().length() > 0) {
        return Integer.parseInt(spacing);
    }

    return 1;
}

From source file:org.cruxframework.crux.widgets.rebind.deviceadaptivegrid.DeviceAdaptiveGridFactory.java

/**
 * @param gridElem//from  ww w .j a  va  2 s.c o  m
 * @return
 */
protected String getRowSelectionModel(JSONObject gridElem) {
    String rowSelection = gridElem.optString("rowSelection");

    RowSelectionModel ret = RowSelectionModel.unselectable;
    if (rowSelection != null && rowSelection.length() > 0) {
        if ("unselectable".equals(rowSelection)) {
            ret = RowSelectionModel.unselectable;
        } else if ("single".equals(rowSelection)) {
            ret = RowSelectionModel.single;
        } else if ("multiple".equals(rowSelection)) {
            ret = RowSelectionModel.multiple;
        } else if ("singleRadioButton".equals(rowSelection)) {
            ret = RowSelectionModel.singleRadioButton;
        } else if ("multipleCheckBox".equals(rowSelection)) {
            ret = RowSelectionModel.multipleCheckBox;
        } else if ("multipleCheckBoxSelectAll".equals(rowSelection)) {
            ret = RowSelectionModel.multipleCheckBoxSelectAll;
        }
    }

    return RowSelectionModel.class.getCanonicalName() + "." + ret.toString();
}

From source file:org.cruxframework.crux.widgets.rebind.deviceadaptivegrid.DeviceAdaptiveGridFactory.java

/**
 * @param gridElem//from w w  w  .  ja v  a 2  s.  c o m
 * @return
 */
protected int getPageSize(JSONObject gridElem) {
    String pageSize = gridElem.optString("pageSize");

    if (pageSize != null && pageSize.length() > 0) {
        return Integer.parseInt(pageSize);
    }

    return Integer.MAX_VALUE;
}

From source file:org.cruxframework.crux.widgets.rebind.deviceadaptivegrid.DeviceAdaptiveGridFactory.java

/**
 * @param out//from  w  w  w .  jav a  2s . c  o m
 * @param gridElem
 * @return
 * @throws CruxGeneratorException
 */
protected String getColumnDefinitions(SourcePrinter out, WidgetCreatorContext context)
        throws CruxGeneratorException {
    String defs = createVariableName("defs");

    JSONObject[] deviceChildren = new JSONObject[2];

    try {
        deviceChildren[0] = context.getWidgetElement().getJSONArray("_children").getJSONObject(0);
        deviceChildren[1] = context.getWidgetElement().getJSONArray("_children").getJSONObject(1);
    } catch (JSONException e) {
        throw new CruxGeneratorException("The widget [" + context.getWidgetId() + "], declared on View ["
                + getView().getId() + "], must contain both large and small columns.");
    }

    if (deviceChildren == null || deviceChildren.length < 2) {
        throw new CruxGeneratorException("The widget [" + context.getWidgetId() + "], declared on View ["
                + getView().getId() + "], must contain both large and small columns.");
    }

    out.println(DeviceAdaptiveGridColumnDefinitions.class.getCanonicalName() + " " + defs + " = new "
            + DeviceAdaptiveGridColumnDefinitions.class.getCanonicalName() + "();");

    for (int deviceIndex = 0; deviceIndex < deviceChildren.length; deviceIndex++) {
        JSONArray colElems = ensureChildren(deviceChildren[deviceIndex], false, context.getWidgetId());
        Size deviceSize = deviceChildren[deviceIndex].toString().contains("largeColumns") ? Size.large
                : Size.small;

        int colsSize = colElems.length();
        if (colsSize > 0) {
            for (int i = 0; i < colsSize; i++) {
                JSONObject colElem = colElems.optJSONObject(i);
                if (colElem != null) {
                    if (!getChildName(colElem).equals("rowDetails")) {
                        String width = colElem.optString("width");
                        String strVisible = colElem.optString("visible");
                        String strSortable = colElem.optString("sortable");
                        String strWrapLine = colElem.optString("wrapLine");
                        String strFrozen = colElem.optString("frozen");
                        String label = colElem.optString("label");
                        String key = colElem.optString("key");
                        String strFormatter = colElem.optString("formatter");
                        String hAlign = colElem.optString("horizontalAlignment");
                        String vAlign = colElem.optString("verticalAlignment");

                        boolean visible = (strVisible != null && strVisible.length() > 0)
                                ? Boolean.parseBoolean(strVisible)
                                : true;
                        boolean sortable = (strSortable != null && strSortable.length() > 0)
                                ? Boolean.parseBoolean(strSortable)
                                : true;
                        boolean wrapLine = (strWrapLine != null && strWrapLine.length() > 0)
                                ? Boolean.parseBoolean(strWrapLine)
                                : true;
                        boolean frozen = (strFrozen != null && strFrozen.length() > 0)
                                ? Boolean.parseBoolean(strFrozen)
                                : false;
                        String formatter = (strFormatter != null && strFormatter.length() > 0) ? strFormatter
                                : null;
                        label = (label != null && label.length() > 0) ? resolveI18NString(label)
                                : EscapeUtils.quote("");

                        String def = createVariableName("def");

                        String columnType = getChildName(colElem);
                        if ("dataColumn".equals(columnType)) {

                            String editorCreatorVarName = getDataColumnEditorCreator(out, colElem, context);

                            out.println(ColumnDefinition.class.getCanonicalName() + " " + def + " = new "
                                    + DataColumnDefinition.class.getCanonicalName() + "(" + label + ", "
                                    + EscapeUtils.quote(width) + ", "
                                    + getContext().getFormatters().getFormatterInstantionCommand(formatter)
                                    + ", " + visible + ", " + sortable + ", " + wrapLine + ", " + frozen + ", "
                                    + AlignmentAttributeParser.getHorizontalAlignment(hAlign,
                                            HasHorizontalAlignment.class.getCanonicalName() + ".ALIGN_CENTER")
                                    + ", "
                                    + AlignmentAttributeParser.getVerticalAlignment(vAlign,
                                            HasVerticalAlignment.class.getCanonicalName() + ".ALIGN_MIDDLE")
                                    + ", " + editorCreatorVarName + ");");
                        } else if ("actionColumn".equals(columnType)) {
                            String widgetCreator = getWidgetColumnCreator(out, colElem, context);

                            out.println(ColumnDefinition.class.getCanonicalName() + " " + def + " = new "
                                    + ActionColumnDefinition.class.getCanonicalName() + "(" + label + ", "
                                    + EscapeUtils.quote(width) + ", " + widgetCreator + ", " + Boolean.FALSE
                                    + ", " + frozen + ", "
                                    + AlignmentAttributeParser.getHorizontalAlignment(hAlign,
                                            HasHorizontalAlignment.class.getCanonicalName() + ".ALIGN_CENTER")
                                    + ", "
                                    + AlignmentAttributeParser.getVerticalAlignment(vAlign,
                                            HasVerticalAlignment.class.getCanonicalName() + ".ALIGN_MIDDLE")
                                    + ");");
                        } else if ("widgetColumn".equals(columnType)) {
                            String widgetCreator = getWidgetColumnCreator(out, colElem, context);

                            out.println(ColumnDefinition.class.getCanonicalName() + " " + def + " = new "
                                    + WidgetColumnDefinition.class.getCanonicalName() + "(" + label + ", "
                                    + EscapeUtils.quote(width) + ", " + widgetCreator + ", " + visible + ", "
                                    + frozen + ", "
                                    + AlignmentAttributeParser.getHorizontalAlignment(hAlign,
                                            HasHorizontalAlignment.class.getCanonicalName() + ".ALIGN_CENTER")
                                    + ", "
                                    + AlignmentAttributeParser.getVerticalAlignment(vAlign,
                                            HasVerticalAlignment.class.getCanonicalName() + ".ALIGN_MIDDLE")
                                    + ");");
                        } else {
                            throw new CruxGeneratorException("Grid [" + context.readWidgetProperty("id")
                                    + "] has an invalid column (unexpected column type).");
                        }

                        out.print(defs + ".add(" + Size.class.getCanonicalName() + "." + deviceSize.name()
                                + ", " + EscapeUtils.quote(key) + ", " + def + ");");
                    }
                }
            }
        } else {
            throw new CruxGeneratorException("Grid [" + context.readWidgetProperty("id") + "] has no column.");
        }
    }

    return defs;
}

From source file:org.cruxframework.crux.widgets.rebind.deviceadaptivegrid.DeviceAdaptiveGridFactory.java

protected String getDataColumnEditorCreator(SourcePrinter out, JSONObject colElem,
        WidgetCreatorContext context) {/*ww  w .  j a  va  2 s  .c o  m*/
    String editorCreatorVarName = "null";

    JSONObject child = ensureFirstChild(colElem, true, context.getWidgetId());

    if (child != null) {
        editorCreatorVarName = createVariableName("dataColumnEditor");

        String packageName = DataColumnEditorCreators.class.getPackage().getName();
        String classSimpleName = ("DColEdit_" + getView().getId() + "_" + context.getWidgetId() + "_"
                + colElem.optString("key")).replaceAll("[^a-zA-Z0-9\\$]", "_");
        String classCanonicalName = packageName + "." + classSimpleName;

        out.println(classCanonicalName + " " + editorCreatorVarName + " = new " + classCanonicalName + "();");

        DeviceAdaptiveDataColumnEditorCreatorFactory dataColEditorFactory = new DeviceAdaptiveDataColumnEditorCreatorFactory(
                classSimpleName, packageName, this, context, child, this.getLoggerVariable(),
                getDeclaredMessages());

        dataColEditorFactory.createEditorCreator();
    }

    return editorCreatorVarName;
}

From source file:net.yama.android.managers.connection.ApplicationException.java

/**
 * Returns a string returned by meetup.com
 * @param ex//  w w w .j a  v a  2s .  c o m
 * @return
 */
private String getOAuthMessage(OAuthProblemException ex) {
    String message = null;

    Map<String, Object> exParams = ex.getParameters();
    for (Map.Entry<String, Object> entry : exParams.entrySet()) {
        String k = entry.getKey();
        Object v = entry.getValue();
        if (k.startsWith("{")) {
            JSONObject json;
            try {
                json = new JSONObject(k);
                String details = json.optString("details");
                message = details;
                break;
            } catch (JSONException e1) {

            }
        }
    }
    return message;
}

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

/**
 * Computes the name of the resource to be created by a POST operation. Returns
 * an empty string if the name was not specified.
 *//*from w  w  w .j a  va2s  .c  om*/
private String computeName(HttpServletRequest request, JSONObject requestObject) {
    String name = decodeSlug(request.getHeader(ProtocolConstants.HEADER_SLUG));

    //next comes the source location for a copy/move
    if (name == null || name.length() == 0) {
        String location = requestObject.optString(ProtocolConstants.KEY_LOCATION);
        int lastSlash = location.lastIndexOf('/');
        if (lastSlash >= 0)
            name = location.substring(lastSlash + 1);
    }
    //finally use the name attribute from the request body
    if (name == null || name.length() == 0)
        name = requestObject.optString(ProtocolConstants.KEY_NAME);
    return name;
}

From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java

public boolean getTokens(Context ctx, String id, String login) {

    if (mOcp == null)
        return false;

    try {//from w  w  w.  ja  va  2  s  .co m

        String requestObject = null;
        String authorization_endpoint = null;
        try {

            // retrieve openid config
            JSONObject json = getHttpJSON(mOcp.m_server_url + openIdConfigurationUrl);
            if (json == null) {
                Logd(TAG, "could not get openid-configuration on server : " + mOcp.m_server_url);
                return false;
            }

            // get authorization end_point
            authorization_endpoint = json.optString("authorization_endpoint");

            Logd(TAG, "authorization_endpoint : " + authorization_endpoint);

            // TAZTAG : no use to define request object if key jwt is not used ?
            if (mUsePrivateKeyJWT) {
                // get jwks_uri of the server
                String jwks_uri = json.optString("jwks_uri");
                if (jwks_uri == null || jwks_uri.length() < 1) {
                    Logd(TAG, "could not get jwks_uri from openid-configuration on server : "
                            + mOcp.m_server_url);
                    return false;
                }
                Logd(TAG, "jwks_uri : " + jwks_uri);

                // get jwks
                String jwks = getHttpString(jwks_uri);
                if (jwks == null || jwks.length() < 1) {
                    Logd(TAG, "could not get jwks_uri content from : " + jwks_uri);
                    return false;
                }
                Logd(TAG, "jwks : " + jwks);

                // extract public key
                PublicKey serverPubKey = KryptoUtils.pubKeyFromJwk(jwks);
                if (serverPubKey == null) {
                    Logd(TAG, "could not extract public key from jwk : " + jwks);
                    return false;
                }

                // get oidc request object
                requestObject = secureProxy.getOidcRequestObject(mOcp.m_server_url, mOcp.m_client_id,
                        mOcp.m_scope, serverPubKey);
                Logd(TAG, "secureStorage requestObject : " + requestObject);
            }

        } catch (Exception ee) {
            // error generating request object
            ee.printStackTrace();
            return false;
        }

        // build post parameters
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
        nameValuePairs.add(new BasicNameValuePair("redirect_uri", mOcp.m_redirect_uri));
        nameValuePairs.add(new BasicNameValuePair("response_type", "code"));
        nameValuePairs.add(new BasicNameValuePair("scope", mOcp.m_scope));

        nameValuePairs.add(new BasicNameValuePair("client_id", secureProxy.getClientId()));

        //         nameValuePairs.add(new BasicNameValuePair("nonce",         mOcp.m_nonce));
        nameValuePairs.add(new BasicNameValuePair("nonce", "1234567890"));
        if (!isEmpty(requestObject)) {
            nameValuePairs.add(new BasicNameValuePair("request", requestObject));
        }
        nameValuePairs.add(new BasicNameValuePair("prompt", "consent"));

        // get URL encoded string from list of key value pairs
        String postParams = getQuery(nameValuePairs);

        Log.d(TAG, "get URL encoded string from list of key value pairs : " + postParams);

        // launch webview

        // init intent
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setClass(ctx, WebViewActivity.class);

        // prepare request parameters
        intent.putExtra("id", id);

        intent.putExtra("server_url", authorization_endpoint);
        intent.putExtra("redirect_uri", mOcp.m_redirect_uri);
        intent.putExtra("client_id", mOcp.m_client_id);
        if (login != null)
            intent.putExtra("login", login);

        intent.putExtra("postParams", postParams);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_NO_ANIMATION);

        // display webview
        ctx.startActivity(intent);

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java

static String getEndpointFromConfigOidc(String endpoint, String server_url) {

    if (isEmpty(endpoint) || isEmpty(server_url))
        return null;

    // retrieve openid-config
    JSONObject json = getHttpJSON(server_url + openIdConfigurationUrl);
    if (json == null) {
        Logd(TAG, "getEndpointFromConfigOidc : could not get openid-configuration on server " + server_url);
        return null;
    }//from  w  ww .  j av  a2s  .c o  m

    // get specified endpoint
    String server_endpoint = json.optString(endpoint);
    if (isEmpty(server_endpoint)) {
        Logd(TAG, "getEndpointFromConfigOidc : could not get " + endpoint + " on server " + server_url);
        return null;
    }

    // return found value
    return server_endpoint;
}