List of usage examples for com.google.gwt.http.client URL encode
public static String encode(String decodedURL)
From source file:org.primordion.ef.program.Xholon2CoffeeScript.java
License:Open Source License
/** * Open the HTML-wrapped CoffeeScript in a new browser window. * @param htmlStr The HTML-wrapped CoffeeScript. * This string includes indentation (pairs of space characters " "), * which must be retained in order for the CoffeeScript parser to work. *//*from w ww . java 2s . c o m*/ protected void openInNewBrowserWindow(String htmlStr) { String url = "data:text/html;charset=UTF-8," + URL.encode(htmlStr).replaceAll(" ", "%20%20").replaceAll("#", "%23"); root.consoleLog(url); Window.open(url, "_blank", ""); // this is internally-generated HTML }
From source file:org.primordion.xholon.app.Application.java
License:Open Source License
public void information() { if (informationFile == null) { println("No information can be diplayed." + " Please provide a valid file name using the InformationFile parameter in the _xhn.xml config file."); return;/*from w w w . j ava 2 s . c om*/ } String url = ""; if (informationFile.startsWith("./")) { /* GWT java.io.File infoFile = new java.io.File(informationFile.substring(2)); String infoFileName = "file://" + infoFile.getAbsolutePath(); for (int i = 0; i < infoFileName.length(); i++) { if (infoFileName.charAt(i) == '\\') { url += '/'; } else { url += infoFileName.charAt(i); } }*/ return; } else if (informationFile.startsWith("http")) { url = informationFile; } else if (informationFile.indexOf("javascript:") != -1) { // this may be a malicious script return; } else { // look for SVG content in the app's optional GWT ClientBundle String infoStr = rcConfig("info", findGwtClientBundle()); // display this infoStr if ((infoStr != null) && (infoStr.length() != 0)) { infoStr = infoStr.trim(); if (infoStr.startsWith("<!doctype html>") || infoStr.startsWith("<html>")) { url = "data:text/html," + URL.encode(infoStr); } else { url = "data:text/xml," + URL.encode(infoStr); } } else { url = GwtEnvironment.gwtHostPageBaseURL + informationFile; } } Window.open(url, "_blank", ""); // checked if it's "javascript:" //org.primordion.xholon.io.BrowserLauncher.launch(url); // GWT }
From source file:org.primordion.xholon.service.nosql.Neo4jRestApi.java
License:Open Source License
/** * Get Neo4j service root, as a test./*from ww w. j a v a 2 s . c o m*/ * GET http://localhost:7474/db/data/ */ protected void getServiceRoot() { String url = "http://localhost:7474/db/data/"; try { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); builder.setHeader("Accept", "application/json"); // " ;charset=UTF-8" builder.sendRequest("", new RequestCallback() { @Override public void onResponseReceived(Request req, Response resp) { if (resp.getStatusCode() == resp.SC_OK) { String jsonStr = resp.getText(); // display the raw returned JSON String contextNode.println(jsonStr); // parse the returned JSON String, and get and display a single value JSONValue jsonValue = ((JSONObject) JSONParser.parseStrict(jsonStr)).get("neo4j_version"); contextNode.println("neo4j_version = " + jsonValue); } 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 CREATE statement to the Neo4j database. * @param cypherStatement A Cypher statement that begins with "CREATE". *///from ww w. j a v a 2 s . c o m 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". */// w w w . j ava2 s . co m 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.restlet.gwt.data.Reference.java
License:LGPL
/** * Encodes a given string using the standard URI encoding mechanism and the * UTF-8 character set./*from w w w . j a va2 s.c o m*/ * * @param toEncode * The string to encode. * @return The encoded string. */ public static String encode(String toEncode) { String result = null; if (toEncode != null) { try { result = URL.encode(toEncode); } catch (NullPointerException npe) { System.err.println("Unable to encode the string with the UTF-8 character set."); } } return result; }
From source file:org.restlet.gwt.data.Reference.java
License:LGPL
/** * Encodes a given string using the standard URI encoding mechanism. If the * provided character set is null, the string is returned but not encoded. * // w w w. j a v a2 s. c om * <em><strong>Note:</strong> The <a * href="http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars"> * World Wide Web Consortium Recommendation</a> states that UTF-8 should be * used. Not doing so may introduce incompatibilites.</em> * * @param toEncode * The string to encode. * @param characterSet * The supported character encoding. * @return The encoded string or null if the named character encoding is not * supported. */ public static String encode(String toEncode, CharacterSet characterSet) { if (!CharacterSet.UTF_8.equals(characterSet)) { throw new IllegalArgumentException("Only UTF-8 URL encoding is supported under GWT"); } String result = null; try { result = (characterSet == null) ? toEncode : URL.encode(toEncode); } catch (NullPointerException npe) { System.err.println("Unable to encode the string with the UTF-8 character set."); } return result; }
From source file:org.rhq.coregui.client.components.ReportExporter.java
License:Open Source License
private String buildUrl() { buildQueryParameters();//from w w w .j a v a2s.c o m // trim the last "&" off the url if exists final String cleanQueryString = queryString.toString().endsWith("&") ? queryString.substring(0, queryString.toString().length() - 1) : queryString.toString(); final String queryStringNotEndingWithQuestionMark = cleanQueryString.endsWith("?") ? cleanQueryString.substring(0, cleanQueryString.length() - 1) : cleanQueryString; return URL.encode(BASE_URL + reportUrl + "." + FORMAT + "?" + queryStringNotEndingWithQuestionMark); }
From source file:org.roda.wui.common.client.tools.RestUtils.java
public static <T extends IsIndexed> void requestCSVExport(Class<T> classToReturn, Filter filter, Sorter sorter, Sublist sublist, Facets facets, boolean onlyActive, boolean exportFacets, String filename) { // api/v1/index/findFORM?type=csv String url = RodaConstants.API_REST_V1_INDEX + "findFORM"; FindRequest request = new FindRequest(classToReturn.getName(), filter, sorter, sublist, facets, onlyActive, exportFacets, filename);/*w w w . ja va 2 s. com*/ final FormPanel form = new FormPanel(); form.setAction(URL.encode(url)); form.setMethod(FormPanel.METHOD_POST); form.setEncoding(FormPanel.ENCODING_URLENCODED); FlowPanel layout = new FlowPanel(); form.setWidget(layout); layout.add(new Hidden("findRequest", FIND_REQUEST_MAPPER.write(request))); layout.add(new Hidden("type", "csv")); form.setVisible(false); RootPanel.get().add(form); // using submit instead of submit completed because Chrome doesn't created // the other event form.addSubmitHandler(new SubmitHandler() { @Override public void onSubmit(SubmitEvent event) { Timer timer = new Timer() { @Override public void run() { RootPanel.get().remove(form); } }; // remove form 10 seconds in the future timer.schedule(10000); } }); form.submit(); }
From source file:org.sonar.api.web.gwt.client.webservices.JsonUtils.java
License:Open Source License
public static void requestJson(String url, JSONHandler handler) { if (!url.endsWith("&") && !url.endsWith("?")) { url += "&"; }/*w w w.ja v a2 s.co m*/ if (!url.contains("format=json")) { url += "format=json&"; } if (!url.contains("callback=")) { //IMPORTANT : the url should ended with ?callback= or &callback= for JSONP calls url += "callback="; } makeJSONRequest(requestId++, URL.encode(url), handler); }