Java URL Decode decodeValue(String value)

Here you can find the source of decodeValue(String value)

Description

decode Value

License

Open Source License

Return

value decoded from JavaScript's decodeURIComponent() format.

Declaration

public static String decodeValue(String value) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright ? 2008, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   www . j  a  v a2 s .co m*/
 * IBM Corporation - initial API and implementation
 *
 *******************************************************************************/

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

public class Main {
    /**
     * @return <code>value</code> decoded from JavaScript's decodeURIComponent() format.
     */
    public static String decodeValue(String value) {
        try {
            return URLDecoder
                    .decode(value, "UTF-8").replaceAll("\\%20", " ").replaceAll("\\!", "\\%21").replaceAll("\\'", "\\%27") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
                    .replaceAll("\\(", "\\%28").replaceAll("\\)", "\\%29").replaceAll("\\~", "\\%7E"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
        } catch (UnsupportedEncodingException e) {
            // Shouldn't happen, but just in case...
            return value
                    .replaceAll("\\%20", " ").replaceAll("\\!", "\\%21").replaceAll("\\'", "\\%27").replaceAll("\\(", "\\%28") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
                    .replaceAll("\\)", "\\%29").replaceAll("\\~", "\\%7E"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        }
    }
}

Related

  1. decodeString(String myString)
  2. decodeStringByUTF8(String str)
  3. decodeStringFields(Object objBean, String code)
  4. decodeUTF8(String s)
  5. decodeValue(String str)
  6. parseStringParamAndDecode(String inParam, String defaultVal, String charset)
  7. pathDecode(String path)
  8. pathDecode(String path)
  9. percentDecode(String encodedString, String messageEncoding)