List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:eu.riscoss.client.riskconfs.RiskConfsModule.java
License:Apache License
protected void onAddNew() { //String name = Window.prompt( "Name:", "" ); String name = riskConfName.getText().trim(); if (name == null || "".equals(name)) return;// w w w . j a v a 2s.co m /**Button bOk = new Button( "Ok" ); //, new ClickHandler() { bOk.addClickHandler( new ClickWrapper<JSONArray>( (JSONArray)response.isArray() ) { @Override public void onClick(ClickEvent event) { String name = txt.getText().trim(); if (name == null || name.equals("") ) return; //String s = RiscossUtil.sanitize(txt.getText().trim());//attention:name sanitation is not directly notified to the user if (!RiscossUtil.sanitize(name).equals(name)){ //info: firefox has some problem with this window, and fires asssertion errors in dev mode Window.alert("Name contains prohibited characters (##,@,\") \nPlease re-enter name"); return; } for(int i=0; i<getValue().size(); i++){ JSONObject o = (JSONObject)getValue().get(i); if (name.equals(o.get( "name" ).isString().stringValue())){ //info: firefox has some problem with this window, and fires asssertion errors in dev mode Window.alert("Layer name already in use.\nPlease re-enter name."); return; } } RiscossJsonClient.createEntity( getChosenName(), getChosenLayer(), getChosenParent(), new JsonCallback() { @Override public void onFailure(Method method, Throwable exception) { Window.alert( exception.getMessage() ); } @Override public void onSuccess(Method method, JSONValue response) { String entity = response.isObject().get( "name" ).isString().stringValue(); EntityInfo info = new EntityInfo( entity ); info.setLayer( JsonUtil.getValue( response, "layer", "" ) ); insertEntityIntoTable( info ); dialog.hide(); } } ); } }); grid.setWidget( 3, 1, bOk); grid.setWidget( 3, 2, new Button( "Cancel", new ClickHandler() { @Override public void onClick(ClickEvent event) { //Window.Location.reload(); dialog.hide(); } } )) ; */ while (!RiscossUtil.sanitize(name).equals(name)) { name = Window.prompt("Name contains prohibited characters (##,@,\") \nRe-enter name:", ""); if (name == null || "".equals(name)) return; } RiscossJsonClient.createRC(name, new JsonCallback() { @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { dataProvider.getList().add(new RCInfo(response.isObject().get("name").isString().stringValue())); } }); }
From source file:eu.riscoss.client.riskconfs.RiskConfsModule.java
License:Apache License
protected void hasRiskSessions() { hasRisk = false;/*from w ww. j av a 2 s .c o m*/ RiscossJsonClient.listRiskAnalysisSessions("", selectedRC, new JsonCallback() { @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { if (response.isObject().get("list").isArray().size() > 0) hasRisk = true; deleteRC(); } }); }
From source file:eu.riscoss.client.SimpleRiskCconf.java
License:Apache License
public SimpleRiskCconf(JSONValue response) { if (response == null) response = new JSONObject(); this.json = response.isObject(); if (this.json == null) { this.json = new JSONObject(); }// ww w. ja v a2 s .c om }
From source file:fast.mediation.client.gui.MediationRuleGUI.java
License:Open Source License
/** * This method transforms the data with the rules * to the this.factsTree (JSON)//from ww w . j av a 2s. c o m * */ public void transform(JSONValue rootJsonValue, FASTMappingRule rule, TreeItem treeItem) { if (RuleUtil.isCompleteRule(rule)) { String kind = rule.getKind(); String targetElemName = rule.getTargetElemName(); //create a handler for operations in the decoded fromField OperationHandler opHandler = new OperationHandler(rule.getSourceTagname()); String sourceTagname = opHandler.getLastSourceTagname(); //add the handler within parse results into the rule rule.setOperationHandler(opHandler); JSONArray elements = new JSONArray(); //for normal sourceTagnames retrieve the elements recursive if (!sourceTagname.endsWith("_Item")) { RuleUtil.jsonValuesByTagName(elements, rootJsonValue, sourceTagname); } //special case: array items else { JSONObject obj = rootJsonValue.isObject(); if (obj != null) { String jsonString = rootJsonValue.toString(); jsonString = jsonString.substring(jsonString.indexOf("["), jsonString.lastIndexOf("]") + 1); rootJsonValue = JSONParser.parse(jsonString); } //add children to elements directly JSONArray jsonArray = rootJsonValue.isArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { JSONValue kid = jsonArray.get(i); int index = elements.size(); elements.set(index, kid); } } } //"createObject" creates an object for every element in the list //and starts recursive call of transform if (kind.equals("createObject")) { for (int i = 0; i < elements.size(); i++) { JSONValue tmpElement = elements.get(i); TreeItem kidItem = treeItem.addItem(targetElemName); transformKids(tmpElement, rule, kidItem); } } //"fillAttribute" fills attribute strings on right position else if (kind.equals("fillAttributes")) { String nodeValue = opHandler.executeOperations(rootJsonValue); treeItem.addItem(targetElemName + ": " + nodeValue); } else if (rule.getKind().equals("dummyRule")) { //TODO dk dummyRule .. i think, searchin in JSON //is not depended to a reduced JSONValue, so we do not //need to cut first lvl.. or?!?!? } } }
From source file:fast.mediation.client.gui.MediationRuleGUI.java
License:Open Source License
/** * recursive method to generate a tree that represents a json value * *//*from w w w.j a v a 2s .com*/ private void buildJsonTree(TreeItem parentItem, JSONValue node, String parentName) { //if it's an object, build the tree for all children JSONArray jsonArray = node.isArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { //add a section item for every child TreeItem treeSection = parentItem.addItem(parentName + "_Item:"); treeSection.setState(true); buildJsonTree(treeSection, jsonArray.get(i), parentName); } } //if it's a string add the leaf (maybe for isNumber() too) JSONString jsonString = node.isString(); if (jsonString != null) { String parentText = parentItem.getText(); String attributeText = jsonString.stringValue(); parentItem.setText(parentText + " " + attributeText); } //if it's an object, build the tree for all children JSONObject operator = node.isObject(); if (operator != null) { Set<String> keys = operator.keySet(); for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); TreeItem treeSection = parentItem.addItem(key + ":"); treeSection.setState(true); JSONValue child = operator.get(key); buildJsonTree(treeSection, child, key); } } }
From source file:fast.servicescreen.client.gui.codegen_js.CodeGenerator.java
License:Open Source License
/** * This method send the current template to * an service which writes a js and a html file with it as content. * *//*from www .ja v a 2 s . c om*/ public void write_JS_File(boolean isLocal) { //create GWT service impl. service = GWT.create(RequestService.class); //send pre - trans - post code to server service.saveJsFileOnServer(isLocal, screen.getName(), prehtml, helperMethods + rootTemplate, posthtml, new AsyncCallback<String>() { @Override public void onSuccess(String result) { GWT.log("Writing .js file to RequestService succed..", null); Window.alert(result); } @Override public void onFailure(Throwable caught) { GWT.log("ERROR while writing .js file to RequestService..", null); Window.alert(caught.getLocalizedMessage()); } }); //shareBuildingBlock(): //url and header String url = "http://localhost:13337/" /*URL_Settings.getGVS_URL()*/ + "buildingblock/resource"; final String cookie = "fastgvsid=" + Cookies.getCookie("fastgvsid"); final HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Cookie", cookie); //build operator String jsonObject = createBuildingBlock(); String body = "buildingblock=" + jsonObject; //upload to GVS service.sendHttpRequest_POST(url, headers, body, new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(String result) { if (result != null && result != "-1" && result.startsWith("{")) { JSONValue resourceVal = JSONParser.parse(result); JSONObject resourceObj = resourceVal.isObject(); JSONValue idVal = resourceObj.get("id"); JSONNumber idNum = idVal.isNumber(); String id = idNum.toString(); if (id != null) { String shareUrl = "http://127.0.0.1:13337/" + "buildingblock/" + id + "/sharing"; service.sendHttpRequest_POST(shareUrl, headers, "", new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { //Resource couldn't be shared System.out.println("Resource couldn't be shared" + caught.getMessage()); } @Override public void onSuccess(String result) { //Resource was shared System.out.println("Resource was shared: " + result); } }); } } } }); }
From source file:fast.servicescreen.client.gui.RuleUtil.java
License:Open Source License
/** * Recursive method for retrieving all jsonvalues for a specified tagName * *//*w ww .ja v a 2s . c o m*/ public static void jsonValuesByTagName(JSONArray elements, JSONValue root, String tagName) { //if object search on first layer. on failure begin depth-search JSONObject object = root.isObject(); if (object != null) { //get (first layer) keys contained in the JSONValue Set<String> keys = object.keySet(); //seek on first layer for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); //found - add it and stop if (key.equals(tagName)) { int index = elements.size(); elements.set(index, object.get(key)); //stop - key can occur only once on first layer break; } //nothing found - depth-search else { jsonValuesByTagName(elements, object.get(key), tagName); } } } //if it's an array, search among it's children by calling recursive method //for every child JSONArray jsonArray = root.isArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { jsonValuesByTagName(elements, jsonArray.get(i), tagName); } } //if it's a matching boolean, number or string: add it JSONBoolean jsonBoolean = root.isBoolean(); if (jsonBoolean != null && tagName.equals(jsonBoolean.booleanValue())) { int index = elements.size(); elements.set(index, jsonBoolean); } JSONNumber jsonNumber = root.isNumber(); if (jsonNumber != null && tagName.equals(jsonNumber.doubleValue())) { int index = elements.size(); elements.set(index, jsonNumber); } JSONString jsonString = root.isString(); if (jsonString != null && tagName.equals(jsonString.stringValue())) { int index = elements.size(); elements.set(index, jsonString); } }
From source file:fast.servicescreen.client.gui.SaveLoadJsonHandler.java
License:Open Source License
public void loadJson(JSONValue savedJson) { JSONObject operator = savedJson.isObject(); if (operator == null) { return;// www. j a va 2s. c o m } // name JSONString name = operator.get("name").isString(); if (name != null) { screen.set("name", name.stringValue()); } //preconditions JSONArray preconditions = operator.get("preconditions").isArray(); if (preconditions != null) { screen.removeAllFromPreconditions(); for (int i = 0; i < preconditions.size(); i++) { JSONObject preCondJson = preconditions.get(i).isObject(); if (preCondJson == null) { return; } FactPort preCond = new FactPort(); String preCondName = preCondJson.get("name").isString().stringValue(); preCond.set("name", preCondName); String preCondFactType = preCondJson.get("factType").isString().stringValue(); preCond.set("factType", preCondFactType); String preCondExampleValue = preCondJson.get("exampleValue").isString().stringValue(); preCond.set("exampleValue", preCondExampleValue); screen.addToPreconditions(preCond); } } //postconditions JSONArray postconditions = operator.get("postconditions").isArray(); if (postconditions != null) { screen.removeAllFromPostconditions(); for (int i = 0; i < postconditions.size(); i++) { JSONObject postCondJson = postconditions.get(i).isObject(); if (postCondJson == null) { return; } FactPort postCond = new FactPort(); String postCondName = postCondJson.get("name").isString().stringValue(); postCond.set("name", postCondName); String postCondFactType = postCondJson.get("factType").isString().stringValue(); postCond.set("factType", postCondFactType); String postCondExampleValue = postCondJson.get("exampleValue").isString().stringValue(); postCond.set("exampleValue", postCondExampleValue); screen.addToPostconditions(postCond); } } // requestTemplate JSONString requestTemplate = operator.get("requestTemplate").isString(); if (requestTemplate != null) { screen.set("requestTemplate", requestTemplate.stringValue()); } JSONObject rules = operator.get("rules").isObject(); JSONObject jsonRoot = rules.get("rootRule").isObject(); if (jsonRoot != null) { FASTMappingRule rootRule = jsonRulesToFASTRules(jsonRoot); screen.removeAllFromMappingRules(); screen.addToMappingRules(rootRule); } RootPanel.get().clear(); designer.buildGUI(); }
From source file:fast.servicescreen.client.rpc.ShareResourceHandler.java
License:Open Source License
public String share(BuildingBlock res) { final String resultString = ""; //url and header String url = gvsUrl + "buildingblock/resource"; final String cookie = "fastgvsid=" + Cookies.getCookie("fastgvsid"); final HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Cookie", cookie); //build operator String body = "buildingblock=" + buildResource(res); // Window.alert("Resource: " + body); //upload to GVS shResService = GWT.create(RequestService.class); shResService.sendHttpRequest_POST(url, headers, body, new AsyncCallback<String>() { @Override/*from w ww .java2s . com*/ public void onFailure(Throwable caught) { } @Override public void onSuccess(String result) { if (result != null && result != "-1") { JSONValue resourceVal = JSONParser.parse(result); JSONObject resourceObj = resourceVal.isObject(); JSONValue idVal = resourceObj.get("id"); JSONNumber idNum = idVal.isNumber(); String id = idNum.toString(); if (id != null) { String shareUrl = gvsUrl + "buildingblock/" + id + "/sharing"; shResService.sendHttpRequest_POST(shareUrl, headers, "", new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { //Resource couldn't be shared System.out.println("Resource couldn't be shared" + caught.getMessage()); } @Override public void onSuccess(String result) { //Resource was shared System.out.println("Resource was shared: " + result); } }); } } } }); return resultString; }
From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.AnalysisPerspective.java
License:Open Source License
public void fromJSONObject(JSONObject o) { if (o != null) { JSONValue val = o.get("perspectiveTitle"); JSONString js = null;/*from w w w. j a v a2 s. c o m*/ perspectiveTitle = null; if (val != null) { js = val.isString(); if (js != null) { perspectiveTitle = js.stringValue(); } } val = o.get("perspectiveQuestion"); perspectiveQuestion = null; if (val != null) { js = val.isString(); if (js != null) { perspectiveQuestion = js.stringValue(); } } val = o.get("perspectiveSummary"); perspectiveSummary = null; if (val != null) { js = val.isString(); if (js != null) { perspectiveSummary = js.stringValue(); } } val = o.get("arguments"); if (val != null) { JSONArray aa = val.isArray(); if (aa != null) { for (int i = 0; i < aa.size(); i++) { val = aa.get(i); JSONObject a = val.isObject(); if (a != null) { arguments.add(new Argument(a)); } } } } val = o.get("counterArguments"); if (val != null) { JSONArray caa = val.isArray(); if (caa != null) { for (int i = 0; i < caa.size(); i++) { val = caa.get(i); JSONObject ca = val.isObject(); if (ca != null) { counterArguments.add(new Argument(ca)); } } } } } }