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:$.Encodes.java

/**
     * URL ?, EncodeUTF-8.// w ww  . jav a2 s  .  co m
     */
    public static String urlDecode(String part) {

        try {
            return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
        } catch (UnsupportedEncodingException e) {
            throw Exceptions.unchecked(e);
        }
    }

From source file:com.sun.socialsite.web.ui.core.struts2.GroupView.java

public void setEncodedGroupHandle(String encodedGroupHandle) {
    try {//from www .  jav  a 2s . c  o m
        setGroupHandle(URLDecoder.decode(encodedGroupHandle, "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        log.error("Failed to decode grouphandle [" + encodedGroupHandle + "]", ex);
    }
}

From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java

private static String extractClasspath(ClassLoader cl) {
    StringBuffer buf = new StringBuffer();
    while (cl != null) {
        if (cl instanceof URLClassLoader) {
            URL urls[] = ((URLClassLoader) cl).getURLs();
            for (int i = 0; i < urls.length; i++) {
                if (buf.length() > 0) {
                    buf.append(File.pathSeparatorChar);
                }/*w w w. ja va2  s.co m*/
                String s = urls[i].getFile();
                try {
                    s = URLDecoder.decode(s, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    continue;
                }
                File f = new File(s);
                buf.append(f.getAbsolutePath());
            }
        }
        cl = cl.getParent();
    }
    return buf.toString();
}

From source file:com.asual.summer.core.util.StringUtils.java

public static String decode(String value) {
    try {//from  www.  j a va  2 s .  c o  m
        return URLDecoder.decode(value, (String) ResourceUtils.getProperty("app.encoding"));
    } catch (Exception e) {
        return value;
    }
}

From source file:com.adguard.commons.web.UrlUtils.java

/**
 * Tries to decode specified text (also trying to autodetect encoding).
 * If something gone wrong -- returns source text.
 *
 * @param text Text to decode//from  w ww. ja v a2 s .  c om
 * @return Decoded string
 */
public static String urlDecode(String text) {
    if (StringUtils.isEmpty(text)) {
        return text;
    }

    try {
        if (text.contains("%8")) {
            return URLDecoder.decode(text, "UTF-8");
        }

        return URLDecoder.decode(text, "ascii");
    } catch (Exception ex) {
        LOG.warn("Error decoding " + text, ex);
    }

    return text;
}

From source file:com.github.achatain.catalog.servlet.IndexIdServlet.java

@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final String userId = getUserId(req);
    final String colId = extractCollectionIdFromRequest(req);
    final String fieldName = URLDecoder.decode(extractFieldNameFromRequest(req), CharEncoding.UTF_8);

    LOG.info(format("User [%s] to add the following index [%s] in the collection [%s]", userId, fieldName,
            colId));//w w w  .  j  av a  2 s  . c o m

    final IndexMessage indexMessage = IndexMessage.create().withUserId(userId).withColId(colId)
            .withFieldName(fieldName).build();

    jmsContext.createProducer().send(indexCreateDestination, indexMessage);
}

From source file:URISupport.java

public static Map<String, String> parseQuery(String uri) throws URISyntaxException {
    try {//from  www .j a  va 2s .  co m
        Map<String, String> rc = new HashMap<String, String>();
        if (uri != null) {
            String[] parameters = uri.split("&");
            for (int i = 0; i < parameters.length; i++) {
                int p = parameters[i].indexOf("=");
                if (p >= 0) {
                    String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
                    String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
                    rc.put(name, value);
                } else {
                    rc.put(parameters[i], null);
                }
            }
        }
        return rc;
    } catch (UnsupportedEncodingException e) {
        throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
    }
}

From source file:com.aptana.webserver.internal.core.builtin.LocalWebServerHttpRequestHandler.java

private void handleRequest(HttpRequest request, HttpResponse response, boolean head)
        throws HttpException, IOException, CoreException, URISyntaxException {
    String target = URLDecoder.decode(request.getRequestLine().getUri(), IOUtil.UTF_8);
    URI uri = URIUtil.fromString(target);
    IFileStore fileStore = uriMapper.resolve(uri);
    IFileInfo fileInfo = fileStore.fetchInfo();
    if (fileInfo.isDirectory()) {
        fileInfo = getIndex(fileStore);//from   ww  w. j a v a  2  s  .c om
        if (fileInfo.exists()) {
            fileStore = fileStore.getChild(fileInfo.getName());
        }
    }
    if (!fileInfo.exists()) {
        response.setStatusCode(HttpStatus.SC_NOT_FOUND);
        response.setEntity(createTextEntity(
                MessageFormat.format(Messages.LocalWebServerHttpRequestHandler_FILE_NOT_FOUND, uri.getPath())));
    } else if (fileInfo.isDirectory()) {
        response.setStatusCode(HttpStatus.SC_FORBIDDEN);
        response.setEntity(createTextEntity(Messages.LocalWebServerHttpRequestHandler_FORBIDDEN));
    } else {
        response.setStatusCode(HttpStatus.SC_OK);
        if (head) {
            response.setEntity(null);
        } else {
            File file = fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor());
            final File temporaryFile = (file == null)
                    ? fileStore.toLocalFile(EFS.CACHE, new NullProgressMonitor())
                    : null;
            response.setEntity(
                    new NFileEntity((file != null) ? file : temporaryFile, getMimeType(fileStore.getName())) {
                        @Override
                        public void close() throws IOException {
                            try {
                                super.close();
                            } finally {
                                if (temporaryFile != null && !temporaryFile.delete()) {
                                    temporaryFile.deleteOnExit();
                                }
                            }
                        }
                    });
        }
    }
}

From source file:com.yiji.openapi.sdk.util.Encodes.java

public static String urlDecode(String part, String encoding) {

    try {//from ww w.j  a v  a  2 s  .  co  m
        return URLDecoder.decode(part, encoding);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.aliasource.webmail.server.LemonSSOProvider.java

@Override
public Credentials obtainCredentials(Map<String, String> settings, HttpServletRequest req) {
    String ticket = req.getParameter("ticket");
    if (ticket == null) {
        logger.warn("no ticket in url");
        return null;
    }/*from  w  w  w  .  j  a va  2  s  .  c o  m*/

    try {
        URL url = new URL(settings.get(SSO_VALIDATE_URL) + "?action=validate&ticket=" + ticket);
        InputStream in = url.openStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        transfer(in, out, true);
        String content = out.toString();
        if (logger.isDebugEnabled()) {
            logger.debug("SSO server returned:\n" + content);
        }
        Credentials creds = null;
        if (!content.equals("invalidOBMTicket")) {
            String[] ssoServerReturn = content.split("&password=");
            String login = ssoServerReturn[0].substring("login=".length());
            String pass = ssoServerReturn[1];
            creds = new Credentials(URLDecoder.decode(login, "UTF-8"), URLDecoder.decode(pass, "UTF-8"));
        }
        return creds;
    } catch (Exception e) {
        logger.error("Ticket validation error: " + e.getMessage(), e);
        return null;
    }

}