]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.util/src/org/argeo/util/http/HttpServerUtils.java
Improve ACR, introduce migration from JCR.
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / http / HttpServerUtils.java
1 package org.argeo.util.http;
2
3 import java.net.URI;
4 import java.util.Objects;
5
6 import com.sun.net.httpserver.HttpContext;
7 import com.sun.net.httpserver.HttpExchange;
8
9 public class HttpServerUtils {
10
11 public static String relativize(HttpContext httpContext, String path) {
12 Objects.requireNonNull(path);
13 if (!path.startsWith(httpContext.getPath()))
14 throw new IllegalArgumentException(path + " does not belong to context" + httpContext.getPath());
15 String relativePath = path.substring(httpContext.getPath().length());
16 // TODO optimise?
17 if (relativePath.startsWith("/"))
18 relativePath = relativePath.substring(1);
19 return relativePath;
20 }
21
22 public static String relativize(HttpExchange exchange) {
23 URI uri = exchange.getRequestURI();
24 HttpContext httpContext = exchange.getHttpContext();
25 return relativize(httpContext, uri.getPath());
26 }
27
28 /** singleton */
29 private HttpServerUtils() {
30
31 }
32 }