public String rewriteStaticRelativeUrl(String url, String contextPrefix) { if (prefix.isRoot()) { return contextPrefix + url; } else { return contextPrefix + prefix.toRelative(Path.ROOT) + "/" + url; } } }
public Path toRelative(Path ancestor) { if (isRoot()) { throw new IllegalStateException("Cannot make root path relative"); } if (!isDescendantOf(ancestor)) { throw new IllegalArgumentException("Cannot create relative path because this path: " + this + " is not descendant of ancestor argument: " + ancestor); } Path fragment = new Path(path.substring(ancestor.path.length()), false); if (fragment.isAbsolute()) { fragment = fragment.toRelative(new Path("/")); } return fragment; } }
/** * {@inheritDoc} */ public Path getUriPathForNode(Path nodePath, Brix brix) { Path uriPath = prefix; if (!nodePath.isRoot()) { // nodePath is not root, we have to append it to prefix uriPath = prefix.append(nodePath.toRelative(Path.ROOT)); } if(nodePath.toString().endsWith(SitePlugin.BRIX_INDEX_PAGE)) { final String orgUrl = nodePath.toString(); String url = orgUrl.substring(0, orgUrl.length() - SitePlugin.BRIX_INDEX_PAGE.length()); uriPath = new Path(url); } return uriPath; }
/** * {@inheritDoc} */ public Path getNodePathForUriPath(Path uriPath, Brix brix) { if (prefix.isAncestorOf(uriPath)) { // strip prefix from path return uriPath.toRelative(prefix).toAbsolute(); } else if (prefix.equals(uriPath)) { // path is same as prefix, which equates to root return Path.ROOT; } else { return null; } }
public String toRealWebNodePath(String nodePath) { Path prefix = new Path(getSiteRootPath()); Path path = new Path(nodePath); if (path.isRoot()) { path = new Path("."); } else if (path.isAbsolute()) { path = path.toRelative(new Path("/")); } return prefix.append(path).toString(); }
public String fromRealWebNodePath(String nodePath) { Path prefix = new Path(getSiteRootPath()); Path path = new Path(nodePath); if (path.equals(prefix)) { path = new Path("/"); } else if (path.isDescendantOf(prefix)) { path = path.toRelative(prefix); } if (!path.isAbsolute()) { path = new Path("/").append(path); } return path.toString(); }
private BrixPageParameters createBrixPageParams(Url url, Path path) { BrixPageParameters parameters = new BrixPageParameters(); Path nodePath = path; Path requestPath = new Path("/" + url.getPath()); if (nodePath.isAncestorOf(requestPath)) { Path remaining = new Path(requestPath.toString(), false).toRelative(nodePath); int i = 0; for (String s : remaining) { parameters.set(i, urlDecode(s)); ++i; } } for (QueryParameter parameter : url.getQueryParameters()) { String parameterName = parameter.getName(); if (PageComponentInfo.parse(parameterName) == null) { parameters.add(parameterName, parameter.getValue()); } } return parameters; }