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.fatwire.dta.sscrawler.util.UriUtil.java

public static Map<String, String> extractParams(final String uri) {
    final String qs = URI.create(uri).getRawQuery();
    final Map<String, String> map = new TreeMap<String, String>();
    if (qs != null) {
        for (final String p : qs.split("&")) {
            final String[] nvp = p.split("=");
            try {
                final String key = URLDecoder.decode(nvp[0], UriUtil.UTF8);
                if (nvp.length > 0) {
                    map.put(key, URLDecoder.decode(nvp[1], UriUtil.UTF8));

                } else {
                    map.put(key, null);/*ww  w .j av a2 s.  c o  m*/
                }
            } catch (final UnsupportedEncodingException e) {
                UriUtil.log.error(e, e);
            }
        }

    }
    return map;
}

From source file:se.vgregion.util.HTTPUtils.java

public static String decode(String value) {
    try {// w  w w .j a va2s . co  m
        return URLDecoder.decode(value, "utf-8");
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException(ex);
    } catch (IllegalArgumentException ex) {
        return null;
    }
}

From source file:eu.europeana.querylog.clean.HTMLCleaner.java

@Override
public String clean(String query) {
    query = StringEscapeUtils.unescapeHtml4(query);
    try {/*w w w . j ava2s.  c o  m*/
        query = URLDecoder.decode(query, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.debug("error trying to convert the text from javascript to string");
    } catch (IllegalArgumentException e) {
        logger.debug("error trying to convert the text from javascript to string");
    }
    return query;

}

From source file:com.nkapps.billing.services.SearchServiceImpl.java

@Override
public String execSearchBy(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Cookie sbtCookie = null;/*from  w  w  w .  j ava2s . co m*/

    String searchBy = request.getParameter("searchBy");
    if (searchBy == null) {
        Cookie[] requestCookies = request.getCookies();
        for (Cookie c : requestCookies) {
            if (c.getName().equals("searchBy")) {
                sbtCookie = c;
            }
        }
        if (sbtCookie != null) {
            searchBy = URLDecoder.decode(sbtCookie.getValue(), "UTF-8");
        } else {
            searchBy = "";
        }
    } else {
        sbtCookie = new Cookie("searchBy", URLEncoder.encode(searchBy, "UTF-8"));
        sbtCookie.setPath("/");
        response.addCookie(sbtCookie);
    }
    return searchBy;
}

From source file:Main.java

private static String encodeUrlParam(String value, String charset) throws UnsupportedEncodingException {
    if (value == null) {
        return "";
    }/*from w w  w . j  a  v  a 2 s. c om*/

    try {
        String decoded = URLDecoder.decode(value, charset);

        String result = "";
        for (int i = 0; i < decoded.length(); i++) {
            char ch = decoded.charAt(i);
            result += (ch == '#') ? "#" : URLEncoder.encode(String.valueOf(ch), charset);
        }

        return result;
    } catch (IllegalArgumentException e) {
        return value;
    }
}

From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java

/**
 * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file
 * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file.
 * @param targetFolder the folder in which resources should be copied to
 * @throws java.io.IOException if the resources can be accessed or copied
 *//*from  w ww  . j  a  va2s .  c om*/
static void copyWebTestResources(final File targetFolder) throws IOException {
    final String resourcesPrefix = "com/canoo/webtest/resources/";
    final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader()
            .getResource(resourcesPrefix + "webtest.xml");

    if (webtestXmlUrl == null) {
        throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml");
    } else if (webtestXmlUrl.toString().startsWith("jar:file")) {
        final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1");
        final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name());
        final JarFile jarFile = new JarFile(jarFileName);
        final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml");

        for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
            final JarEntry jarEntry = entries.nextElement();
            if (jarEntry.getName().startsWith(resourcesPrefix)) {
                final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix);
                final URL url = new URL(urlPrefix + relativeName);
                final File targetFile = new File(targetFolder, relativeName);
                FileUtils.forceMkdir(targetFile.getParentFile());
                FileUtils.copyURLToFile(url, targetFile);
            }
        }
    } else if (webtestXmlUrl.toString().startsWith("file:")) {
        // we're probably developing and/or have a custom version of the resources in classpath
        final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl);
        final File resourceFolder = webtestXmlFile.getParentFile();

        FileUtils.copyDirectory(resourceFolder, targetFolder);
    } else {
        throw new IllegalStateException(
                "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl);
    }
}

From source file:it.marcoberri.mbmeteo.helper.ConfigurationHelper.java

private ConfigurationHelper() {
    try {//from   ww w.  j a v  a 2 s .com
        final URL main = getClass().getProtectionDomain().getCodeSource().getLocation();
        final String path = URLDecoder.decode(main.getPath(), "utf-8");
        final String webInfFolderPosition = new File(path).getPath();
        final String webInfFolder = webInfFolderPosition.substring(0, webInfFolderPosition.indexOf("classes"));
        prop = new Properties();
        prop.load(FileUtils.openInputStream(new File(webInfFolder + File.separator + "config.properties")));
    } catch (final IOException e) {
        throw new RuntimeException("Error initializing mongo db", e);
    }
}

From source file:de.brendamour.jpasskit.signing.PKPassTemplateFolder.java

public PKPassTemplateFolder(URL fileUrlOfTemplateDirectory) throws UnsupportedEncodingException {
    pathToTemplateDirectory = URLDecoder.decode(fileUrlOfTemplateDirectory.getFile(), "UTF-8");
}

From source file:cn.newtouch.util.utils.encode.EncodeUtils.java

/**
 * URL ?, EncodeUTF-8. /*from  www.  ja  va  2s  .  c o m*/
 */
public static String urlDecode(String input) {
    try {
        return URLDecoder.decode(input, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported Encoding Exception", e);
    }
}

From source file:com.aliyun.odps.ship.common.Util.java

public static String getSessionBaseDir() throws IllegalArgumentException {

    String basePath = getRootDir();

    if (DshipContext.INSTANCE.get(Constants.SESSION_DIR) != null) {
        try {/*  w  w w . j  av  a  2  s .c  o  m*/
            basePath = URLDecoder.decode(DshipContext.INSTANCE.get(Constants.SESSION_DIR), "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
    }

    File baseDir = new File(basePath);
    if (!baseDir.exists()) {
        baseDir.mkdirs();
    } else if (baseDir.isFile()) {
        throw new IllegalArgumentException("SessionDir must be directory, now is a file.");
    }
    return basePath;
}