@Test public void testAddParametersToURIQuery() { Map<String, String> newParams = new HashMap<>(); newParams.put("conversationId", "0NXMAIN21"); Map<String, String> expectedParams = new HashMap<>(parameters); expectedParams.put("conversationId", "0NXMAIN21"); String newUri = URIUtils.addParametersToURIQuery(URI, newParams); assertEquals( "http: newUri); String uriPath = URIUtils.getURIPath(newUri); String newUriQuery = newUri.substring(uriPath.length() + 1); Map<String, String> actualParams = URIUtils.getRequestParameters(newUriQuery); assertEquals(expectedParams, actualParams); String newPartialUri = URIUtils.addParametersToURIQuery(PARTIAL_URI, newParams); assertEquals( "nuxeo/view_documents.faces?currentTab=TAB_CONTENT&documentId=4012a2d7-384e-4735-ab98-b06b598072fa&repositoryName=demo&conversationId=0NXMAIN21", newPartialUri); uriPath = URIUtils.getURIPath(newPartialUri); newUriQuery = newPartialUri.substring(uriPath.length() + 1); actualParams = URIUtils.getRequestParameters(newUriQuery); assertEquals(expectedParams, actualParams); }
public static String addParametersToURIQuery(String uriString, Map<String, String> parameters) { if (uriString == null || parameters == null || parameters.isEmpty()) { return uriString; } String uriPath = getURIPath(uriString); Map<String, String> existingParams = getRequestParameters(uriString.substring(uriPath.length())); if (existingParams == null) { existingParams = new LinkedHashMap<>(); } existingParams.putAll(parameters); String res; if (!existingParams.isEmpty()) { String newQuery = getURIQuery(existingParams); res = uriPath + '?' + newQuery; } else { res = uriPath; } return res; }
URIUtils { public static String addParametersToURIQuery(String uriString, Map<String, String> parameters) { if (uriString == null || parameters == null || parameters.isEmpty()) { return uriString; } String uriPath = getURIPath(uriString); Map<String, String> existingParams = getRequestParameters(uriString.substring(uriPath.length())); if (existingParams == null) { existingParams = new LinkedHashMap<>(); } existingParams.putAll(parameters); String res; if (!existingParams.isEmpty()) { String newQuery = getURIQuery(existingParams); res = uriPath + '?' + newQuery; } else { res = uriPath; } return res; } }
URIUtils { public static String addParametersToURIQuery(String uriString, Map<String, String> parameters) { if (uriString == null || parameters == null || parameters.isEmpty()) { return uriString; } String uriPath = getURIPath(uriString); Map<String, String> existingParams = getRequestParameters(uriString.substring(uriPath.length())); if (existingParams == null) { existingParams = new LinkedHashMap<>(); } existingParams.putAll(parameters); String res; if (!existingParams.isEmpty()) { String newQuery = getURIQuery(existingParams); res = uriPath + '?' + newQuery; } else { res = uriPath; } return res; } private  URIUtils(); }
URIUtils { public static String addParametersToURIQuery(String uriString, Map<String, String> parameters) { if (uriString == null || parameters == null || parameters.isEmpty()) { return uriString; } String uriPath = getURIPath(uriString); Map<String, String> existingParams = getRequestParameters(uriString.substring(uriPath.length())); if (existingParams == null) { existingParams = new LinkedHashMap<>(); } existingParams.putAll(parameters); String res; if (!existingParams.isEmpty()) { String newQuery = getURIQuery(existingParams); res = uriPath + '?' + newQuery; } else { res = uriPath; } return res; } private  URIUtils(); static String getURIQuery(Map<String, String> parameters); static String getURIPath(String uri); static Map<String, String> getRequestParameters(String uriQuery); static String addParametersToURIQuery(String uriString, Map<String, String> parameters); static String quoteURIPathComponent(String s, boolean quoteSlash); static String quoteURIPathComponent(String s, boolean quoteSlash, boolean quoteAt); static String quoteURIPathToken(String s); static String unquoteURIPathComponent(String s); }
URIUtils { public static String addParametersToURIQuery(String uriString, Map<String, String> parameters) { if (uriString == null || parameters == null || parameters.isEmpty()) { return uriString; } String uriPath = getURIPath(uriString); Map<String, String> existingParams = getRequestParameters(uriString.substring(uriPath.length())); if (existingParams == null) { existingParams = new LinkedHashMap<>(); } existingParams.putAll(parameters); String res; if (!existingParams.isEmpty()) { String newQuery = getURIQuery(existingParams); res = uriPath + '?' + newQuery; } else { res = uriPath; } return res; } private  URIUtils(); static String getURIQuery(Map<String, String> parameters); static String getURIPath(String uri); static Map<String, String> getRequestParameters(String uriQuery); static String addParametersToURIQuery(String uriString, Map<String, String> parameters); static String quoteURIPathComponent(String s, boolean quoteSlash); static String quoteURIPathComponent(String s, boolean quoteSlash, boolean quoteAt); static String quoteURIPathToken(String s); static String unquoteURIPathComponent(String s);  }