public Path toAbsolute() { if (!isAbsolute()) { return ROOT.append(this); } else { return this; } }
/** * {@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; }
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 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 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); } } }
@SuppressWarnings("unchecked") public void validate(IValidatable validatable) { Object o = validatable.getValue(); if (o != null) { JcrNode node = nodeModel.getObject(); Path path = null; if (o instanceof Path) { path = (Path) o; } else { path = new Path(o.toString()); } if (!path.isAbsolute()) { Path parent = new Path(node.getPath()); if (!((BrixNode) node).isFolder()) parent = parent.parent(); path = parent.append(path); } else { path = new Path(SitePlugin.get().toRealWebNodePath(path.toString())); } if (node.getSession().itemExists(path.toString()) == false) { ValidationError error = new ValidationError(); error.setMessage("Node ${path} could not be found"); error.addKey("NodePathValidator"); error.getVariables().put("path", path.toString()); validatable.error(error); } } } }
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)); } }