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.salesmanager.core.util.StringUtil.java

public static Map deformatUrlResponse(String payload) throws Exception {
    HashMap nvp = new HashMap();
    StringTokenizer stTok = new StringTokenizer(payload, "&");
    while (stTok.hasMoreTokens()) {
        StringTokenizer stInternalTokenizer = new StringTokenizer(stTok.nextToken(), "=");
        if (stInternalTokenizer.countTokens() == 2) {
            String key = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8");
            String value = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8");
            nvp.put(key.toUpperCase(), value);
        }/*from  w  ww. j av a2 s  .c o m*/
    }
    return nvp;
}

From source file:com.petercho.Encoder.java

/**
 * Description of the Method//from w ww.j  av  a 2 s.co m
 *
 * @param str Description of the Parameter
 * @return Description of the Return Value
 */
public static String urlDecode(String str) {
    try {
        return URLDecoder.decode(str, DEFAULT_ENCODING);
    } catch (Exception e) {
        return "Decoding error";
    }
}

From source file:com.hurence.logisland.classloading.PluginLoader.java

/**
 * Scan for plugins./*from w ww  . ja  va  2 s  .c  o m*/
 */
private static void scanAndRegisterPlugins() {
    Set<URL> urls = new HashSet<>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    while (cl != null) {
        if (cl instanceof URLClassLoader) {
            urls.addAll(Arrays.asList(((URLClassLoader) cl).getURLs()));
            cl = cl.getParent();
        }
    }

    for (URL url : urls) {
        try {
            Archive archive = null;
            try {
                archive = new JarFileArchive(
                        new File(URLDecoder.decode(url.getFile(), Charset.defaultCharset().name())), url);
            } catch (Exception e) {
                //silently swallowing exception. just skip the archive since not an archive
            }
            if (archive == null) {
                continue;
            }
            Manifest manifest = archive.getManifest();
            if (manifest != null) {
                String exportedPlugins = manifest.getMainAttributes()
                        .getValue(ManifestAttributes.MODULE_EXPORTS);
                if (exportedPlugins != null) {
                    String version = StringUtils.defaultIfEmpty(
                            manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION),
                            "UNKNOWN");

                    logger.info("Loading components from module {}", archive.getUrl().toExternalForm());

                    final Archive arc = archive;

                    if (StringUtils.isNotBlank(exportedPlugins)) {
                        Arrays.stream(exportedPlugins.split(",")).map(String::trim).forEach(s -> {
                            if (registry.putIfAbsent(s, PluginClassloaderBuilder.build(arc)) == null) {
                                logger.info("Registered component '{}' version '{}'", s, version);
                            }

                        });
                    }
                }
            }

        } catch (Exception e) {
            logger.error("Unable to load components from " + url.toExternalForm(), e);
        }
    }
}

From source file:io.fabric8.maven.generator.javaexec.FatJarDetectorTest.java

private String decodeUrl(URL testDirUrl) throws UnsupportedEncodingException {
    return URLDecoder.decode(testDirUrl.getPath(), "UTF-8");
}

From source file:lv.semti.morphology.webservice.InflectPhraseResource.java

@Get
public String retrieve() {
    String query = (String) getRequest().getAttributes().get("phrase");
    try {//from ww w . j  a v a2  s .  c  om
        query = URLDecoder.decode(query, "UTF8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    String category = getQuery().getValues("category");

    MorphoServer.analyzer.enableGuessing = true;
    MorphoServer.analyzer.enableVocative = true;
    MorphoServer.analyzer.guessVerbs = false;
    MorphoServer.analyzer.guessParticiples = false;
    MorphoServer.analyzer.guessAdjectives = true;
    MorphoServer.analyzer.guessInflexibleNouns = true;
    MorphoServer.analyzer.enableAllGuesses = true;

    //MorphoServer.analyzer.describe(new PrintWriter(System.err));

    JSONObject oInflections = new JSONObject();
    Expression e = new Expression(query, category, true); // Pieemam, ka klients padod pamatformu
    //e.describe(new PrintWriter(System.err)); // ko tad tageris im ir sadom?jis
    Map<String, String> inflections = e.getInflections();
    for (String i_case : inflections.keySet()) {
        oInflections.put(i_case, inflections.get(i_case).replaceAll("'", "''"));
    }
    if (e.category == Category.hum) {
        if (e.gender == Gender.masculine)
            oInflections.put(AttributeNames.i_Gender, AttributeNames.v_Masculine);
        if (e.gender == Gender.feminine)
            oInflections.put(AttributeNames.i_Gender, AttributeNames.v_Feminine);
    }

    MorphoServer.analyzer.defaultSettings();
    return oInflections.toJSONString();
}

From source file:Main.java

private static String decode(final String content, final String encoding) {
    try {//from  w w w . j  a v  a 2s .  c o m
        return URLDecoder.decode(content, encoding != null ? encoding : "UTF-8");
    } catch (UnsupportedEncodingException problem) {
        throw new IllegalArgumentException(problem);
    }
}

From source file:com.apabi.qrcode.utils.EncodeUtils.java

/**
 * URL ?./*w w  w .j  a  v  a  2s.com*/
 */
public static String urlDecode(final String input, final String encoding) {
    try {
        return URLDecoder.decode(input, encoding);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported Encoding Exception", e);
    }
}

From source file:de.zib.gndms.gndmc.utils.RedirectResponseExtractor.java

@Override
public void extractData(final String url, final ClientHttpResponse response) throws IOException {

    super.extractData(url, response);

    cookie = null;/*from  ww  w.  j ava 2s .  com*/
    location = null;

    for (String header : getHeaders().keySet()) {
        if ("Set-Cookie".equals(header)) {
            cookie = new LinkedList<String>();

            for (String value : getHeaders().get(header)) {
                cookie.add(value);
            }
        } else if ("Location".equals(header)) {
            location = URLDecoder.decode(getHeaders().get(header).get(0), "utf8");
        }
    }

    if (null == location) {
        throw new IllegalArgumentException("Got a redirection but no Location (HTTP Header) to redirect to.");
    }
}

From source file:spring.travel.site.auth.CookieDecoder.java

private String urlDecode(String arg) {
    try {/*from  w w  w.j  a  v  a  2 s  .c o m*/
        return URLDecoder.decode(arg, "UTF-8");
    } catch (UnsupportedEncodingException bogus) {
        return arg;
    }
}

From source file:lv.semti.morphology.webservice.TokenResource.java

@Get("json")
public String retrieve() {
    String query = (String) getRequest().getAttributes().get("query");
    try {/*from   w ww  . jav a2s .  c o m*/
        query = URLDecoder.decode(query, "UTF8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return analyze(query);
}