com.google.gwt.http.client.URL Java Examples
The following examples show how to use
com.google.gwt.http.client.URL.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UrlParameters.java From swellrt with Apache License 2.0 | 6 votes |
/** * Build a query string out of a map of key/value pairs. * @param queryEntries */ public static String buildQueryString(Map<String, String> queryEntries) { StringBuffer sb = new StringBuffer(); boolean firstIteration = true; for (Entry<String, String> e : queryEntries.entrySet()) { if (firstIteration) { sb.append('?'); } else { sb.append('&'); } String encodedName = URL.encodeComponent(e.getKey()); sb.append(encodedName); sb.append('='); String encodedValue = URL.encodeComponent(e.getValue()); sb.append(encodedValue); firstIteration = false; } return sb.toString(); }
Example #2
Source File: Preview.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * showEmbedPDF * * @param uuid Unique document ID to be previewed. */ public void showEmbedPDF(String uuid) { hideWidgetExtension(); vPanel.clear(); if (previewEvent != null) { vPanel.add(hReturnPanel); vPanel.setCellHeight(hReturnPanel, String.valueOf(TURN_BACK_HEIGHT) + "px"); } vPanel.add(pdf); vPanel.setCellHorizontalAlignment(pdf, HasAlignment.ALIGN_CENTER); vPanel.setCellVerticalAlignment(pdf, HasAlignment.ALIGN_MIDDLE); if (previewAvailable) { String url = RPCService.DownloadServlet + "?inline=true&uuid=" + URL.encodeQueryString(uuid); pdf.setHTML("<div id=\"pdfembededcontainer\">" + "<object id=\"" + pdfID + "\" name=\"" + pdfID + "\" width=\"" + width + "\" height=\"" + height + "\" type=\"application/pdf\" data=\"" + url + "\"&#zoom=85&scrollbar=1&toolbar=1&navpanes=1&view=FitH\">" + "<p>Browser plugin suppport error, PDF can not be displayed</p>" + "</object>" + "</div>\n"); // needed for rewriting purpose } else { swf.setHTML("<div id=\"pdfembededcontainer\" align=\"center\"><br><br>" + Main.i18n("preview.unavailable") + "</div>\n"); } }
Example #3
Source File: RequestInfo.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
protected void setQueryString(String queryString) { this.queryString = queryString; paramMap = new HashMap<String, String>(); if (queryString != null && queryString.length() > 1) { String qs = queryString.substring(1); String[] kvPairs = qs.split("&"); for (int i = 0; i < kvPairs.length; i++) { String[] kv = kvPairs[i].split("="); if (kv.length > 1) { paramMap.put(kv[0], URL.decodeComponent(kv[1])); } else { paramMap.put(kv[0], ""); } } } }
Example #4
Source File: Util.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
public static String webstartURL(String appName, Map<String, String> params) { StringBuffer url = new StringBuffer(GWT.getHostPageBaseURL()); url.append("webstart/"); url.append(appName); url.append(".jsp?random="); url.append(new Date().getTime()); url.append("&language="); url.append(I18N.getLocale()); url.append("&docLanguage="); url.append(I18N.getDefaultLocaleForDoc()); url.append("&sid="); url.append(Session.get().getSid()); if (params != null) for (String p : params.keySet()) { url.append("&"); url.append(p); url.append("="); url.append(URL.encode(params.get(p))); } return url.toString(); }
Example #5
Source File: UserAuthentication.java From unitime with Apache License 2.0 | 6 votes |
public void authenticate() { if (!CONSTANTS.allowUserLogin()) { if (isAllowLookup()) doLookup(); else ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target=" + URL.encodeQueryString(Window.Location.getHref())); return; } AriaStatus.getInstance().setText(ARIA.authenticationDialogOpened()); iError.setVisible(false); iDialog.center(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { iUserName.selectAll(); iUserName.setFocus(true); } }); }
Example #6
Source File: FindDocumentSelectPopup.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * addDocument */ private void addDocumentToWikiEditor() { if (selectedRow >= 0) { String uuid = documentTable.getText(selectedRow, 2); String name = UtilComunicator.getName(documentTable.getText(selectedRow, 1)); switch (type) { case FIND_DOCUMENT: Wiki.get().addDocumentTag(uuid, name); break; case FIND_IMAGE: String url = RPCService.DownloadServlet; url += "?uuid=" + URL.encodeQueryString(uuid); Wiki.get().addImageTag(url, getParameters()); break; } } }
Example #7
Source File: Scrub.java From swellrt with Apache License 2.0 | 6 votes |
/** * Scrub a url if scrubbing is turned on * * Does not scrub urls with leading hashes * * @param url * @return The scrubbed version of the url, if it's not already scrubbed */ public static String scrub(String url) { if (enableScrubbing) { if (url.startsWith("#") || url.startsWith(REFERRER_SCRUBBING_URL)) { // NOTE(user): The caller should be responsible for url encoding if // neccessary. There is no XSS risk here as it is a fragment. return url; } else { String x = REFERRER_SCRUBBING_URL + URL.encodeComponent(url); return x; } } else { // If we are not scrubbing the url, then we still need to sanitize it, // to protect against e.g. javascript. String sanitizedUri = EscapeUtils.sanitizeUri(url); return sanitizedUri; } }
Example #8
Source File: Scrub.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
/** * Scrub a url if scrubbing is turned on * * Does not scrub urls with leading hashes * * @param url * @return The scrubbed version of the url, if it's not already scrubbed */ public static String scrub(String url) { if (enableScrubbing) { if (url.startsWith("#") || url.startsWith(REFERRER_SCRUBBING_URL)) { // NOTE(user): The caller should be responsible for url encoding if // neccessary. There is no XSS risk here as it is a fragment. return url; } else { String x = REFERRER_SCRUBBING_URL + URL.encodeComponent(url); return x; } } else { // If we are not scrubbing the url, then we still need to sanitize it, // to protect against e.g. javascript. String sanitizedUri = EscapeUtils.sanitizeUri(url); return sanitizedUri; } }
Example #9
Source File: Location.java From document-management-system with GNU General Public License v2.0 | 6 votes |
protected void setQueryString(String queryString) { this.queryString = queryString; paramMap = new HashMap<String, String>(); if (queryString != null && queryString.length() > 1) { String qs = queryString.substring(1); String[] kvPairs = qs.split("&"); for (int i = 0; i < kvPairs.length; i++) { String[] kv = kvPairs[i].split("="); if (kv.length > 1) { paramMap.put(kv[0], URL.decodeQueryString(kv[1])); } else { paramMap.put(kv[0], ""); } } } }
Example #10
Source File: OpenProjectDialog.java From geowe-core with GNU General Public License v3.0 | 6 votes |
private SelectHandler createUrlToShare(final VerticalPanel geoDataContainer) { return new SelectHandler() { @Override public void onSelect(SelectEvent event) { urlToShareAnchor.setHref(getHref()); urlToShareAnchor.setText( UIMessages.INSTANCE.seeOtherWindow("GeoWE Project"), Direction.LTR); urlShared.setText(getHref()); urlPanel.setVisible(true); urlShared.setVisible(true); } private String getHref() { String baseUrl = GWT.getHostPageBaseURL(); baseUrl += "?projectUrl=" + URL.encodeQueryString(urlTextField.getValue()); return baseUrl; } }; }
Example #11
Source File: NewTokenFormatter.java From core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public List<PlaceRequest> toPlaceRequestHierarchy(String historyToken) throws TokenFormatException { historyToken = URL.decodeQueryString(historyToken); int split = historyToken.indexOf(hierarchySeparator); if (split == 0) { throw new TokenFormatException("Place history token is missing."); } else { List<PlaceRequest> result = new ArrayList<PlaceRequest>(); if (split == -1) { result.add(unescapedToPlaceRequest(historyToken)); // History token consists of a single place token } else { String[] placeTokens = historyToken.split(hierarchySeparator); for (String placeToken : placeTokens) { if (placeToken.isEmpty()) { throw new TokenFormatException("Bad parameter: Successive place tokens require a single '" + hierarchySeparator + "' between them."); } result.add(unescapedToPlaceRequest(placeToken)); } } return result; } }
Example #12
Source File: Util.java From document-management-system with GNU General Public License v2.0 | 6 votes |
/** * Download files exported as zip * * @author danilo */ @Deprecated public static void downloadFiles(List<String> path, String params) { if (!params.equals("")) { params = "&" + params; } final Element downloadIframe = RootPanel.get("__download").getElement(); String url = RPCService.DownloadServlet + "?export" + params; for (String p : path) { url += "&pathList=" + URL.encodeQueryString(p); } DOM.setElementAttribute(downloadIframe, "src", url); }
Example #13
Source File: WfsVectorLayerDef.java From geowe-core with GNU General Public License v3.0 | 6 votes |
private String createWfsUrl() { StringBuffer url = new StringBuffer(serviceUrl); url.append("?request=GetFeature"); url.append("&service=WFS"); url.append("&version=" + version); url.append("&typeName=" + nameSpaceFeatureType); if (maxFeatures != 0) { url.append(getMaxFeaturesLimit()); } if (!getFormat().isEmpty()) { url.append(getOutputFormat()); } if (queryBbox) { url.append("&srsName=" + getEpsg()); url.append("&bbox=" + bbox.getLowerLeftX() + "," + bbox.getLowerLeftY() + "," + bbox.getUpperRightX() + "," + bbox.getUpperRightY()); } else { url.append("&CQL_FILTER=" + URL.encodeQueryString(cql)); } return url.toString(); }
Example #14
Source File: GadgetWidget.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
/** * Utility function to convert an attribute string to a Gadget StateMap. * * @param attribute attribute value string. * @return StateMap constructed from the attribute value. */ private StateMap attributeToState(String attribute) { StateMap result = StateMap.create(); if ((attribute != null) && !attribute.equals("")) { log("Unescaped attribute: ", URL.decodeComponent(attribute)); result.fromJson(URL.decodeComponent(attribute)); log("State map: ", result.toJson()); } return result; }
Example #15
Source File: UrlParameters.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
UrlParameters(String query) { if (query.length() > 1) { String[] keyvalpairs = query.substring(1, query.length()).split("&"); for (String pair : keyvalpairs) { String[] keyval = pair.split("="); // Some basic error handling for invalid query params. if (keyval.length == 2) { map.put(URL.decodeComponent(keyval[0]), URL.decodeComponent(keyval[1])); } else if (keyval.length == 1) { map.put(URL.decodeComponent(keyval[0]), ""); } } } }
Example #16
Source File: GadgetWidget.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
/** * Processes changes in the gadget element attributes. * TODO(user): move some of this code to the handler. * * @param name attribute name. * @param value new attribute value. */ public void onAttributeModified(String name, String value) { log("Attribute '", name, "' changed to '", value, "'"); if (userPrefs == null) { log("Attribute changed before the gadget is initialized."); return; } if (name.equals(URL_ATTRIBUTE)) { source = (value == null) ? "" : value; } else if (name.equals(TITLE_ATTRIBUTE)) { String title = (value == null) ? "" : URL.decodeComponent(value); if (!title.equals(ui.getTitleLabelText())) { log("Updating title: ", title); ui.setTitleLabelText(title); } } else if (name.equals(PREFS_ATTRIBUTE)) { updatePrefsFromAttribute(value); } else if (name.equals(STATE_ATTRIBUTE)) { StateMap newState = attributeToState(value); if (!state.compare(newState)) { String podiumState = newState.get(PODIUM_STATE_NAME); if ((podiumState != null) && (!podiumState.equals(state.get(PODIUM_STATE_NAME)))) { sendPodiumOnStateChangedRpc(getGadgetName(), podiumState); } state.clear(); state.copyFrom(newState); log("Updating gadget state: ", state.toJson()); gadgetStateSubmitter.submit(); } } }
Example #17
Source File: ClientPercentEncoderDecoder.java From swellrt with Apache License 2.0 | 5 votes |
@Override public String decode(String encodedValue) throws URIEncoderDecoder.EncodingException { String ret = URL.decodePathSegment(encodedValue); if (ret.indexOf(0xFFFD) != -1) { throw new URIEncoderDecoder.EncodingException("Unable to decode value " + encodedValue + " it contains invalid UTF-8"); } return ret; }
Example #18
Source File: JsoSearchBuilderImpl.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
private static String getUrl(SearchRequest searchRequest) { String query = URL.encodeQueryString(searchRequest.getQuery()); String params = "?query=" + query + "&index=" + searchRequest.getIndex() + "&numResults=" + searchRequest.getNumResults(); return SEARCH_URL_BASE + "/" + params; }
Example #19
Source File: MultivaluedParamComposition.java From requestor with Apache License 2.0 | 5 votes |
/** * Construct encoded URI part from gives values. * * @param separator the separator of parameters from current URI part * @param name the parameter name * @param values the parameter value(s), each object will be converted to a {@code String} using its {@code * toString()} method. * * @return encoded URI part */ @Override public String asUriPart(String separator, String name, String... values) { assertNotNullOrEmpty(name, "Parameter name cannot be null or empty."); String uriPart = URL.encodeQueryString(name) + "="; String sep = ""; for (String value : values) { assertNotNullOrEmpty(value, "Parameter value of *" + name + "* null or empty. You must inform a valid value"); uriPart += sep + URL.encodeQueryString(value); sep = ","; } return uriPart; }
Example #20
Source File: MultivaluedParamComposition.java From requestor with Apache License 2.0 | 5 votes |
/** * Construct encoded URI part from gives values. * * @param separator the separator of parameters from current URI part * @param name the parameter name * @param values the parameter value(s), each object will be converted to a {@code String} using its {@code * toString()} method. * * @return encoded URI part */ @Override public String asUriPart(String separator, String name, String... values) { assertNotNullOrEmpty(name, "Parameter name cannot be null or empty."); String uriPart = ""; String sep = ""; for (String value : values) { assertNotNullOrEmpty(value, "Parameter value of *" + name + "* null or empty. You must inform a valid value"); uriPart += sep + URL.encodeQueryString(name) + "=" + URL.encodeQueryString(value); sep = separator; } return uriPart; }
Example #21
Source File: GadgetNonEditorGwtTest.java From swellrt with Apache License 2.0 | 5 votes |
/** * Tests the IFrame URI generator of Gadget class. */ public void testIframeUri() { String xmlSource = "http://test.com/gadget.xml"; String href = "http://" + Location.getHost(); String hrefEscaped = href.replace("?", "%3F"); if (hrefEscaped.endsWith("/")) { hrefEscaped = hrefEscaped.substring(0, hrefEscaped.length() - 1); } int clientInstanceId = 1234; GadgetUserPrefs userPrefs = GadgetUserPrefs.create(); userPrefs.put("pref1", "value1"); userPrefs.put("pref2", "value2"); GadgetMetadata metadata = getTestMetadata(xmlSource); WaveId waveId = WaveId.of("wave.google.com", "123"); WaveletId waveletId = WaveletId.of("wave.google.com", "conv+root"); WaveletName name = WaveletName.of(waveId, waveletId); String securityToken = "SECURITY"; GadgetWidget gadget = GadgetWidget.createForTesting( clientInstanceId, userPrefs, name, securityToken, new FakeLocale()); int gadgetInstanceId = -12345; String url = gadget.buildIframeUrl(gadgetInstanceId, metadata.getIframeUrl(VIEW_NAME)); String expectedValue = "//0" + GADGET_SERVER + "/gadgets" + "/ifr?url=http://test.com/gadget.xml&view=canvas&nocache=1&mid=" + gadgetInstanceId + "&lang=wizard&country=OZ&parent=" + hrefEscaped + "&wave=1&waveId=" + URL.encodeQueryString(ModernIdSerialiser.INSTANCE.serialiseWaveId(waveId)) + "#rpctoken=" + gadget.getRpcToken() + "&st=" + securityToken + "&up_pref1=value1&up_pref2=value2"; assertEquals(expectedValue, url); }
Example #22
Source File: EventResourceTimetable.java From unitime with Apache License 2.0 | 5 votes |
public HistoryToken(PageType type) { iType = type.name(); // 1. take page type defaults --> DEFAULTS if (type.getParams() != null) for (int i = 0; 1 + i < type.getParams().length; i += 2) iDefaults.put(type.getParams()[i], type.getParams()[i + 1]); // 2. take page parameters --> DEFAULTS (on top of the page type defaults) for (Map.Entry<String, List<String>> params: Window.Location.getParameterMap().entrySet()) iDefaults.put(params.getKey(), params.getValue().get(0)); // 3. take cookie --> PARAMS (override defaults) String cookie = EventCookie.getInstance().getHash(iType); if (cookie != null) { for (String pair: cookie.split("\\&")) { int idx = pair.indexOf('='); if (idx >= 0) { String key = pair.substring(0, idx); if (Location.getParameter(key) == null) iParams.put(key, URL.decodeQueryString(pair.substring(idx + 1))); } } } // 4. take page token (hash) --> PARAMS (override cookie) parse(History.getToken()); }
Example #23
Source File: GadgetWidget.java From swellrt with Apache License 2.0 | 5 votes |
/** * Appends tokens to the iframe URI fragment. * * @param fragment Original parameter fragment of the gadget URI. * @return Updated parameter fragment with new RPC and security tokens. */ private String updateGadgetUriFragment(String fragment) { fragment = "rpctoken=" + rpcToken + (fragment.isEmpty() || (fragment.charAt(0) == '&') ? "" : "&") + fragment; if ((securityToken != null) && !securityToken.isEmpty()) { fragment += "&st=" + URL.encodeComponent(securityToken); } return fragment; }
Example #24
Source File: GadgetWidget.java From swellrt with Apache License 2.0 | 5 votes |
/** * Utility function to convert an attribute string to a Gadget StateMap. * * @param attribute attribute value string. * @return StateMap constructed from the attribute value. */ private StateMap attributeToState(String attribute) { StateMap result = StateMap.create(); if ((attribute != null) && !attribute.equals("")) { log("Unescaped attribute: ", URL.decodeComponent(attribute)); result.fromJson(URL.decodeComponent(attribute)); log("State map: ", result.toJson()); } return result; }
Example #25
Source File: JsoSearchBuilderImpl.java From swellrt with Apache License 2.0 | 5 votes |
private static String getUrl(SearchRequest searchRequest) { String query = URL.encodeQueryString(searchRequest.getQuery()); String params = "?query=" + query + "&index=" + searchRequest.getIndex() + "&numResults=" + searchRequest.getNumResults(); return SEARCH_URL_BASE + "/" + params; }
Example #26
Source File: SectioningStatusPage.java From unitime with Apache License 2.0 | 5 votes |
private void exportData() { int tab = iTabIndex; if (tab < 0) tab = SectioningStatusCookie.getInstance().getTab(iOnline); String query = "output=student-dashboard.csv&online=" + (iOnline ? 1 : 0) + "&tab=" + tab + "&sort=" + SectioningStatusCookie.getInstance().getSortBy(iOnline, tab); if (tab == 0) for (Long courseId: iSelectedCourseIds) query += "&c=" + courseId; if (tab == 1) query += "&g=" + SectioningStatusCookie.getInstance().getSortByGroup(iOnline); query += "&query=" + URL.encodeQueryString(iFilter.getValue()); FilterRpcRequest req = iFilter.getElementsRequest(); if (req.hasOptions()) { for (Map.Entry<String, Set<String>> option: req.getOptions().entrySet()) { for (String value: option.getValue()) { query += "&f:" + option.getKey() + "=" + URL.encodeQueryString(value); } } } if (req.getText() != null && !req.getText().isEmpty()) { query += "&f:text=" + URL.encodeQueryString(req.getText()); } RPC.execute(EncodeQueryRpcRequest.encode(query), new AsyncCallback<EncodeQueryRpcResponse>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(EncodeQueryRpcResponse result) { ToolBox.open(GWT.getHostPageBaseURL() + "export?q=" + result.getQuery()); } }); }
Example #27
Source File: SectioningStatusPage.java From unitime with Apache License 2.0 | 5 votes |
private void checkLastQuery() { if (Window.Location.getParameter("q") != null) { iFilter.setValue(Window.Location.getParameter("q"), true); if (Window.Location.getParameter("t") != null) { if ("2".equals(Window.Location.getParameter("t"))) { iTabBar.selectTab(1); } else { iTabBar.selectTab(0); } } else { loadData(); } } else if (Window.Location.getHash() != null && !Window.Location.getHash().isEmpty()) { String hash = URL.decode(Window.Location.getHash().substring(1)); if (!hash.matches("^[0-9]+\\:?[0-9]*@?$")) { if (hash.endsWith("@")) { iFilter.setValue(hash.substring(0, hash.length() - 1), true); iTabBar.selectTab(1); } else if (hash.endsWith("$")) { iFilter.setValue(hash.substring(0, hash.length() - 1), true); iTabBar.selectTab(2); } else { iFilter.setValue(hash, true); loadData(); } } } else { String q = SectioningStatusCookie.getInstance().getQuery(iOnline); if (q != null) iFilter.setValue(q, true); int t = SectioningStatusCookie.getInstance().getTab(iOnline); if (t >= 0 && t < iTabBar.getTabCount()) { iTabBar.selectTab(t, false); iTabIndex = -1; } if (GWT_CONSTANTS.searchWhenPageIsLoaded() && q != null && !q.isEmpty()) loadData(); } }
Example #28
Source File: EventResourceTimetable.java From unitime with Apache License 2.0 | 5 votes |
public String toString(String skip) { String ret = ""; for (String key: new TreeSet<String>(iParams.keySet())) { if (key.equals(skip)) continue; if (!ret.isEmpty()) ret += "&"; ret += key + "=" + URL.encodeQueryString(iParams.get(key)); } return ret; }
Example #29
Source File: EventResourceTimetable.java From unitime with Apache License 2.0 | 5 votes |
public void parse(String token) { if (token != null && !token.isEmpty()) for (String pair: token.split("\\&")) { int idx = pair.indexOf('='); if (idx >= 0) iParams.put(pair.substring(0, idx), URL.decodeQueryString(pair.substring(idx + 1))); } }
Example #30
Source File: GUIExternalCall.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public String getUrl(boolean document, Long[] ids, String[] titles) { String url = getBaseUrl(); url += "?type=" + (document ? "document" : "folder"); url += "&id="; for (Long id : ids) { if (!url.endsWith("=")) url += ","; url += id.toString(); } for (String param : getParameters()) { if ("user".equals(param.trim())) url += "&user=" + Session.get().getUser().getUsername(); else if ("filename".equals(param.trim())) { url += "&filename="; for (String title : titles) { if (!url.endsWith("=")) url += ","; url += title; } } } if (getSuffix() != null && !"".equals(getSuffix())) url += "&" + getSuffix(); return URL.encode(url); }