All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jupiter.tools.mvc.requester.url.UriBuilder Maven / Gradle / Ivy

The newest version!
package com.jupiter.tools.mvc.requester.url;

import java.net.URI;

import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

/**
 * Created on 07/04/2020
 * 

* * @author Korovin Anatoliy */ public class UriBuilder { public URI build(String pattern, Object[] args) { String urlPattern = pattern.trim(); URI uri = internalBuildUri(urlPattern, args); return startFromDash(uri) ? uri : internalBuildUri('/' + urlPattern, args); } private URI internalBuildUri(String url, Object[] args) { UriComponents components = (args != null) ? UriComponentsBuilder.fromUriString(url).buildAndExpand(args) : UriComponentsBuilder.fromUriString(url).build(); return components.encode().toUri(); } private boolean startFromDash(URI uri) { return uri.toString().charAt(0) == '/'; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy