@Override public boolean matches(@Nonnull String path) { return (PathUtils.denotesRoot(path) ? false : names.contains(PathUtils.getName(path))); }
private String getPathPrefix(String indexPath) { // 2 = /oak:index/<index name> String parentPath = PathUtils.getAncestorPath(indexPath, 2); return PathUtils.denotesRoot(parentPath) ? "" : parentPath; }
private static String getPathWithMaxDepth(String path, int maxDepth){ int depth = PathUtils.getDepth(path); if (depth <= maxDepth){ return path; } return PathUtils.getAncestorPath(path, depth - maxDepth); }
public PropertyInclude(PropertyDefinition pd) { super(getParentPath(pd.name)); this.propertyDefinition = pd; this.propertyName = PathUtils.getName(pd.name); this.parentPath = getParentPath(pd.name); if (pd.isRegexp) { pattern = Pattern.compile(propertyName); } else { pattern = null; } }
/** * Get the parent of a path. The parent of the root path ("/") is the root * path. * * @param path the path * @return the parent path */ @Nonnull public static String getParentPath(String path) { return getAncestorPath(path, 1); }
@Nonnull @Override public ImmutableTree getTree(@Nonnull String path) { checkArgument(PathUtils.isAbsolute(path)); ImmutableTree child = rootTree; for (String name : elements(path)) { child = child.getChild(name); } return child; }
@Nonnull private String getOakPathOrThrow(@Nonnull String absPath) throws RepositoryException { String p = sessionContext.getOakPathOrThrow(absPath); if (!PathUtils.isAbsolute(p)) { throw new RepositoryException("Not an absolute path: " + absPath); } return p; }
private static void checkNotPath(NodeBuilder node, String key, String path) { path = PathUtils.concat(key, path); String parentPath = PathUtils.getParentPath(path); String name = PathUtils.getName(path); NodeBuilder check = node; for (String p : PathUtils.elements(parentPath)) { Assert.assertTrue("Missing child node " + p + " on path " + path, check.hasChildNode(p)); check = check.child(p); } Assert.assertFalse(check.hasChildNode(name)); }
@NotNull @Override public ImmutableTree getTree(@NotNull String path) { checkArgument(PathUtils.isAbsolute(path)); ImmutableTree child = rootTree; for (String name : elements(path)) { child = child.getChild(name); } return child; }
private Diff(@NotNull Diff parentDiff, @NotNull String name, @Nullable NodeState before, @Nullable NodeBuilder after) { this.parentDiff = parentDiff; isRoot = false; path = PathUtils.concat(parentDiff.path, name); this.beforeState = before; afterBuilder = after; afterHoldsCug = CugUtil.hasCug(after); }
@NotNull private static NodeState getNode(@NotNull NodeState root, @NotNull String path) { NodeState node = root; for (String name : elements(path)) { node = node.getChildNode(name); } return node; }
private static PropertyState getValue(NodeState node, String propertyRelativePath) { int depth = PathUtils.getDepth(propertyRelativePath); NodeState propNode = node; String propName = propertyRelativePath; if (depth > 1) { propName = PathUtils.getName(propertyRelativePath); String parentPath = PathUtils.getParentPath(propertyRelativePath); propNode = NodeStateUtils.getNode(node, parentPath); } return propNode.getProperty(propName); } }
private void markChanged(String path) { if (!PathUtils.denotesRoot(path) && !PathUtils.isAbsolute(path)) { throw new IllegalArgumentException("path: " + path); } while (true) { changedNodes.add(path); if (PathUtils.denotesRoot(path)) { break; } path = PathUtils.getParentPath(path); } }
@Override public boolean evaluate() { String p = parentSelector.currentPath(); String c = childSelector.currentPath(); // the parent of the root is the root, // so we need to special case this return !PathUtils.denotesRoot(c) && PathUtils.getParentPath(c).equals(p); }
private Set<String> unprecisePaths(Set<String> paths, int level) { Set<String> result = new HashSet<String>(); for (String path : paths) { String unprecise = path; while(PathUtils.getDepth(unprecise) > level) { unprecise = PathUtils.getParentPath(unprecise); } result.add(unprecise); } return result; }
static String getSafePropName(String relativePropName) { String propName = PathUtils.getName(relativePropName); int indexOfColon = propName.indexOf(':'); if (indexOfColon > 0){ propName = propName.substring(indexOfColon + 1); } //Just keep ascii chars propName = propName.replaceAll("\\W", ""); return propName; } }