Package org.apache.jackrabbit.oak.api

Examples of org.apache.jackrabbit.oak.api.TreeLocation


*/
public class LocationUtil {

    @Nonnull
    public static TreeLocation getTreeLocation(TreeLocation parentLocation, String relativePath) {
        TreeLocation targetLocation = parentLocation;
        String[] segments = Text.explode(relativePath, '/', false);
        for (int i = 0; i < segments.length && targetLocation != TreeLocation.NULL; i++) {
            String segment = segments[i];
            if (PathUtils.denotesCurrent(segment)) {
                continue;
            } else if (PathUtils.denotesParent(segment)) {
                targetLocation = targetLocation.getParent();
            } else {
                targetLocation = targetLocation.getChild(segment);
            }
        }
        return targetLocation;
    }
View Full Code Here


     * @return  property at the path given by {@code relPath} or {@code null} if
     * no such property exists
     */
    @CheckForNull
    public PropertyDelegate getProperty(String relPath) throws RepositoryException {
        TreeLocation propertyLocation = getChildLocation(relPath);
        PropertyState propertyState = propertyLocation.getProperty();
        return propertyState == null
                ? null
                : new PropertyDelegate(sessionDelegate, propertyLocation);
    }
View Full Code Here

    private TreeLocation getChildLocation(String relPath) throws RepositoryException {
        if (PathUtils.isAbsolute(relPath)) {
            throw new RepositoryException("Not a relative path: " + relPath);
        }

        TreeLocation loc = getLocation();
        for (String element : PathUtils.elements(relPath)) {
            if (PathUtils.denotesParent(element)) {
                loc = loc.getParent();
            } else if (!PathUtils.denotesCurrent(element)) {
                loc = loc.getChild(element);
            // else . -> skip to next element
        }
        return loc;
    }
View Full Code Here

                });
    }

    private Iterator<PropertyDelegate> propertyDelegateIterator(
            Iterator<? extends PropertyState> properties) throws InvalidItemStateException {
        final TreeLocation location = getLocation();
        return Iterators.transform(
                Iterators.filter(properties, new Predicate<PropertyState>() {
                    @Override
                    public boolean apply(PropertyState property) {
                        return !property.getName().startsWith(":");
                    }
                }),
                new Function<PropertyState, PropertyDelegate>() {
                    @Override
                    public PropertyDelegate apply(PropertyState propertyState) {
                        return new PropertyDelegate(sessionDelegate, location.getChild(propertyState.getName()));
                    }
                });
    }
View Full Code Here

    @Nonnull
    public NodeUtil getOrAddTree(String relativePath, String primaryTypeName) {
        if (relativePath.indexOf('/') == -1) {
            return getOrAddChild(relativePath, primaryTypeName);
        } else {
            TreeLocation location = LocationUtil.getTreeLocation(tree.getLocation(), relativePath);
            if (location.getTree() == null) {
                NodeUtil target = this;
                for (String segment : Text.explode(relativePath, '/')) {
                    if (PathUtils.denotesParent(segment)) {
                        target = target.getParent();
                    } else if (target.hasChild(segment)) {
                        target = target.getChild(segment);
                    } else if (!PathUtils.denotesCurrent(segment)) {
                        target = target.addChild(segment, primaryTypeName);
                    }
                }
                return target;
            } else {
                return new NodeUtil(location.getTree());
            }
        }
    }
View Full Code Here

     * @param path Oak path
     * @return  The {@code PropertyDelegate} at {@code path} or {@code null} if
     * none exists or not accessible.
     */
    public PropertyDelegate getProperty(String path) {
        TreeLocation location = root.getLocation(path);
        return location.getProperty() == null
            ? null
            : new PropertyDelegate(this, location);
    }
View Full Code Here

        } else {
            return dlg.perform(new SessionOperation<PropertyImpl>() {
                @Override
                public PropertyImpl perform() throws RepositoryException {
                    String oakPath = dlg.getOakPathOrThrowNotFound(absPath);
                    TreeLocation loc = dlg.getLocation(oakPath);
                    if (loc.getProperty() == null) {
                        throw new PathNotFoundException(absPath);
                    }
                    else {
                        return new PropertyImpl(new PropertyDelegate(dlg, loc));
                    }
View Full Code Here

        } else {
            return dlg.perform(new SessionOperation<Boolean>() {
                @Override
                public Boolean perform() throws RepositoryException {
                    String oakPath = dlg.getOakPathOrThrowNotFound(absPath);
                    TreeLocation loc = dlg.getLocation(oakPath);
                    return loc.getProperty() != null;
                }
            });
        }
    }
View Full Code Here

     * @return  tree location of the underlying item
     * @throws InvalidItemStateException if the location points to a stale item
     */
    @Nonnull
    public TreeLocation getLocation() throws InvalidItemStateException {
        TreeLocation location = getLocationOrNull();
        if (location == TreeLocation.NULL) {
            throw new InvalidItemStateException("Item is stale");
        }
        return location;
    }
View Full Code Here

        }
        if (!isVersionable(versionable)) {
            throw new UnsupportedRepositoryOperationException(
                    versionable.getPath() + " is not versionable");
        }
        TreeLocation location = versionable.getLocation();
        if (isCheckedOut(location)) {
            versionable.setProperty(VersionConstants.JCR_ISCHECKEDOUT,
                    Boolean.FALSE, Type.BOOLEAN);
            try {
                getWorkspaceRoot().commit();
                refresh();
            } catch (CommitFailedException e) {
                getWorkspaceRoot().refresh();
                throw new RepositoryException(e);
            }
        }
        return getBaseVersion(getWorkspaceRoot().getTree(location.getPath()));
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.api.TreeLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.