@Override public String toString() { return asString(); }
/** * checks, if this {@link URLPath} ends with a slash * * @return {@code true} if it contains a trailing slash, otherwise * {@code false} */ public boolean hasTrailingSlash() { if (isEmpty()) { return false; } return getSegment(size() - 1).isEmpty(); }
/** * gives a {@link URLPath} without a trailing slash * * @return a new created {@link URLPath}, which have all elements, without a * trailing slash */ public URLPath removeTrailingSlash() { if (!hasTrailingSlash()) { return this; } return getSubPath(0, size() - 1); }
/** * gives an {@link URLPath}, which contains all elements starting from the * given index. * * @param start of the first element (including) {@link URLPath} * @return the {@link URLPath} with the sub elements */ public URLPath getSubPath(int start) { return getSubPath(start, size()); }
@Override public String getEffectivePathInfo() { int start = 1; if (!isAuthenticationSchemeInServletPath()) { start = 2; } URLPath path = getPath().getSubPath(start); if (path.isEmpty()) { return ""; } return "/" + path.removeTrailingSlash().asString(); }
/** * Appends the given url path to this path. */ public URLPath append(URLPath toAppend) { if (toAppend == null || toAppend.isEmpty()) { return this; } if (this.isEmpty()) { return toAppend; } if (this.isRoot() && toAppend.isRoot()) { return ROOT; } ArrayList newParts = new ArrayList(removeTrailingSlash().segments); newParts.addAll(toAppend.segments); return new URLPath(newParts); }
public static String buildSubUrl(String url, String... subpaths) { URLPath urlPath = URLPath.fromString(subpaths); if (urlPath.isEmpty()) { return url; } String query = URLUtils.getQueryStringFromUrl(url); url = URLUtils.removeQueryStringFromUrl(url); if (!(url == null || url.isEmpty()) && !(url.endsWith("/"))) { url += "/"; } url += urlPath.asString(); url = URLUtils.appendQueryToUrl(url, query); return url; }
/** * gives an {@link URLPath}, which contains all elements in the given range. * * @param start index (including) * @param end index (excluding) * @return the {@link URLPath} with the sub elements */ public URLPath getSubPath(int start, int end) { List<String> parts = getSegments(); List<String> newSegments = parts.subList(start, end); URLPath newPath = new URLPath(newSegments); if (newPath.isEmpty()) { return EMPTY; } if (newPath.isRoot()) { return ROOT; } return newPath; }
@Override public String getEnforcementPointId() { URLPath path = getPath(); return path.isEmpty() ? "" : urlPath.getSegment(0); }
/** * gives a {@link URLPath} with a trailing slash * * @return a new created {@link URLPath}, which have all elements, with a * trailing slash */ public URLPath appendTrailingSlash() { if (hasTrailingSlash()) { return this; } return append(ROOT); }
WSSRequestUrl(String servletUrl, String servletPath, String pathInfo, WSSRequestUrlFactory factory) { m_servletUrl = servletUrl; m_servletPath = servletPath; urlPath = URLPath.fromString(pathInfo==null ? "" : pathInfo); setRequestUrlFactory(factory); }
/** * if this path represents a path root (single slash); */ public boolean isRoot() { return ROOT.equals(this); }
public String getAuthenticationScheme(WSSRequestUrl wssRequestUrl) { if (isAuthenticationSchemeInServletPath()) { int nextslash = wssRequestUrl.getServletPath().indexOf("/", 1); return wssRequestUrl.getServletPath().substring(1, nextslash > -1 ? nextslash : wssRequestUrl.getServletPath().length()); } else { return wssRequestUrl.getPath().getSegmentOrEmptyString(1); } } }
/** * checks, if this {@link URLPath} have no elements * * @return {@code true} if this {@link URLPath} have no elements, otherwise * {@code false} */ public boolean isEmpty() { return EMPTY.equals(this); }