Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:org.thingsplode.synapse.core.Uri.java

private void processQuery(String encoding) throws UnsupportedEncodingException {
    queryParameters = new ArrayList<>();
    String[] pairs = query.split("&");
    for (String pair : pairs) {
        int idx = pair.indexOf("=");
        queryParameters.add(new Parameter<>(URLDecoder.decode(pair.substring(0, idx), encoding),
                URLDecoder.decode(pair.substring(idx + 1), encoding)));
    }//w w w.  j a  va 2 s. c  om
}

From source file:io.pivotal.cla.webdriver.BaseWebDriverTests.java

protected static String urlDecode(String value) throws UnsupportedEncodingException {
    return URLDecoder.decode(value, "UTF-8");
}

From source file:com.geecko.QuickLyric.lyrics.LyricWiki.java

@Reflection
public static Lyrics fromMetaData(String artist, String title) {
    if ((artist == null) || (title == null))
        return new Lyrics(ERROR);
    String originalArtist = artist;
    String originalTitle = title;
    String url = null;/*  www .  ja va2s.  c o  m*/
    try {
        String encodedArtist = URLEncoder.encode(artist, "UTF-8");
        String encodedSong = URLEncoder.encode(title, "UTF-8");
        JSONObject json = new JSONObject(
                getUrlAsString(new URL(String.format(baseUrl, encodedArtist, encodedSong))).replace("song = ",
                        ""));
        url = URLDecoder.decode(json.getString("url"), "UTF-8");
        artist = json.getString("artist");
        title = json.getString("song");
        encodedArtist = URLEncoder.encode(artist, "UTF-8");
        encodedSong = URLEncoder.encode(title, "UTF-8");
        json = new JSONObject(getUrlAsString(new URL(String.format(baseAPIUrl, encodedArtist, encodedSong))))
                .getJSONObject("result");
        Lyrics lyrics = new Lyrics(POSITIVE_RESULT);
        lyrics.setArtist(artist);
        lyrics.setTitle(title);
        lyrics.setText(json.getString("lyrics").replaceAll("\n", "<br />"));
        lyrics.setURL(url);
        lyrics.setOriginalArtist(originalArtist);
        lyrics.setOriginalTitle(originalTitle);
        return lyrics;
    } catch (JSONException e) {
        return new Lyrics(NO_RESULT);
    } catch (IOException e) {
        return url == null ? new Lyrics(ERROR) : fromURL(url, originalArtist, originalTitle);
    }
}

From source file:io.lightlink.utils.ClasspathScanUtils.java

private static void findFromDirectory(URL packageURL, List<String> names) throws UnsupportedEncodingException {
    if (packageURL == null)
        return;//from  w ww .  j  a  va2 s.co m
    File folder = new File(URLDecoder.decode(packageURL.getPath(), "UTF-8"));

    Collection<File> files = FileUtils.listFiles(folder, null, true);
    int length = folder.getAbsolutePath().length();

    String entryName;
    if (files != null)
        for (File actual : files) {
            entryName = actual.getAbsolutePath().substring(length);
            names.add(entryName);
        }
}

From source file:org.wallride.web.controller.admin.customfield.CustomFieldSearchController.java

@RequestMapping(method = RequestMethod.GET)
public String search(@PathVariable String language,
        @Validated @ModelAttribute("form") CustomFieldSearchForm form, BindingResult result,
        @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest)
        throws UnsupportedEncodingException {
    Page<CustomField> customFields = customfieldService.getCustomFields(form.toCustomFieldSearchRequest(),
            pageable);/*from   ww w.  jav a 2s.co  m*/

    model.addAttribute("customFields", customFields);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new Pagination<>(customFields, servletRequest));

    UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest)
            .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build();
    if (!StringUtils.isEmpty(uriComponents.getQuery())) {
        model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8"));
    }

    return "customfield/index";
}

From source file:com.krawler.esp.handlers.APICallHandlerServiceImpl.java

@Override
public JSONObject callApp(String appURL, JSONObject jData, String companyid, String action, boolean storeCall) {
    String requestData = (jData == null ? "" : jData.toString());

    Apiresponse apires = null;//  w  ww.  j  a  va2 s.  c  o m
    if (storeCall) {
        apires = makePreEntry(companyid, requestData, action);
    }
    String res = "{success:false}";
    InputStream iStream = null;
    String strSandbox = appURL + API_STRING;
    try {
        URL u = new URL(strSandbox);
        URLConnection uc = u.openConnection();
        uc.setDoOutput(true);
        uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        java.io.PrintWriter pw = new java.io.PrintWriter(uc.getOutputStream());
        pw.println("action=" + action + "&data=" + URLEncoder.encode(requestData, "UTF-8"));
        pw.close();
        iStream = uc.getInputStream();
        java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(iStream));
        res = URLDecoder.decode(in.readLine(), "UTF-8");
        in.close();
        iStream.close();
    } catch (IOException iex) {
        logger.warn("Remote API call for '" + strSandbox + "' failed because " + iex.getMessage());
    } finally {
        if (iStream != null) {
            try {
                iStream.close();
            } catch (Exception e) {
            }
        }
    }
    JSONObject resObj;
    try {
        resObj = new JSONObject(res);
    } catch (Exception ex) {
        logger.warn("Improper response from Remote API: " + res);
        resObj = new JSONObject();
        try {
            resObj.put("success", false);
        } catch (Exception e) {
        }
    }

    if (storeCall) {
        makePostEntry(apires, res);
    }

    return resObj;
}

From source file:org.wallride.web.controller.admin.comment.CommentSearchController.java

@RequestMapping(method = RequestMethod.GET)
public String search(@PathVariable String language, @Validated CommentSearchForm form, BindingResult result,
        @PageableDefault(value = 50, sort = "date", direction = Sort.Direction.DESC) Pageable pageable,
        Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException {
    Page<Comment> comments = commentService.getComments(form.toCommentSearchRequest(), pageable);

    model.addAttribute("form", form);
    model.addAttribute("comments", comments);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new org.wallride.web.support.Pagination<>(comments, servletRequest));

    UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest)
            .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build();
    if (!StringUtils.isEmpty(uriComponents.getQuery())) {
        model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8"));
    }/*from  w w w.  ja  v a2 s .  c  om*/

    return "comment/index";
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.SetEmailDA.java

public ActionForward setEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    final String host = HostAccessControl.getRemoteAddress(request);
    final String ip = request.getRemoteAddr();
    final String password = request.getParameter("password");
    final String userUId = request.getParameter("userUId");
    final String email = URLDecoder.decode(request.getParameter("email"), "UTF-8");

    String message = "ko";

    try {// w ww .ja  v a2 s  .  c om

        SetEmail.run(host, ip, password, userUId, email);
        final User user = User.findByUsername(userUId);
        if (user.getPerson() != null && user.getPerson().getStudent() != null) {
            final Student student = user.getPerson().getStudent();
            for (final Registration registration : student.getRegistrationsSet()) {
                final StudentCandidacy candidacy = registration.getStudentCandidacy();
                if (candidacy != null
                        && (candidacy instanceof DegreeCandidacy || candidacy instanceof IMDCandidacy)
                        && candidacy.getExecutionYear().isCurrent()
                        && !candidacy.getCandidacySituationsSet().isEmpty()) {
                    new PDFGeneratorThread(candidacy.getExternalId(), request.getServerName(),
                            request.getServerPort(), request.getContextPath(), request.getServletPath())
                                    .start();
                }
            }
        }
        message = "ok";
    } catch (NotAuthorizedException ex) {
        message = "Not authorized";
    } catch (UserAlreadyHasEmailException ex) {
        message = "User already has email.";
    } catch (UserDoesNotExistException ex) {
        message = "User does not exist.";
    } catch (Throwable ex) {
        message = ex.getMessage();
        logger.error(ex.getMessage(), ex);
    } finally {
        final ServletOutputStream servletOutputStream = response.getOutputStream();
        response.setContentType("text/html");
        servletOutputStream.print(message);
        servletOutputStream.flush();
        response.flushBuffer();
    }

    return null;
}

From source file:com.payu.ratel.server.InMemoryDiscoveryServer.java

@Override
@PUT/*from w  w w . j a v  a2  s.  c o m*/
@Consumes("application/json")
@Path("/service/{service}")
public void collectStatistics(@PathParam("service") String address,
        Map<String, Map<String, String>> statistics) {
    try {
        statisticsHolder.putStatistics(URLDecoder.decode(address, "UTF-8"), statistics);
    } catch (UnsupportedEncodingException e) {
        throw new AssertionError("UTF-8 must be supported", e);
    }
}

From source file:io.github.kitarek.elasthttpd.plugins.consumers.file.mapper.UriToFileMapper.java

private String normalizeUrlRequestPath(String uriRequestPath) {
    String localRequestPath;/*ww  w .  j  a v a2s .  co  m*/
    try {
        localRequestPath = URLDecoder.decode(uriRequestPath, Charset.defaultCharset().displayName());
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Cannot decode URI. Using original URI path for file", e);
        localRequestPath = uriRequestPath;
    }
    final Path p = Paths.get(localRequestPath);
    return p.normalize().toAbsolutePath().toString();
}