Example usage for com.google.gwt.json.client JSONValue isString

List of usage examples for com.google.gwt.json.client JSONValue isString

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isString.

Prototype

public JSONString isString() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONString.

Usage

From source file:org.bonitasoft.console.client.admin.page.view.DeletePageFormProblemsCallout.java

License:Open Source License

public DeletePageFormProblemsCallout(final JSONArray formMappings, String pageName) {
    super(_("%pageName% is used by:", new Arg("pageName", pageName)));
    List<String> processDefinitionIds = new ArrayList<String>();
    for (int i = 0; i < formMappings.size(); ++i) {
        JSONObject item = formMappings.get(i).isObject();
        JSONValue value = item.get("processDefinitionId");
        JSONValue type = item.get("type");
        JSONValue taskName = item.get("task");
        String processDefinitionId = value.isString().stringValue();
        if (!processDefinitionIds.contains(processDefinitionId)) {
            processDefinitionIds.add(processDefinitionId);
            new APICaller(ProcessDefinition.get()).get(processDefinitionId, new GetProcessNameCallback());
        }/*from w  ww.  j a v  a  2 s. com*/
    }
}

From source file:org.bonitasoft.web.toolkit.client.common.json.JSonUnserializerClient.java

License:Open Source License

private AbstractTreeNode<String> unserializeTreeNode(final JSONValue value) {
    if (value.isArray() != null) {
        return unserializeTreeNode(value.isArray());
    } else if (value.isObject() != null) {
        return unserializeTreeNode(value.isObject());
    } else if (value.isBoolean() != null) {
        return new TreeLeaf<String>(value.isBoolean().booleanValue() ? "1" : "0");
    } else if (value.isNumber() != null) {
        return new TreeLeaf<String>(value.isNumber().toString());
    } else if (value.isString() != null) {
        return new TreeLeaf<String>(value.isString().stringValue());
    }/*from w  w w  . j a v a  2  s .c o  m*/
    return null;
}

From source file:org.broadleafcommerce.openadmin.client.datasource.dynamic.module.BasicClientEntityModule.java

License:Apache License

protected void buildCriteria(JSONArray criteriaArray, CriteriaTransferObject cto) {
    if (criteriaArray != null) {
        for (int i = 0; i <= criteriaArray.size() - 1; i++) {
            JSONObject itemObj = criteriaArray.get(i).isObject();
            if (itemObj != null) {
                JSONValue val = itemObj.get("fieldName");
                if (val == null) {
                    JSONArray array = itemObj.get("criteria").isArray();
                    buildCriteria(array, cto);
                } else {
                    FilterAndSortCriteria filterCriteria = cto.get(val.isString().stringValue());
                    String[] items = filterCriteria.getFilterValues();
                    String[] newItems = new String[items.length + 1];
                    int j = 0;
                    for (String item : items) {
                        newItems[j] = item;
                        j++;//w w  w.j a  v a  2s  .co  m
                    }
                    JSONValue value = itemObj.get("value");
                    newItems[j] = value.toString();
                    newItems[j] = newItems[j].replaceAll("\"", "");

                    String fieldTypeVal = null;
                    DataSourceField field = dataSource.getField(val.isString().stringValue());
                    if (field != null) {
                        fieldTypeVal = field.getAttribute("fieldType");
                    }
                    SupportedFieldType fieldType = fieldTypeVal == null ? SupportedFieldType.STRING
                            : SupportedFieldType.valueOf(fieldTypeVal);
                    if (fieldType != null) {
                        switch (fieldType) {
                        case DECIMAL:
                            processFilterValueClause(filterCriteria, newItems[j]);
                            break;
                        case INTEGER:
                            processFilterValueClause(filterCriteria, newItems[j]);
                            break;
                        case MONEY:
                            processFilterValueClause(filterCriteria, newItems[j]);
                            break;
                        case DATE:
                            if (newItems.length > 1) {
                                for (int x = 0; x < newItems.length; x++) {
                                    newItems[x] = updateMinutesFromDateFilter(newItems[x], x);
                                }
                                filterCriteria.setFilterValues(newItems);
                            } else {
                                String[] dateItems = new String[2];
                                JSONValue operator = itemObj.get("operator");
                                String op = operator.isString().stringValue();
                                if (op.startsWith("greater")) {
                                    dateItems[0] = newItems[0];
                                    dateItems[1] = null;
                                } else {
                                    dateItems[0] = null;
                                    dateItems[1] = newItems[0];
                                }
                                for (int x = 0; x < dateItems.length; x++) {
                                    dateItems[x] = updateMinutesFromDateFilter(dateItems[x], x);
                                }
                                filterCriteria.setFilterValues(dateItems);
                            }
                            break;
                        default:
                            filterCriteria.setFilterValues(newItems);
                            break;
                        }
                    } else {
                        filterCriteria.setFilterValues(newItems);
                    }
                }
            }
        }
    }
}

From source file:org.broadleafcommerce.openadmin.client.view.dynamic.dialog.FileUploadDialog.java

License:Apache License

public FileUploadDialog() {
    setIsModal(true);/*from  w ww. jav  a2s  .  com*/
    setShowModalMask(true);
    setShowMinimizeButton(false);
    setAutoSize(true);
    setCanDragResize(true);
    setOverflow(Overflow.HIDDEN);

    VStack stack = new VStack();
    stack.setWidth(630);
    stack.setHeight(300);
    dynamicForm = new DynamicForm();
    dynamicForm.setEncoding(Encoding.MULTIPART);
    dynamicForm.setTarget("hidden_frame");
    //dynamicForm.setAction("cms.upload.service");
    dynamicForm.setPadding(10);
    dynamicForm.setHeight100();
    stack.addMember(dynamicForm);

    cancelButton = new IButton("Cancel");
    cancelButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            hide();
        }
    });

    saveButton = new IButton("Upload");
    saveButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (dynamicForm.validate()) {
                String callbackName = JavaScriptMethodHelper
                        .registerCallbackFunction(new JavaScriptMethodCallback() {
                            public void execute(String jsObj) {
                                try {
                                    JSONObject entityJs = JSONParser.parse(jsObj).isObject();
                                    JSONValue errorJs = entityJs.get("error");

                                    if (errorJs != null) {
                                        SC.warn(errorJs.isString().stringValue());
                                        java.util.logging.Logger.getLogger(getClass().toString())
                                                .warning(errorJs.isString().stringValue());
                                        ;
                                    } else {
                                        Entity entity = new Entity();
                                        String type = entityJs.get("type").isString().stringValue();
                                        entity.setType(new String[] { type });

                                        JSONArray propArrayJs = entityJs.get("properties").isArray();
                                        int length = propArrayJs.size();
                                        Property[] props = new Property[length];
                                        for (int j = 0; j <= length - 1; j++) {
                                            JSONObject propJs = propArrayJs.get(j).isObject();
                                            Property property = new Property();
                                            property.setName(propJs.get("name").isString().stringValue());
                                            property.setValue(propJs.get("value").isString().stringValue());
                                            props[j] = property;
                                        }
                                        entity.setProperties(props);
                                        DataSourceModule module = ((DynamicEntityDataSource) dynamicForm
                                                .getDataSource()).getCompatibleModule(OperationType.BASIC);
                                        Record record = module.buildRecord(entity, false);
                                        if (handler != null) {
                                            handler.onItemEdited(new ItemEdited((ListGridRecord) record,
                                                    dynamicForm.getDataSource()));
                                        }
                                    }
                                } catch (Exception e) {
                                    SC.warn(e.getMessage());
                                    java.util.logging.Logger.getLogger(getClass().toString()).log(Level.SEVERE,
                                            e.getMessage(), e);
                                } finally {
                                    uploadProgressWindow.stopProgress();
                                    Timer timer = new Timer() {
                                        public void run() {
                                            uploadProgressWindow.finalizeProgress();
                                            hide();
                                        }
                                    };
                                    timer.schedule(500);
                                }
                            }
                        });
                ((UploadStatusProgress) uploadProgressWindow.getProgressBar()).setCallbackName(callbackName);
                uploadProgressWindow.startProgress();
                dynamicForm.setAction("cms.upload.service?callbackName=" + callbackName);
                dynamicForm.getField("callbackName").setValue(callbackName);
                dynamicForm.submitForm();
                saveButton.disable();
                cancelButton.disable();
            }
        }
    });

    VLayout vLayout = new VLayout();
    vLayout.setAlign(VerticalAlignment.BOTTOM);
    HLayout hLayout = new HLayout(10);
    hLayout.setAlign(Alignment.CENTER);
    hLayout.addMember(saveButton);
    hLayout.addMember(cancelButton);
    hLayout.setLayoutTopMargin(20);
    hLayout.setLayoutBottomMargin(20);
    vLayout.addMember(hLayout);
    stack.addMember(vLayout);

    addItem(stack);

    NamedFrame frame = new NamedFrame("hidden_frame");
    frame.setWidth("1");
    frame.setHeight("1");
    frame.setVisible(false);

    addItem(frame);
}

From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java

License:Apache License

private ColumnFilter parseColumnFilter(JSONObject columnFilterJson) {
    if (columnFilterJson == null)
        return null;

    String columnId = null;//from   ww  w  . java2 s  . com
    String functionType = null;

    JSONValue value = columnFilterJson.get(COLUMNID);
    if (checkNotNull(value, false, "the column id field of a column filter cannot be null.")) {
        columnId = value.isString() != null ? value.isString().stringValue() : null;
    }

    value = columnFilterJson.get(FUNCTION_TYPE);
    if (checkNotNull(value, false, "the function type field of a column filter cannot be null.")) {
        functionType = value.isString() != null ? value.isString().stringValue() : null;
    }

    value = columnFilterJson.get(FUNCTION_TERMS);

    if (isCoreFilter(functionType)) {
        CoreFunctionFilter cff = new CoreFunctionFilter();
        cff.setColumnId(columnId);
        cff.setType(CoreFunctionType.getByName(functionType));

        if (checkNotNull(value, false, "the parameters of a core function filter cannot be null.")) {
            cff.setParameters(parseCoreFunctionParameters(value.isArray()).toArray(new Comparable[] {}));
        }

        return cff;

    } else if (isLogicalFilter(functionType)) {
        LogicalExprFilter lef = new LogicalExprFilter();
        lef.setColumnId(columnId);
        lef.setLogicalOperator(LogicalExprType.getByName(functionType));

        if (checkNotNull(value, false, "the parameters of a logical expression filter cannot be null.")) {
            // Logical expression terms are an an array of column filters
            lef.setLogicalTerms(parseColumnFilters(value.isArray()));
        }

        return lef;
    } else
        throw new RuntimeException("Wrong type of column filter has been specified.");
}

From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java

License:Apache License

private DataSetGroup parseDataSetGroup(JSONObject dataSetGroupJson) {
    if (dataSetGroupJson == null)
        return null;

    DataSetGroup dataSetGroup = new DataSetGroup();

    dataSetGroup.setColumnGroup(null);/*from ww  w .  j a v a2 s . c o  m*/
    JSONValue value = dataSetGroupJson.get(COLUMNGROUP);
    if (value != null)
        dataSetGroup.setColumnGroup(parseColumnGroup(value.isObject()));

    List<GroupFunction> groupFunctions = parseGroupFunctions(
            (value = dataSetGroupJson.get(GROUPFUNCTIONS)) != null ? value.isArray() : null);
    if (groupFunctions != null)
        dataSetGroup.getGroupFunctions().addAll(groupFunctions);

    dataSetGroup.setSelectedIntervalNames(null);
    value = dataSetGroupJson.get(SELECTEDINTERVALS);
    if (value != null)
        dataSetGroup.setSelectedIntervalNames(parseSelectedIntervals(value.isArray()));

    dataSetGroup.setJoin(false);
    value = dataSetGroupJson.get(JOIN);
    if (value != null)
        dataSetGroup.setJoin(Boolean.valueOf(value.isString().stringValue()));

    return dataSetGroup;
}

From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java

License:Apache License

private ColumnGroup parseColumnGroup(JSONObject columnGroupJson) {
    if (columnGroupJson == null)
        return null;
    ColumnGroup columnGroup = new ColumnGroup();
    JSONValue value = columnGroupJson.get(SOURCEID);
    columnGroup.setSourceId(value != null ? value.isString().stringValue() : null);
    columnGroup.setColumnId(/*from  w  w  w  .  ja va 2s  .co m*/
            (value = columnGroupJson.get(COLUMNID)) != null ? value.isString().stringValue() : null);
    columnGroup.setStrategy((value = columnGroupJson.get(GROUPSTRATEGY)) != null
            ? GroupStrategy.getByName(value.isString().stringValue())
            : null);
    columnGroup.setMaxIntervals((value = columnGroupJson.get(MAXINTERVALS)) != null
            ? Integer.parseInt(value.isString().stringValue())
            : -1);
    columnGroup.setIntervalSize(
            (value = columnGroupJson.get(INTERVALSIZE)) != null ? value.isString().stringValue() : null);
    columnGroup.setAscendingOrder(
            (value = columnGroupJson.get(ASCENDING)) != null ? Boolean.valueOf(value.isString().stringValue())
                    : false);
    columnGroup.setFirstMonthOfYear((value = columnGroupJson.get(FIRSTMONTHOFYEAR)) != null
            ? Month.getByName(value.isString().stringValue())
            : null);
    columnGroup.setFirstDayOfWeek((value = columnGroupJson.get(FIRSTDAYOFWEEK)) != null
            ? DayOfWeek.getByName(value.isString().stringValue())
            : null);
    return columnGroup;
}

From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java

License:Apache License

private GroupFunction parseGroupFunction(JSONObject groupFunctionJson) {
    if (groupFunctionJson == null)
        return null;
    GroupFunction groupFunction = new GroupFunction();
    JSONValue value = groupFunctionJson.get(SOURCEID);
    groupFunction.setSourceId(value != null ? value.isString().stringValue() : null);
    groupFunction.setColumnId(//from  w  w  w.j a v a 2  s.co  m
            (value = groupFunctionJson.get(COLUMNID)) != null ? value.isString().stringValue() : null);
    groupFunction.setFunction((value = groupFunctionJson.get(FUNCTION)) != null
            ? AggregateFunctionType.getByName(value.isString().stringValue())
            : null);
    return groupFunction;
}

From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java

License:Apache License

private ColumnSort parseColumnSort(JSONObject columnSortJson) {
    if (columnSortJson == null)
        return null;
    ColumnSort columnSort = new ColumnSort();
    JSONValue value = columnSortJson.get(COLUMNID);
    columnSort.setColumnId(value != null ? value.isString().stringValue() : null);
    columnSort.setOrder((value = columnSortJson.get(SORTORDER)) != null
            ? SortOrder.getByName(value.isString().stringValue())
            : null);/*from  www . j a v  a 2  s  .  com*/
    return columnSort;
}

From source file:org.dashbuilder.displayer.client.json.DisplayerSettingsJSONMarshaller.java

License:Apache License

public DisplayerSettings fromJsonString(String jsonString) {
    DisplayerSettings ds = new DisplayerSettings();

    if (!StringUtils.isBlank(jsonString)) {

        JSONObject parseResult = JSONParser.parseStrict(jsonString).isObject();

        if (parseResult != null) {

            // UUID
            JSONValue uuidValue = parseResult.get(SETTINGS_UUID);
            ds.setUUID(uuidValue != null && uuidValue.isString() != null ? uuidValue.isString().stringValue()
                    : null);//from  ww  w.j a  v  a 2 s  . co m

            // First look if a dataset 'on-the-fly' has been specified
            JSONValue data = parseResult.get(JSON_DATASET_PREFIX);
            if (data != null) {
                DataSet dataSet = dataSetJSONMarshaller.fromJson(data.isObject());
                ds.setDataSet(dataSet);

                // Remove from the json input so that it doesn't end up in the settings map.
                parseResult.put(JSON_DATASET_PREFIX, null);

                // If none was found, look for a dataset lookup definition
            } else if ((data = parseResult.get(JSON_DATASET_LOOKUP_PREFIX)) != null) {
                DataSetLookup dataSetLookup = dataSetLookupJSONMarshaller.fromJson(data.isObject());
                ds.setDataSetLookup(dataSetLookup);

                // Remove from the json input so that it doesn't end up in the settings map.
                parseResult.put(JSON_DATASET_LOOKUP_PREFIX, null);

            } else {
                throw new RuntimeException("Either a DataSet or a DataSetLookup should be specified");
            }

            // Now parse all other settings
            ds.setSettingsFlatMap(parseSettingsFromJson(parseResult));
        }
    }
    return ds;
}