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(); }
public Path(String path, boolean canonize) { if (path == null || path.length() == 0) { throw new IllegalArgumentException("Argument 'path' cannot be null or empty"); } if (canonize) { path = new Path(path, false).canonical().path; } if (!path.equals("/") && path.endsWith(SEPARATOR)) { this.path = path.substring(0, path.length() - 1); } else { this.path = path; } }
public Path canonical() { if (isCanonical()) { return this; } else { return doCanonical(); } }
public Path toAbsolute() { if (!isAbsolute()) { return ROOT.append(this); } else { return this; } }
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 JcrNode nodeForPath(BrixNode baseNode, String path) { Path realPath = new Path(SitePlugin.get().toRealWebNodePath(path)); if (realPath.isAbsolute() == false) { Path base = new Path(baseNode.getPath()); if (!baseNode.isFolder()) { base = base.parent(); } realPath = base.append(realPath); } String strPath = realPath.toString(); if (baseNode.getSession().itemExists(strPath) == false) { return null; } else { return ((JcrNode) baseNode.getSession().getItem(strPath)); } }
private String getCommonParentPath(List<JcrNode> nodes) { Path current = null; String sitePath = SitePlugin.get().getSiteRootPath(); for (JcrNode node : nodes) { if (node.getPath().startsWith(sitePath) && node instanceof GlobalContainerNode == false) { if (current == null) { current = new Path(node.getPath()).parent(); } else { Path another = new Path(node.getPath()).parent(); Path common = Path.ROOT; Iterator<String> i1 = current.iterator(); Iterator<String> i2 = another.iterator(); while (i1.hasNext() && i2.hasNext()) { String s1 = i1.next(); String s2 = i2.next(); if (Objects.equal(s1, s2)) { common = common.append(new Path(s1)); } else { break; } } current = common; } } } if (current == null) { current = Path.ROOT; } return current.toString(); }
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; } }
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; }
private void createFolder() { final JcrNode parent = (JcrNode) getModelObject(); final Path path = new Path(parent.getPath()); final Path newPath = path.append(new Path(name)); final JcrSession session = parent.getSession(); if (session.itemExists(newPath.toString())) { class ModelObject implements Serializable { @SuppressWarnings("unused") public String path = SitePlugin.get().fromRealWebNodePath(newPath.toString()); } ; String error = getString("resourceExists", new Model<ModelObject>(new ModelObject())); error(error); } else { FolderNode node = (FolderNode) parent.addNode(name, "nt:folder"); parent.save(); SitePlugin.get().selectNode(this, node, true); } } }
/** * {@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 Path subpath(int idx) { if (idx <= 0) { throw new IndexOutOfBoundsException(); } final int size = size(); final boolean abs = isAbsolute(); int chunks = (abs) ? size + 1 : size; if (idx > chunks) { throw new IndexOutOfBoundsException(); } if (idx == chunks) { // shortcut in case we want the entire path return this; } int iterations = ((abs) ? idx - 1 : idx); int end = 1; for (int i = 0; i < iterations; i++) { end = path.indexOf(SEPARATOR, end + 1); } if (end == 0) { return new Path("/"); } String newPath = path.substring(0, end); return new Path(newPath); }
builder.append(urlEncodePath(new Path(nodeURL, false)));
public Path append(Path relative) { if (relative == null) { throw new IllegalArgumentException("Argument 'relative' cannot be null"); } if (relative.isAbsolute()) { throw new IllegalArgumentException("Cannot append an absolute path"); } StringBuilder appended = new StringBuilder(path.length() + 1 + relative.path.length()); appended.append(path); if (!path.endsWith(SEPARATOR)) { appended.append("/"); } appended.append(relative.path); return new Path(appended.toString()); }
public JcrNode nodeForPath(BrixNode baseNode, Path path) { return nodeForPath(baseNode, path.toString()); }
@Override public void afterWorkspaceMove(String srcAbsPath, String destAbsPath) throws RepositoryException { String n1 = new Path(srcAbsPath).getName().toLowerCase(); // check if the item had extension before renaming. This is used to handle special case // when coda creates // "Untitled file" node that is later renamed to real file name if (n1.lastIndexOf('.') > n1.lastIndexOf('/')) { // it had, this is probably not a new file return; } handleNewNode(destAbsPath, null, brix.wrapSession(session), true); } }
final Path nodePath = brix.getConfig().getMapper().getNodePathForUriPath(uriPath.toAbsolute(), brix); final String jcrPath = SitePlugin.get().toRealWebNodePath(nodePath.toString());
public boolean isDescendantOf(Path other) { if (other.isRoot()) { if (isRoot()) { return false; } else if (isAbsolute()) { return true; } else { return false; } } else { return path.startsWith(other.path + SEPARATOR) && path.length() > other.path.length(); } }