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:com.consol.citrus.admin.util.FileHelperImpl.java

/**
 * {@inheritDoc}/*from  w ww . j av a  2s.  c om*/
 */
public String decodeDirectoryUrl(String url, String rootDirectory) {
    String directory = null;

    try {
        directory = URLDecoder.decode(url, "UTF-8"); // TODO use system default encoding?
    } catch (UnsupportedEncodingException e) {
        throw new CitrusAdminRuntimeException("Unable to decode directory URL", e);
    }

    if (directory.equals("/")) {
        if (StringUtils.hasText(rootDirectory)) {
            directory = rootDirectory;
        } else {
            return rootDirectory;
        }
    }

    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:org.wallride.web.controller.admin.user.UserSearchController.java

@RequestMapping(method = RequestMethod.GET)
public String search(@PathVariable String language, @Validated @ModelAttribute("form") UserSearchForm form,
        BindingResult result, @PageableDefault(50) Pageable pageable, Model model,
        HttpServletRequest servletRequest) throws UnsupportedEncodingException {
    Page<User> users = userService.getUsers(form.toUserSearchRequest(), pageable);

    model.addAttribute("users", users);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new Pagination<>(users, 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  ww  .j a v  a  2s  . com*/

    return "user/index";
}

From source file:de.highbyte_le.weberknecht.request.RequestWrapper.java

/**
 * read URL encoded parameters (enctype="application/x-www-form-urlencoded") from HTTP method body (HTTP POST)
 * //from  ww  w .ja  va2 s  . com
 * <p>the default reader is used to read the method body.
 * The specified encoding is only used to decode the URL parameters, not to read the method body.
 * </p>
 * 
 * @param request
 * @param urlEncoding
 *       the character set encoding used to decode the URL encoded parameters.
 */
public static RequestWrapper createFromUrlEncodedContent(HttpServletRequest request, String urlEncoding)
        throws IOException {
    RequestWrapper wrapper = new RequestWrapper();
    int contentLength = request.getContentLength();
    if (logger.isDebugEnabled())
        logger.debug("content length is " + contentLength);

    if (contentLength > 0) {
        String query = extractQuery(request);

        if (logger.isDebugEnabled())
            logger.debug("query is '" + query + "'");

        int startIndex = 0;
        int i;
        do {
            i = query.indexOf("&", startIndex);
            String nameValue;
            if (i != -1) {
                nameValue = query.substring(startIndex, i);
            } else {
                nameValue = query.substring(startIndex, query.length());
            }

            int j = nameValue.indexOf("=");
            if (j != -1) {
                String name = URLDecoder.decode(nameValue.substring(0, j), urlEncoding);
                String value = URLDecoder.decode(nameValue.substring(j + 1, nameValue.length()), urlEncoding);
                wrapper.addParameter(name, value);
                logger.debug("createFromUrlEncodedContent(HttpServletRequest, String) - found parameter: "
                        + name + "=" + value);
            }

            startIndex = i + 1;
        } while (i != -1);
    }

    return wrapper;
}

From source file:de.mpg.mpdl.service.rest.screenshot.service.HtmlScreenshotServlet.java

/**
 * Read a parameter from the request/*w  ww  .  j av a2  s .c  o  m*/
 * 
 * @param req
 * @param name
 * @return
 * @throws UnsupportedEncodingException
 */
private String readParam(HttpServletRequest req, String name) throws UnsupportedEncodingException {
    String value = req.getParameter(name);
    if ("crop".equals(name) && value != null) {
        String notEncodedvalue = repareCropParam(value);
        if (!notEncodedvalue.equals(value))
            return notEncodedvalue;
    }
    return value == null ? "" : URLDecoder.decode(value, "UTF-8");
}

From source file:se.vgregion.pubsub.push.impl.DefaultPushSubscriberVerifyTest.java

@Test
@Transactional//from   w w  w  .  j ava 2  s  . com
@Rollback
public void verify() throws Exception {
    final LinkedBlockingQueue<HttpRequest> requests = new LinkedBlockingQueue<HttpRequest>();

    server.register("/*", new HttpRequestHandler() {
        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context)
                throws HttpException, IOException {
            requests.add(request);

            response.setEntity(
                    new StringEntity(getQueryParamValue(request.getRequestLine().getUri(), "hub.challenge")));
        }
    });

    subscriber.verify(SubscriptionMode.SUBSCRIBE);

    Assert.assertEquals(1, requests.size());

    HttpRequest actualRequest = requests.poll();
    String requestUri = actualRequest.getRequestLine().getUri();
    Assert.assertEquals("subscribe", getQueryParamValue(requestUri, "hub.mode"));
    Assert.assertEquals(subscriber.getTopic().toString(),
            URLDecoder.decode(getQueryParamValue(requestUri, "hub.topic"), "UTF-8"));
    Assert.assertNotNull(getQueryParamValue(requestUri, "hub.challenge"));
    Assert.assertEquals("123", getQueryParamValue(requestUri, "hub.lease_seconds"));
    Assert.assertEquals(subscriber.getVerifyToken(), getQueryParamValue(requestUri, "hub.verify_token"));
}

From source file:com.frostwire.search.eztv.EztvSearchResult.java

private String parseFileName(String urlEncodedFileName) {
    String decodedFileName = null;
    try {/*from w  w w  .jav  a 2  s.  com*/
        if (!StringUtils.isNullOrEmpty(urlEncodedFileName)) {
            decodedFileName = URLDecoder.decode(urlEncodedFileName, "UTF-8");
        }
    } catch (UnsupportedEncodingException ignored) {
    }
    return decodedFileName;
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLURIDereferencer.java

public Data dereference(URIReference uriReference, XMLCryptoContext context) throws URIReferenceException {
    if (null == uriReference) {
        throw new NullPointerException("URIReference cannot be null");
    }//  ww  w.j a  va  2s . co m
    if (null == context) {
        throw new NullPointerException("XMLCrytoContext cannot be null");
    }

    String uri = uriReference.getURI();
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOG.warn("could not URL decode the uri: " + uri);
    }
    LOG.debug("dereference: " + uri);
    try {
        InputStream dataInputStream = findDataInputStream(uri);
        if (null == dataInputStream) {
            LOG.debug("cannot resolve, delegating to base DOM URI dereferencer: " + uri);
            return this.baseUriDereferencer.dereference(uriReference, context);
        }
        return new OctetStreamData(dataInputStream, uri, null);
    } catch (IOException e) {
        throw new URIReferenceException("I/O error: " + e.getMessage(), e);
    }
}

From source file:org.wallride.web.controller.admin.tag.TagSearchController.java

@RequestMapping
public String search(@PathVariable String language, @Validated @ModelAttribute("form") TagSearchForm form,
        BindingResult errors, @PageableDefault(50) Pageable pageable, Model model,
        HttpServletRequest servletRequest) throws UnsupportedEncodingException {
    Page<Tag> tags = tagService.getTags(form.toTagSearchRequest(), pageable);

    model.addAttribute("tags", tags);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new Pagination<>(tags, 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 ww  w. j av  a 2  s.c  o  m*/

    return "tag/index";
}

From source file:com.huawei.streaming.cql.executor.mergeuserdefinds.Merger.java

private void copyFilesToTmp(Application app) throws IOException {
    String[] files = app.getUserFiles();

    if (files != null) {
        for (String file : files) {
            FileUtils.copyFileToDirectory(new File(file), tmpOutputDir);
        }/*from w  w  w  .j  a v  a2 s .c  o m*/
    }

    if (Strings.isNullOrEmpty(System.getProperty("cql.dependency.jar"))) {
        //for unit test, not throw exception here.
        LOG.error("Failed to found cql.dependency.jar path in System properties.");
    } else {
        String path = System.getProperty("cql.dependency.jar");
        FileUtils.copyFileToDirectory(new File(URLDecoder.decode(path, "UTF-8")), tmpOutputDir);
    }
}

From source file:at.ac.univie.isc.asio.web.HttpServer.java

/**
 * Attempt to parse request parameters from the query string and the request body in case of a
 * form submission./*from  www .  ja va  2 s  .c  o  m*/
 *
 * @param exchange http exchange
 * @return parsed parameters as map
 * @throws IOException on any errors
 */
public static Map<String, String> parseParameters(final HttpExchange exchange) throws IOException {
    final ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
    final String rawQuery = exchange.getRequestURI().getQuery();
    if (rawQuery != null) { // null if no query string present
        final String query = URLDecoder.decode(rawQuery, StandardCharsets.UTF_8.name());
        params.putAll(PARAMETER_PARSER.split(query));
    }
    if (isForm(exchange)) {
        final String rawBody = Payload.decodeUtf8(ByteStreams.toByteArray(exchange.getRequestBody()));
        final String form = URLDecoder.decode(rawBody, StandardCharsets.UTF_8.name());
        params.putAll(PARAMETER_PARSER.split(form));
    }
    return params.build();
}