Here you can find the source of replaceString(String uri, String baseURI, Map
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> |
public static String replaceString(String uri, String baseURI, Map<String, String> prefixes)
//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; } } }