List of usage examples for com.google.gwt.core.client JsonUtils escapeValue
public static native String escapeValue(String toEscape) ;
From source file:nl.mpi.tg.eg.experiment.client.service.DataSubmissionService.java
License:Open Source License
private String jsonEscape(String inputString) { return (inputString == null) ? null : JsonUtils.escapeValue(inputString); }
From source file:nl.strohalm.cyclos.mobile.client.model.Parameters.java
License:Open Source License
/** * Converts a key:value pair to JSON valid format *//*from w w w . ja va2s . com*/ private String pairToJSON(String key, String value, boolean escapeValue) { StringBuilder sb = new StringBuilder(); sb.append(JsonUtils.escapeValue(key)); sb.append(JSON_SEPARATOR); sb.append(escapeValue ? JsonUtils.escapeValue(value) : value); return sb.toString(); }
From source file:org.eclipse.che.ide.examples.CheFluxLiveEditExtension.java
License:Open Source License
@Inject public CheFluxLiveEditExtension(final MessageBusProvider messageBusProvider, final EventBus eventBus, final MachineManager machineManager, final MachineServiceClient machineServiceClient, final DtoUnmarshallerFactory dtoUnmarshallerFactory, final AppContext appContext, final CommandManager commandManager, final CommandPropertyValueProviderRegistry commandPropertyValueProviderRegistry) { this.commandManager = commandManager; this.messageBus = messageBusProvider.getMessageBus(); this.commandPropertyValueProviderRegistry = commandPropertyValueProviderRegistry; injectSocketIO();// w w w . j a v a 2s . com eventBus.addHandler(ProjectExplorerLoadedEvent.getType(), new ProjectExplorerLoadedEvent.ProjectExplorerLoadedHandler() { @Override public void onProjectsLoaded(ProjectExplorerLoadedEvent event) { String machineId = appContext.getDevMachineId(); Promise<List<MachineProcessDto>> processesPromise = machineServiceClient .getProcesses(machineId); processesPromise.then(new Operation<List<MachineProcessDto>>() { @Override public void apply(final List<MachineProcessDto> descriptors) throws OperationException { if (descriptors.isEmpty()) { return; } Log.info(getClass(), "machine processes"); for (MachineProcessDto machineProcessDto : descriptors) { Log.info(getClass(), " - " + machineProcessDto); if (connectIfFluxMicroservice(machineProcessDto)) { break; } } } }); } }); String machineId = appContext.getDevMachineId(); final Unmarshallable<MachineProcessEvent> unmarshaller = dtoUnmarshallerFactory .newWSUnmarshaller(MachineProcessEvent.class); final String processStateChannel = "machine:process:" + machineId; final MessageHandler handler = new SubscriptionHandler<MachineProcessEvent>(unmarshaller) { @Override protected void onMessageReceived(MachineProcessEvent result) { Log.info(getClass(), "process event" + result); if (MachineProcessEvent.EventType.STARTED.equals(result.getEventType())) { final int processId = result.getProcessId(); machineServiceClient.getProcesses(appContext.getDevMachineId()) .then(new Operation<List<MachineProcessDto>>() { @Override public void apply(List<MachineProcessDto> descriptors) throws OperationException { if (descriptors.isEmpty()) { return; } for (final MachineProcessDto machineProcessDto : descriptors) { if (machineProcessDto.getPid() == processId) { Log.info(getClass(), "Started Process" + machineProcessDto); new Timer() { @Override public void run() { if (connectIfFluxMicroservice(machineProcessDto)) { // break; } } }.schedule(8000); return; } } } }); } } @Override protected void onErrorReceived(Throwable exception) { Log.error(getClass(), exception); } }; wsSubscribe(processStateChannel, handler); eventBus.addHandler(DocumentReadyEvent.TYPE, new DocumentReadyHandler() { @Override public void onDocumentReady(DocumentReadyEvent event) { liveDocuments.put(event.getDocument().getFile().getPath(), event.getDocument()); final DocumentHandle documentHandle = event.getDocument().getDocumentHandle(); documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, new DocumentChangeHandler() { @Override public void onDocumentChange(DocumentChangeEvent event) { if (socket != null) { // full path start with /, so substring String fullPath = event.getDocument().getDocument().getFile().getPath().substring(1); String project = fullPath.substring(0, fullPath.indexOf('/')); String resource = fullPath.substring(fullPath.indexOf('/') + 1); String text = JsonUtils.escapeValue(event.getText()); String json = "{"// + "\"username\":\"USER\","// + "\"project\":\"" + project + "\","// + "\"resource\":\"" + resource + "\"," // + "\"offset\":" + event.getOffset() + "," // + "\"removedCharCount\":" + event.getRemoveCharCount() + "," // + "\"addedCharacters\": " + text // + "}"; if (isUpdatingModel) { return; } socket.emit("liveResourceChanged", JsonUtils.unsafeEval(json)); } } }); } }); }
From source file:org.eclipse.che.ide.flux.liveedit.FluxMessageBuilder.java
License:Open Source License
public FluxMessageBuilder withAddedCharacters(String addedCharacters) { this.addedCharacters = JsonUtils.escapeValue(addedCharacters); return this; }
From source file:org.jboss.ballroom.client.widgets.forms.Form.java
License:Open Source License
@SuppressWarnings("unchecked") private String encodeValue(Object object) { StringBuilder sb = new StringBuilder(); if (object instanceof List) // list objects {/*from ww w .ja v a 2 s .c o m*/ List listObject = (List) object; sb.append("["); int c = 0; for (Object item : listObject) { sb.append(encodeValue(item)); if (c < listObject.size() - 1) sb.append(", "); c++; } sb.append("]"); } else if (object instanceof Map) { Map<String, String> map = (Map<String, String>) object; sb.append("{"); for (Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, String> entry = iterator.next(); sb.append(encodeValue(entry.getKey())).append(":").append(encodeValue(entry.getValue())); if (iterator.hasNext()) { sb.append(","); } } sb.append("}"); } else if (AutoBeanUtils.getAutoBean(object) != null) { Splittable split = AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(object)); sb.append("{ "); sb.append(encodeValue(split)); sb.append(" }"); } else if (object instanceof Splittable) { Splittable split = (Splittable) object; if (split.isString()) return encodeValue(split.asString()); int c = 0; List<String> keys = split.getPropertyKeys(); for (String key : keys) { sb.append(encodeValue(key)); sb.append(" : "); sb.append(encodeValue(split.get(key))); if (c < keys.size() - 1) sb.append(", "); c++; } } else { boolean quoted = (object instanceof String); String escaped = JsonUtils.escapeValue(object.toString()); escaped = escaped.substring(1, escaped.length() - 1); // JsonUtils adds extra quotes if (quoted) sb.append("\""); sb.append(escaped); if (quoted) sb.append("\""); } return sb.toString(); }
From source file:org.primordion.xholon.io.json.JsonStrWriter.java
License:Open Source License
public void writeAttribute(String name, String value) { /*try {//from ww w.j a v a2 s . co m streamWriter.writeAttribute(name, value); } catch (XMLStreamException e) { e.printStackTrace(); }*/ // ex: "connector": "ancestor::PetriNet/Places/C" if ("Val".equalsIgnoreCase(name) && !isShouldWriteVal()) { return; } if ("AllPorts".equalsIgnoreCase(name) && !isShouldWriteAllPorts()) { return; } sb.append("\"").append(name).append("\":").append(JsonUtils.escapeValue(value)) // Returns a quoted, escaped JSON String. .append(","); }
From source file:org.primordion.xholon.io.json.JsonStrWriter.java
License:Open Source License
public void writeText(String text) { /*try {//ww w . jav a 2s. c o m streamWriter.writeCharacters(text); } catch (XMLStreamException e) { e.printStackTrace(); }*/ sb.append("\"").append("Text").append("\":").append(JsonUtils.escapeValue(text)) // Returns a quoted, escaped JSON String. .append(","); }
From source file:org.primordion.xholon.service.nosql.Neo4jRestApi.java
License:Open Source License
/** * Post a Cypher CREATE statement to the Neo4j database. * @param cypherStatement A Cypher statement that begins with "CREATE". *//*w ww. j av a 2 s . c om*/ protected void postCreate(String cypherStatement) { String url = "http://localhost:7474/db/data/transaction/commit"; String jsonReqStr = "{\"statements\":[{\"statement\":" // escapes double-quote to \\" and LF to \\n, and puts double-quote at start and end + JsonUtils.escapeValue(cypherStatement) + ",\"resultDataContents\":[\"row\",\"graph\"],\"includeStats\":true}]}"; try { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url)); builder.setHeader("Accept", "application/json"); builder.setHeader("Content-Type", "application/json;charset=utf-8"); builder.sendRequest(jsonReqStr, new RequestCallback() { @Override public void onResponseReceived(Request req, Response resp) { if (resp.getStatusCode() == resp.SC_OK) { String jsonRespStr = resp.getText(); // display the raw returned JSON String contextNode.println(jsonRespStr); } else { contextNode.println("status code:" + resp.getStatusCode()); contextNode.println("status text:" + resp.getStatusText()); contextNode.println("text:\n" + resp.getText()); } } @Override public void onError(Request req, Throwable e) { contextNode.println("onError:" + e.getMessage()); } }); } catch (RequestException e) { contextNode.println("RequestException:" + e.getMessage()); } }
From source file:org.primordion.xholon.service.nosql.Neo4jRestApi.java
License:Open Source License
/** * Post a Cypher MATCH statement to the Neo4j database. * @param cypherStatement A Cypher statement that begins with "MATCH". *//*from w w w . j a v a 2 s . com*/ protected void postMatch(String cypherStatement) { String url = "http://localhost:7474/db/data/cypher"; String jsonReqStr = "{\"query\" : " // escapes double-quote to \\" and LF to \\n, and puts double-quote at start and end + JsonUtils.escapeValue(cypherStatement) + "}"; try { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url)); builder.setHeader("Accept", "application/json;charset=utf-8"); builder.setHeader("Content-Type", "application/json"); builder.sendRequest(jsonReqStr, new RequestCallback() { @Override public void onResponseReceived(Request req, Response resp) { if (resp.getStatusCode() == resp.SC_OK) { String jsonRespStr = resp.getText(); // display the raw returned JSON String contextNode.println(jsonRespStr); } else { contextNode.println("status code:" + resp.getStatusCode()); contextNode.println("status text:" + resp.getStatusText()); contextNode.println("text:\n" + resp.getText()); } } @Override public void onError(Request req, Throwable e) { contextNode.println("onError:" + e.getMessage()); } }); } catch (RequestException e) { contextNode.println("RequestException:" + e.getMessage()); } }
From source file:org.rapla.rest.client.gwt.internal.impl.ser.JavaLangString_JsonSerializer.java
License:Apache License
@Override public void printJson(final StringBuilder sb, final String o) { sb.append(JsonUtils.escapeValue(o)); }