Java Map Replace replaceString(String uri, String baseURI, Map prefixes)

Here you can find the source of replaceString(String uri, String baseURI, Map prefixes)

Description

=====================================================================================
Shorten an URI by removing all bases or using its prefixes

License

Open Source License

Parameter

Parameter Description
uri String need to be shortened
baseURI Base URI. Null if we don't want to used base uri
prefixes List of prefixes <prefix, string>

Declaration

public static String replaceString(String uri, String baseURI, Map<String, String> prefixes) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /**//  w  w  w .j a v a 2 s . c  om
     * =====================================================================================<br>
     * Shorten an URI by removing all bases or using its prefixes
     * 
     * @param uri
     *            String need to be shortened
     * @param baseURI
     *            Base URI. Null if we don't want to used base uri
     * @param prefixes
     *            List of prefixes <prefix, string>
     * @return
     */
    public static String replaceString(String uri, String baseURI, Map<String, String> prefixes) {
        if (baseURI != null && uri.startsWith(baseURI)) {
            return uri.replace(baseURI, "");
        } else {
            if (prefixes != null) {
                for (Entry<String, String> prefix : prefixes.entrySet())
                    uri = uri.replace(prefix.getValue(), prefix.getKey());
            }
            return uri;
        }
    }
}

Related

  1. replaceProperties(final CharSequence string, final Map properties)
  2. replaceQueryParameterInUrl(String fullUrl, Map newParameter)
  3. replaceSeparator(String value, String separator, Map map)
  4. replaceString(Map bodyToReplace, String replacingContent)
  5. replaceString(String source, Map args)
  6. replaceTemplates(String template, Map entries)
  7. replaceTokens(String inputString, Map tokenMap)
  8. replaceToStringBuilder(String s, String begin, String end, Map values)
  9. replaceValues(String s, String begin, String end, Map values)