org.webpieces.webserver.impl.RouterLookupProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-webserver Show documentation
Show all versions of http-webserver Show documentation
The full webpieces server AS A library
package org.webpieces.webserver.impl;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.webpieces.router.api.RouterService;
import org.webpieces.router.impl.compression.FileMeta;
import org.webpieces.templating.api.RouterLookup;
import org.webpieces.util.net.URLEncoder;
@Singleton
public class RouterLookupProxy implements RouterLookup {
private RouterService router;
@Inject
public RouterLookupProxy(RouterService router) {
this.router = router;
}
@Override
public String fetchUrl(String routeId, Map args) {
return router.convertToUrl(routeId, args, false );
}
@Override
public String pathToUrlEncodedHash(String relativeUrlPath) {
FileMeta hashMeta = router.relativeUrlToHash(relativeUrlPath);
if(hashMeta == null || hashMeta.getHash() == null)
return null;
return URLEncoder.encode(hashMeta.getHash(), StandardCharsets.UTF_8);
}
}