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.spectralogic.ds3client.utils.MetadataStringManipulation.java

/**
 * Decodes a percent encoded string//w w w .  j a v  a  2  s.c  o m
 */
public static String toDecodedString(final String str) {
    if (str == null) {
        return null;
    }
    try {
        return URLDecoder.decode(str, CharEncoding.UTF_8);
    } catch (final UnsupportedEncodingException e) {
        //Should not happen
        throw new RuntimeException("Could not decode string: " + str, e);
    }
}

From source file:org.vietspider.server.handler.cms.metas.IndexSearchHandler.java

public String handle(final HttpRequest request, final HttpResponse response, final HttpContext context,
        String... params) throws Exception {
    String pattern = params[1];/*  w  w w. j  av a  2  s  .  c  o m*/
    int idx = pattern.indexOf('=');
    if (idx < 0 || idx >= pattern.length() - 1) {
        throw new IndexOutOfBoundsException("Incorrect parammeter");
    }

    String search = URLDecoder.decode(pattern.substring(idx + 1), "UTF-8");

    pattern = search;

    MetaList metas = new MetaList();
    metas.setAction("SEARCH");
    metas.setCurrentPage(Integer.parseInt(params[0]));

    String[][] parameters = ParameterParser.getParameters(params[1]);

    /*SearchQuery query = null;
    if(parameters.length > 0) {
      query = new SearchQuery(parameters[0][1]);
    //      for(int i = 1; i < parameters.length; i++) {
    //        if("region".equalsIgnoreCase(parameters[i][0])) {
    //          query.setRegion(parameters[i][1]);
    //        }
    //      }
    } else {
      throw new IndexOutOfBoundsException("Incorrect parammeter");
    }*/

    ArticleSearchQuery query = new ArticleSearchQuery();
    for (int i = 0; i < parameters.length; i++) {
        if (parameters[i][0].charAt(0) == '?') {
            parameters[i][0] = parameters[i][0].substring(1);
        }
        //      System.out.println(parameters[i][0] + " : "+ parameters[i][1]);
        if (parameters[i][0].equals("text")) {
            query.setPattern(parameters[i][1]);
        } else if (parameters[i][0].equals("source")) {
            query.setSource(parameters[i][1]);
        } else if (parameters[i][0].equals("dtstart")) {
            parameters[i][1] = parameters[i][1].replace('.', '/');
            try {
                SimpleDateFormat dateFormat = CalendarUtils.getDateFormat();
                Date date = dateFormat.parse(parameters[i][1]);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                calendar.set(Calendar.HOUR, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                query.setIndexFrom(calendar.getTimeInMillis());
            } catch (Exception e) {
                LogService.getInstance().setMessage(e, e.toString());
            }
        } else if (parameters[i][0].equals("dtend")) {
            parameters[i][1] = parameters[i][1].replace('.', '/');
            try {
                SimpleDateFormat dateFormat = CalendarUtils.getDateFormat();
                Date date = dateFormat.parse(parameters[i][1]);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                calendar.set(Calendar.HOUR, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
                query.setIndexTo(calendar.getTimeInMillis());
            } catch (Exception e) {
                LogService.getInstance().setMessage(e, e.toString());
            }
        }
    }

    if (Application.LICENSE != Install.PERSONAL) {
        //      ArticleSearchQuery query = new ArticleSearchQuery(parameters[0][1]);
        query.setHighlightStart("<b style=\"color: black; background-color: rgb(255, 255, 102);\">");
        query.setHighlightEnd("</b>");
        ArticleIndexStorage.getInstance().search(metas, query);
    }

    //    System.out.println("thay co " + metas.getData().size());

    //    System.out.println(parameters[0][1]);

    //    File tempFolder = UtilFile.getFolder("content/temp/search/");
    //    ContentSearcher2 searcher = new ContentSearcher2(ContentSearcher2.SIMPLE, tempFolder);
    //    HighlightBuilder highlighter = new HighlightBuilder(query.getPattern().toLowerCase());
    //    highlighter.setHighlightTag("<b style=\"color: black; background-color: rgb(255, 255, 102);\">", "</b>");
    //      query.setParser(new QueryParser());
    //    DefaultArticleHandler articleHandler2 = new DefaultArticleHandler(highlighter);
    //    searcher.search(metas, query, articleHandler2);
    //    ContentSearcher searcher = new ContentSearcher();
    //    searcher.search(metas, pattern);

    WebRM resources = new WebRM();
    StringBuilder builder = new StringBuilder(resources.getLabel("search"));
    metas.setTitle(builder.toString());
    metas.setUrl(params[1]);

    return write(request, response, context, metas, params);
}

From source file:com.zeroro.paypal.classic.ipn.IPNMessageParser.java

public IPNMessageParser(String ipnMessage) {

    nvp = new HashMap<>();

    if (!StringUtils.isEmpty(ipnMessage)) {
        String[] pairs = ipnMessage.split("&");
        for (String pair : pairs) {
            String[] keyValue = pair.split("=", 2); // match only the first =
            try {
                nvp.put(URLDecoder.decode(keyValue[0], "UTF-8"), URLDecoder.decode(keyValue[1], "UTF-8"));
            } catch (UnsupportedEncodingException e) { // will never happen as UTF-8 is supported
                logger.error("encoding ipn message error", e);
            }/* w  ww  .  j  a  v a2  s  .c  o  m*/
        }
    }
}

From source file:com.yilang.commons.utils.util.Encodes.java

public static String urlDecode(String part) {

    try {//  w ww.java 2s.co m
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.unchecked(e);
    }
}

From source file:de.metanome.backend.algorithm_execution.TempFileGenerator.java

public TempFileGenerator() throws UnsupportedEncodingException {
    // Get path to resource dir.
    String pathToFolder = Thread.currentThread().getContextClassLoader().getResource("").getPath();
    pathToFolder += "/" + TEMP_FILE_PATH;
    this.pathToFolder = URLDecoder.decode(pathToFolder, "utf-8");
    // Create subdir.
    new File(this.pathToFolder).mkdirs();

    this.createdFiles = new LinkedList<>();
}

From source file:com.pamarin.income.util.UrlUtils.java

/**
 * example<br/>//from w w w  .  ja va 2s.co m
 * input --> http%3A%2F%2Fpamarin.com%2F%40jittagornp<br/>
 * output --> http://pamarin.com/@jittagornp
 *
 * @param str
 * @return
 */
public static String decode(String str) {
    try {
        return URLDecoder.decode(str, ENCODE);
    } catch (Exception ex) {
        return str;
    }
}

From source file:com.bstek.dorado.web.resolver.WebContextSupportedController.java

/**
 * URI?ContentPathURI/*from  ww  w  .j av a 2  s  .  c  o  m*/
 */
protected String getRelativeRequestURI(HttpServletRequest request) throws UnsupportedEncodingException {
    String uri = (String) request.getAttribute("originalUrlPath");
    if (uri == null) {
        uri = request.getRequestURI().substring(getContextPath(request).length());
    }
    uri = StringUtils.replaceChars(URLDecoder.decode(uri, Configure.getString("view.uriEncoding")),
            ESCAPED_PATH_DELIM, PathUtils.PATH_DELIM);
    if (uri.length() > 1 && uri.charAt(0) == PathUtils.PATH_DELIM) {
        uri = uri.substring(1);
    }
    return uri;
}

From source file:ru.apertum.qsystem.reports.net.NetUtil.java

public static synchronized HashMap<String, String> getCookie(String data, String delimiter) {
    final HashMap<String, String> res = new HashMap<>();
    final String[] ss = data.split(delimiter);
    for (String s : ss) {
        final String[] ss0 = s.split("=");
        try {/*w  w  w. j a  va  2 s.c  o  m*/
            res.put(URLDecoder.decode(ss0[0], "utf-8"),
                    URLDecoder.decode(ss0.length == 1 ? "" : ss0[1], "utf-8"));
        } catch (UnsupportedEncodingException ex) {
            QLog.l().logRep().error(ss0[1], ex);
        }
    }
    return res;
}

From source file:jp.ambrosoli.http.server.action.IndexAction.java

@Execute(validator = false)
public String helloWorld() {
    String name = this.request.getParameter("name");
    String queryString = this.requestScope.get("javax.servlet.forward.query_string");
    String[] query = StringUtils.split(queryString, "=");
    if (ArrayUtils.isNotEmpty(query)) {
        try {/*  w  w  w  .j  av  a2  s .  c  o m*/
            name = URLDecoder.decode(query[1], this.request.getCharacterEncoding());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    if (StringUtils.isEmpty(name)) {
        this.response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
    ResponseUtil.write("Hello, " + name + "!", "UTF-8");
    return null;
}

From source file:com.adaptris.core.fs.FsHelper.java

/**
 * Create a file reference from a URL using the platform default encoding for the URL.
 * /*from w  ww  .j a va2  s . c  o m*/
 * @param url the URL.
 * @param charset the encoding that the url is considered to be in.
 * @return a File object
 * @throws UnsupportedEncodingException if the encoding was not supported.
 */
public static File createFileReference(URL url, String charset) throws UnsupportedEncodingException {
    String charSetToUse = StringUtils.defaultIfBlank(charset, System.getProperty("file.encoding"));
    String filename = URLDecoder.decode(url.getPath(), charSetToUse);
    // Cope with file://localhost/./config/blah -> /./config/blah is the result of getPath()
    // Munge that properly.
    if (filename.startsWith("/.")) {
        filename = filename.substring(1);
    }
    return new File(filename);
}