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:ch.cyberduck.core.HostParser.java

public static Host parse(final ProtocolFactory factory, final Protocol scheme, final String url) {
    final String input = url.trim();
    int begin = 0;
    int cut;/*from w ww.  ja  v  a2 s. c  o m*/
    Protocol protocol = null;
    if (input.indexOf("://", begin) != -1) {
        cut = input.indexOf("://", begin);
        protocol = factory.forName(input.substring(begin, cut));
        begin += cut - begin + 3;
    }
    if (null == protocol) {
        protocol = scheme;
    }
    String username;
    String password = null;
    if (protocol.isAnonymousConfigurable()) {
        username = preferences.getProperty("connection.login.anon.name");
    } else {
        username = preferences.getProperty("connection.login.name");
    }
    if (input.indexOf('@', begin) != -1) {
        if (-1 == input.indexOf(Path.DELIMITER, begin)
                || input.indexOf('@', begin) < input.indexOf(Path.DELIMITER, begin)) {
            cut = input.indexOf('@', begin);
            // Handle at sign in username
            while (cut < input.lastIndexOf('@')) {
                if (input.indexOf(Path.DELIMITER, begin) != -1
                        && input.indexOf('@', cut + 1) > input.indexOf(Path.DELIMITER, begin)) {
                    // At sign is part of the path
                    break;
                }
                cut = input.indexOf('@', cut + 1);
            }
            if (input.indexOf(':', begin) != -1 && cut > input.indexOf(':', begin)) {
                // ':' is not for the port number but username:pass separator
                username = input.substring(begin, input.indexOf(':', begin));
                begin += username.length() + 1;
                cut = input.indexOf('@', begin);
                try {
                    username = URLDecoder.decode(username, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    log.error(e.getMessage(), e);
                }
                password = input.substring(begin, cut);
                begin += password.length() + 1;
            } else {
                // No password given
                username = input.substring(begin, cut);
                begin += username.length() + 1;
                try {
                    username = URLDecoder.decode(username, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    }
    String hostname = preferences.getProperty("connection.hostname.default");
    String path = null;
    int port = protocol.getDefaultPort();
    // Handle IPv6
    if (input.indexOf('[', begin) != -1 && input.indexOf(']', begin) != -1) {
        if (input.indexOf(']', begin) > input.indexOf('[', begin)) {
            begin = input.indexOf('[', begin) + 1;
            cut = input.indexOf(']', begin);
            String address = input.substring(begin, cut);
            if (isv6Address(address)) {
                hostname = address;
                begin += hostname.length();
            }
        }
    } else if (input.indexOf(Path.DELIMITER, begin) != -1) {
        cut = input.indexOf(Path.DELIMITER, begin);
        String address = input.substring(begin, cut);
        if (isv6Address(address)) {
            hostname = address;
            begin += hostname.length();
        }
    } else {
        if (isv6Address(input)) {
            hostname = input;
            begin += hostname.length();
        }
    }
    if (StringUtils.isBlank(hostname)) {
        // Handle DNS name or IPv4
        if (StringUtils.isNotBlank(input)) {
            if (input.indexOf(':', begin) != -1 && (input.indexOf(Path.DELIMITER, begin) == -1
                    || input.indexOf(':', begin) < input.indexOf(Path.DELIMITER, begin))) {
                cut = input.indexOf(':', begin);
            } else if (input.indexOf(Path.DELIMITER, begin) != -1) {
                cut = input.indexOf(Path.DELIMITER, begin);
            } else {
                cut = input.length();
            }
            hostname = input.substring(begin, cut);
            begin += hostname.length();
        }
    }
    if (input.indexOf(':', begin) != -1 && (input.indexOf(Path.DELIMITER, begin) == -1
            || input.indexOf(':', begin) < input.indexOf(Path.DELIMITER, begin))) {
        begin = input.indexOf(':', begin) + 1;
        String portString;
        if (input.indexOf(Path.DELIMITER, begin) != -1) {
            cut = input.indexOf(Path.DELIMITER, begin);
            portString = input.substring(begin, cut);
            try {
                port = Integer.parseInt(portString);
                begin += portString.length();
            } catch (NumberFormatException e) {
                log.warn("Invalid port number given");
            }
            try {
                path = URLDecoder.decode(input.substring(begin, input.length()), "UTF-8");
                begin += path.length();
            } catch (UnsupportedEncodingException | IllegalArgumentException e) {
                log.error(e.getMessage(), e);
            }
        } else {
            portString = input.substring(begin, input.length());
            try {
                port = Integer.parseInt(portString);
                begin += portString.length();
            } catch (NumberFormatException e) {
                log.warn("Invalid port number given");
            }
        }
    }
    if (input.indexOf(Path.DELIMITER, begin) != -1) {
        try {
            path = URLDecoder.decode(input.substring(begin, input.length()), "UTF-8");
        } catch (UnsupportedEncodingException | IllegalArgumentException e) {
            log.error(e.getMessage(), e);
        }
    }
    switch (protocol.getType()) {
    case s3:
    case googlestorage:
    case swift:
        if (StringUtils.isNotBlank(protocol.getDefaultHostname())) {
            if (StringUtils.isNotBlank(hostname)) {
                // Replace with static hostname and prefix path with bucket
                if (StringUtils.isBlank(path)) {
                    path = PathNormalizer.normalize(hostname);
                } else {
                    path = PathNormalizer.normalize(hostname) + path;
                }
                hostname = protocol.getDefaultHostname();
            }
        }
    }
    final Host host = new Host(protocol, hostname, port, path, new Credentials(username, password));
    host.configure();
    return host;
}

From source file:com.zotoh.maedr.device.apache.HttpHplr.java

private static void getParams(HttpEvent ev, String qry) throws UnsupportedEncodingException {
    String[] ss = qry.split("&");
    String n, v, s;//www. j  av a2 s . c o m
    int pos;

    if (ss != null)
        for (int i = 0; i < ss.length; ++i) {
            s = ss[i];
            pos = s.indexOf("=");
            if (pos > 0) {
                n = trim(s.substring(0, pos));
                v = trim(s.substring(pos + 1));
                if (!isEmpty(v)) {
                    v = URLDecoder.decode(v, "utf-8");
                }
                ev.addParam(n, v);
            }
        }

}

From source file:com.hbc.api.gateway.alizhifu.util.AlipayCallBackValidator.java

public boolean signValidate(HttpServletRequest request) throws UnsupportedEncodingException {
    Map<String, String> parmmap = this.getParameterMap(request);
    Map<String, String> filterMap = this.parmFilter(parmmap);
    String cleanLink = this.createLinkString(filterMap);

    String alisign = request.getParameter("sign");
    String signType = request.getParameter("sign_type");
    if (StringUtils.isBlank(alisign) || StringUtils.isBlank(signType)) {
        return Boolean.FALSE;
    }//from  www . j av  a 2 s.  com

    if (signType.equalsIgnoreCase(SIGN_TYPE_OF_MD5)) {
        return AliPayMD5.verify(cleanLink, alisign, alipayConfig.securityCode, SIGN_ENCODING);
    } else if (signType.equalsIgnoreCase(SIGN_TYPE_OF_RSA)) {
        StringBuffer spayurl = new StringBuffer();
        for (String keystr : filterMap.keySet()) {
            spayurl = spayurl.append(keystr + "=" + URLDecoder.decode(filterMap.get(keystr), "UTF-8") + "&");
        }
        String dspayurl = spayurl.substring(0, spayurl.length() - 1);
        //mysign = RSA.sign(dspayurl, alipayConfig.privateKey, "UTF-8");
    }
    return Boolean.FALSE;
}

From source file:de.dailab.plistacontest.client.ClientAndContestHandler0MQ.java

/**
 * Handle incoming messages. This method is called by plista We check the
 * message, and extract the relevant parameter values
 * /*from  ww w.  j ava 2 s .c  o m*/
 * @see org.eclipse.jetty.server.Handler#handle(String,
 *      org.eclipse.jetty.server.Request,
 *      javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
public String handle(String typeMessage, String bodyMessage, String propertyMessage, String entityMessage)
        throws IOException {

    String responseText = "";
    String encoding = null;

    // handle idomaar messages
    if (bodyMessage == null || bodyMessage.length() == 0) {

        // we may recode the body message
        if (encoding != null) {
            bodyMessage = URLDecoder.decode(bodyMessage, encoding);
            propertyMessage = URLDecoder.decode(propertyMessage, encoding);
            entityMessage = URLDecoder.decode(entityMessage, encoding);
        }

        // delegate the request and create a response message
        responseText = handleIdomaarMessage(typeMessage, propertyMessage, entityMessage);
        return responseText;

    } else {
        // handle old data format messages
        // we may recode the body message
        if (encoding != null) {
            bodyMessage = URLDecoder.decode(bodyMessage, "utf-8");
        }
        responseText = handleTraditionalMessage(typeMessage, bodyMessage);
    }
    // send the response message as text
    return responseText;
}

From source file:com.erdao.PhotSpotCloud.PhotSpotCloudServlet.java

/**
 * do Get, main entry for this servlet//  www . j  a v  a  2s  . c o  m
 */
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    // get request params
    String qMode = req.getParameter("q");
    String debugstr = req.getParameter("dbg");
    if (debugstr != null) {
        try {
            debugstr = URLDecoder.decode(debugstr, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    jsoncb_ = req.getParameter("callback");
    String appVer = req.getParameter("appver");
    appVerDbl_ = 0.0;
    if (appVer != null)
        appVerDbl_ = Double.parseDouble(appVer.substring(0, 3));

    String compactJson = null;
    totalFeedSize_ = 0;
    // request branch
    if (qMode == null || qMode.equals("searchspot")) {
        compactJson = ProcessPhotoSearch(req);
    } else if (qMode.equals("localsearch")) {
        svcMode_ = MODE_LOCALSEARCH;
        compactJson = ProcessLocalSearch(req);
    }
    if (compactJson == null)
        return;

    // Compact JSON and format it
    resp.setContentType("text/plain");
    resp.setCharacterEncoding("utf-8");
    if (jsoncb_ != null)
        resp.getWriter().println(jsoncb_ + "(" + compactJson + ")");
    else
        resp.getWriter().println(compactJson);
    // debug log
    if (svcMode_ == MODE_LOCALSEARCH)
        log_.info("localsearch from=" + req.getRemoteAddr() + ",user-agent=" + req.getHeader("user-agent")
                + ",latlng=" + lat_ + "," + lng_ + ",dbg=" + debugstr + ",openfeed=" + openfeedSuccess_
                + ",feedcount=" + compactFeedSize_);
    else
        log_.info("spotsearch from=" + req.getRemoteAddr() + ",user-agent=" + req.getHeader("user-agent")
                + ",bbox=" + nwlat_ + "," + nwlng_ + "," + selat_ + "," + selng_ + ",svc=" + service_ + ",dbg="
                + debugstr + ",openfeed=" + openfeedSuccess_ + ",totalfeed=" + totalFeedSize_ + ",compactfeed="
                + compactFeedSize_);

}

From source file:com.suntek.gztpb.controller.ChemicalController.java

@RequestMapping(value = "isCarrierExists.htm", method = RequestMethod.POST)
public @ResponseBody String isCarrierExists(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    response.setCharacterEncoding("utf-8");
    String carrierNo = "";
    try {/*from ww  w.j a  va2  s  .co  m*/
        carrierNo = URLDecoder.decode(request.getParameter("carrierNo"), "utf-8");
    } catch (UnsupportedEncodingException e) {
        System.out.println(
                "[gztpbwebsite]?????????!"
                        + e.getMessage());
    }
    if (carrierNo == "null" || carrierNo == "") {
        return "0";
    } else {
        String carrier = chemicalService.isCarrierExists(carrierNo);
        if (carrierNo.equals("0"))
            return "0";
        else
            return java.net.URLEncoder.encode(carrier, "utf-8");
    }
}

From source file:org.fenixedu.start.service.ProjectService.java

private String getFilePath(Resource resource, String type) throws IOException {
    String path = URLDecoder.decode(resource.getURL().getPath(), "UTF-8");
    return path.substring(path.indexOf("/templates/" + type + "/") + ("/templates/" + type + "/").length());
}

From source file:com.googlecode.flyway.core.util.scanner.FileSystemLocationScanner.java

/**
 * Converts this file into a resource name on the classpath.
 * @param classPathRootOnDisk The location of the classpath root on disk, with a trailing slash.
 * @param file The file.// w ww  .  j  a  va  2 s  .  co  m
 * @return The resource name on the classpath.
 * @throws IOException when the file could not be read.
 */
private String toResourceNameOnClasspath(String classPathRootOnDisk, File file) throws IOException {
    String fileName = URLDecoder.decode(file.toURI().toURL().getFile(), "UTF-8");

    //Cut off the part on disk leading to the root of the classpath
    //This leaves a resource name starting with the scanRootLocation,
    //   with no leading slash, containing subDirs and the fileName.
    return fileName.substring(classPathRootOnDisk.length());
}

From source file:de.renew.workflow.connector.internal.cases.ScenarioHandler.java

@Override
public String getURI() {
    try {/*from  www  . j av  a 2s.c  om*/
        return URLDecoder.decode(m_scenario.getURI(), Charsets.UTF_8.name());
    } catch (final UnsupportedEncodingException e) {
        WorkflowConnectorPlugin.getDefault().getLog().log(StatusUtilities.statusFromThrowable(e));
    }

    return m_scenario.getURI();
}

From source file:com.tintin.devcloud.web.FileResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from   w  w w.j ava 2s . c o  m*/
public Response getFile(@QueryParam("path") String filePath) {
    try {
        String fileName = URLDecoder.decode(filePath, "UTF-8");
        File file = new File(fileName);
        String content = FileUtils.readFileToString(file);

        return Response.ok(new FileModel(file.getName(), content, filePath)).build();
    } catch (Exception e) {
        return Response.serverError().build();
    }

}