Java URI to extractParamsFromURI(String uri)

Here you can find the source of extractParamsFromURI(String uri)

Description

Extract a dispatch rule string from URI parameters (specified using example values)

License

Apache License

Parameter

Parameter Description
uri The URI containing parameters

Return

A string representing dispatch rules for the corresponding incoming request.

Declaration

public static String extractParamsFromURI(String uri) 

Method Source Code


//package com.java2s;
/*//from   w  w  w .j  a va 2s .  c om
 * Licensed to Laurent Broudoux (the "Author") under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. Author licenses this
 * file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Main {
    /**
     * Extract a dispatch rule string from URI parameters (specified using example values)
     * @param uri The URI containing parameters
     * @return A string representing dispatch rules for the corresponding incoming request.
     */
    public static String extractParamsFromURI(String uri) {
        if (uri.contains("?") && uri.contains("=")) {
            String parameters = uri.substring(uri.indexOf("?") + 1);
            StringBuilder params = new StringBuilder();

            for (String parameter : parameters.split("&")) {
                String[] pair = parameter.split("=");
                try {
                    String key = URLDecoder.decode(pair[0], "UTF-8");
                    String value = URLDecoder.decode(pair[1], "UTF-8");
                    if (params.length() > 0) {
                        params.append(" && ");
                    }
                    params.append(key);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }
            return params.toString();
        }
        return "";
    }
}

Related

  1. extractFromURIParams(String paramsRule, String uri)
  2. extractHostAddress(String uri)
  3. extractHostname(String uri)
  4. extractLocalName(String uri)
  5. extractOntologyNameUriFromRDF(String rdfString, boolean generateURI)
  6. extractS3Key(URI uri)
  7. extractTargetSystemFromUri(URI uri)
  8. extractURIFromText(String texto)
  9. toDecodedString(URI uri)