List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:de.jcup.egradle.core.util.LinkToTypeConverter.java
private LinkData internalConvertLink(String link) { if (link == null) { return null; }//from w ww.jav a 2 s. c o m if (!isLinkSchemaConvertable(link)) { return null; } try { link = URLDecoder.decode(link, UTF_8.name()); } catch (UnsupportedEncodingException e) { return null; } String typeName = StringUtils.substring(link, DSLConstants.HYPERLINK_TYPE_PREFIX.length()); if (StringUtils.isBlank(typeName)) { return null; } LinkData data = new LinkData(); int index = typeName.indexOf("#"); if (index == -1) { /* no property or method - just plain type, so guard close */ data.mainName = typeName; return data; } return handleMethodOrProperty(typeName, data); }
From source file:com.frostwire.search.torlock.TorLockSearchResult.java
private String parseFileName(String urlEncodedFileName, String fallbackName) { String decodedFileName = fallbackName; try {/*from w ww. ja v a 2s. c om*/ if (!StringUtils.isNullOrEmpty(urlEncodedFileName)) { decodedFileName = URLDecoder.decode(urlEncodedFileName, "UTF-8"); decodedFileName.replace("&", "and"); } } catch (UnsupportedEncodingException e) { } return decodedFileName + ".torrent"; }
From source file:jp.mixi.android.sdk.util.UrlUtils.java
/** * ?Bundle???//from w w w . j ava2s. c om * * @param data ? * @return Bundle */ private static Bundle decodeUrl(String data) { Bundle bundle = new Bundle(); if (data != null) { String[] array = data.split(PARAM_SEPARATOR); for (String parameter : array) { String[] vals = parameter.split(EQUAL); if (vals.length == 2) { try { bundle.putString(URLDecoder.decode(vals[0], HTTP.UTF_8), URLDecoder.decode(vals[1], HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } } } return bundle; }
From source file:com.k42b3.aletheia.protocol.http.Request.java
/** * Returns all GET params from the url as hashmap * //w w w . java 2 s.c o m * @return HashMap<String, String> */ public HashMap<String, String> getParams() { HashMap<String, String> params = new HashMap<String, String>(); String query = url.getQuery(); if (query != null) { String[] parts = query.split("&"); for (int i = 0; i < parts.length; i++) { try { String[] kv = parts[i].split("=", 2); if (kv.length == 1) { params.put(kv[0], ""); } else if (kv.length == 2) { params.put(kv[0], URLDecoder.decode(kv[1], "UTF-8")); } } catch (UnsupportedEncodingException e) { } } } return params; }
From source file:com.consol.citrus.admin.service.FileBrowserService.java
/** * Decodes file path url./* w ww . j a v a 2s .c o m*/ * @param url * @param rootDirectory * @return */ public String decodeDirectoryUrl(String url, String rootDirectory) { String directory; try { directory = URLDecoder.decode(url, Citrus.CITRUS_FILE_ENCODING); } catch (UnsupportedEncodingException e) { throw new ApplicationRuntimeException("Unable to decode directory URL", e); } if (directory.equals("/")) { if (StringUtils.hasText(rootDirectory)) { directory = rootDirectory; } else { return ""; } } if (!StringUtils.hasText(directory)) { return ""; } else if (directory.charAt(directory.length() - 1) == '\\') { directory = directory.substring(0, directory.length() - 1) + "/"; } else if (directory.charAt(directory.length() - 1) != '/') { directory += "/"; } return directory; }
From source file:ar.com.zauber.commons.web.uri.factory.RelativePathUriFactory.java
/** * Genera el path hasta la ruta de la aplicacin. * @param request/* ww w . ja va 2 s.co m*/ * @return path */ private String generarPath(final HttpServletRequest request, final String destination) { try { String encoding = request.getCharacterEncoding(); if (StringUtils.isBlank(encoding)) { encoding = defaultEncoding; } // si estamos en un jsp... String uri = (String) request.getAttribute("javax.servlet.forward.request_uri"); if (uri == null) { uri = request.getRequestURI(); } uri = URLDecoder.decode(uri, encoding); // Saco el contexto uri = uri.substring(URLDecoder.decode(request.getContextPath(), encoding).length()); final String[] ret = comunDenominador(uri, destination); uri = ret[0]; // cuento los subs int slashes = StringUtils.countMatches(uri, "/"); // si empezaba en barra resto 1 if (uri.startsWith("/")) { slashes--; } final StringBuilder sb = new StringBuilder(); boolean empty = true; for (int i = 0; i < slashes; i++) { empty = false; sb.append(".."); if (i + 1 < slashes) { sb.append('/'); } } if (empty) { sb.append('.'); } sb.append(ret[1]); return sb.toString(); } catch (UnsupportedEncodingException e) { throw new UnhandledException(e); } }
From source file:com.iterzp.momo.utils.WebUtils.java
/** * ?cookie// www .j a v a 2 s . c o m * * @param request * HttpServletRequest * @param name * cookie?? * @return ?null */ public static String getCookie(HttpServletRequest request, String name) { Assert.notNull(request); Assert.hasText(name); Cookie[] cookies = request.getCookies(); if (cookies != null) { try { name = URLEncoder.encode(name, "UTF-8"); for (Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return URLDecoder.decode(cookie.getValue(), "UTF-8"); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; }
From source file:com.nridge.core.base.std.WebUtl.java
public static String urlDecodeValue(String aValue) { String decodedValue;/*from w ww .j a v a2 s . c o m*/ try { decodedValue = URLDecoder.decode(aValue, StrUtl.CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { decodedValue = aValue; } return decodedValue; }
From source file:org.ocpsoft.redoculous.tests.asciidoc.AsciidocIncludeTest.java
License:asdf
@Test public void testServeAsciidocWithInclude() throws Exception { WebTest test = new WebTest(baseUrl); String repositoryURL = "file://" + repository.getAbsolutePath(); HttpAction<HttpPost> action = test.post("/api/v1/manage?repo=" + repositoryURL); Assert.assertEquals(201, action.getResponse().getStatusLine().getStatusCode()); String location = URLDecoder.decode(action.getResponseHeaderValue("location"), "UTF8"); Assert.assertEquals(test.getBaseURL() + test.getContextPath() + "/api/v1/serve?repo=" + repositoryURL, location);/*from ww w . j a v a 2 s .c o m*/ HttpAction<HttpGet> document = test.get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=master"); Assert.assertTrue(document.getResponseContent().contains("PrettyFaces")); Assert.assertTrue(document.getResponseContent().contains(ASDF123)); }
From source file:mml.handler.post.MMLPostVersionHandler.java
/** * Handle a POST request//from www . j a v a2s . c om * @param request the raw request * @param response the response we will write to * @param urn the rest of the URL after stripping off the context * @throws MMLException */ public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try { String value = request.getParameter("data"); if (value != null) { JSONObject jObj = (JSONObject) JSONValue.parse(value); this.version1 = (String) jObj.get(JSONKeys.VERSION1); if (version1 == null) version1 = "/base"; else version1 = URLDecoder.decode(version1, "UTF-8"); this.longName = (String) jObj.get(JSONKeys.LONGNAME); this.docid = (String) jObj.get(JSONKeys.DOCID); this.dialect = getDialectFromDocid(); JSONArray layers = (JSONArray) jObj.get("layers"); ScratchVersion corcodeDefault = new ScratchVersion(version1, longName, docid + "/default", Database.CORCODE, null, true); ScratchVersion corcodePages = new ScratchVersion(version1, longName, docid + "/pages", Database.CORCODE, null, true); ScratchVersion text = new ScratchVersion(version1, longName, docid, Database.CORTEX, null, true); this.style = ScratchVersionSet.getDefaultStyleName(docid); for (int i = 0; i < layers.size(); i++) { JSONObject layer = (JSONObject) layers.get(i); String name = (String) layer.get(JSONKeys.NAME); String html = (String) layer.get(JSONKeys.BODY); stil = new STILDocument(style); pages = new STILDocument(style); // reduce html to text, corcode-default and corcode-pages Document doc = Jsoup.parseBodyFragment(html); Element body = doc.body(); parseBody(body); int num = ScratchVersion.layerNumber(name); text.addLayer(sb.toString().toCharArray(), num); corcodeDefault.addLayer(stil.toString().toCharArray(), num); corcodePages.addLayer(pages.toString().toCharArray(), num); } Scratch.save(text); Scratch.save(corcodeDefault); Scratch.save(corcodePages); response.setContentType("text/plain"); response.getWriter().write("OK"); } } catch (Exception e) { System.out.println(e.getMessage()); throw new MMLException(e); } }