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(); }
@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)); } }
break; path = path.parent(); if (path.isRoot()) { break;