Package org.apache.jackrabbit.name

Examples of org.apache.jackrabbit.name.Path$RootElement


        // check sanity of this session
        sanityCheck();

        // check paths & get node instances

        Path srcPath;
        Path.PathElement srcName;
        Path srcParentPath;
        NodeImpl targetNode;
        NodeImpl srcParentNode;
        try {
            srcPath = PathFormat.parse(srcAbsPath, getNamespaceResolver()).getNormalizedPath();
            if (!srcPath.isAbsolute()) {
                throw new RepositoryException("not an absolute path: " + srcAbsPath);
            }
            srcName = srcPath.getNameElement();
            srcParentPath = srcPath.getAncestor(1);
            ItemImpl item = getItemManager().getItem(srcPath);
            if (!item.isNode()) {
                throw new PathNotFoundException(srcAbsPath);
            }
            targetNode = (NodeImpl) item;
            srcParentNode = (NodeImpl) getItemManager().getItem(srcParentPath);
        } catch (AccessDeniedException ade) {
            throw new PathNotFoundException(srcAbsPath);
        } catch (MalformedPathException mpe) {
            String msg = srcAbsPath + ": invalid path";
            log.debug(msg);
            throw new RepositoryException(msg, mpe);
        }

        Path destPath;
        Path.PathElement destName;
        Path destParentPath;
        NodeImpl destParentNode;
        try {
            destPath = PathFormat.parse(destAbsPath, getNamespaceResolver()).getNormalizedPath();
            if (!destPath.isAbsolute()) {
                throw new RepositoryException("not an absolute path: " + destAbsPath);
View Full Code Here


        // check sanity of this session
        sanityCheck();

        Item item;
        try {
            Path p = PathFormat.parse(parentAbsPath, getNamespaceResolver()).getNormalizedPath();
            if (!p.isAbsolute()) {
                throw new RepositoryException("not an absolute path: " + parentAbsPath);
            }
            item = getItemManager().getItem(p);
        } catch (MalformedPathException mpe) {
            String msg = parentAbsPath + ": invalid path";
View Full Code Here

                            oldParent = (NodeState) stateMgr.getItemState(oldParentId);
                        }

                        NodeTypeImpl oldParentNodeType = getNodeType(oldParent, session);
                        Set mixins = oldParent.getMixinTypeNames();
                        Path newPath = getPath(n.getNodeId(), hmgr);
                        Path oldPath = getZombiePath(n.getNodeId(), hmgr);
                        if (!oldPath.equals(newPath)) {
                            events.add(EventState.childNodeRemoved(oldParentId,
                                    getParent(oldPath),
                                    n.getNodeId(),
                                    oldPath.getNameElement(),
                                    oldParentNodeType.getQName(),
                                    mixins,
                                    session));

                            NodeState newParent = (NodeState) changes.get(newParentId);
                            NodeTypeImpl newParentNodeType = getNodeType(newParent, session);
                            mixins = newParent.getMixinTypeNames();
                            events.add(EventState.childNodeAdded(newParentId,
                                    getParent(newPath),
                                    n.getNodeId(),
                                    newPath.getNameElement(),
                                    newParentNodeType.getQName(),
                                    mixins,
                                    session));
                        } else {
                            log.error("Unable to calculate old path of moved node");
                        }
                    } else {
                        // a moved node always has a modified parent node
                        NodeState parent = null;
                        try {
                            // root node does not have a parent UUID
                            if (state.getParentId() != null) {
                                parent = (NodeState) changes.get(state.getParentId());
                            }
                        } catch (NoSuchItemStateException e) {
                            // should never happen actually. this would mean
                            // the parent of this modified node is deleted
                            String msg = "Parent of node " + state.getId() + " is deleted.";
                            log.error(msg);
                            throw new ItemStateException(msg, e);
                        }
                        if (parent != null) {
                            // check if node has been renamed
                            NodeState.ChildNodeEntry moved = null;
                            for (Iterator removedNodes = parent.getRemovedChildNodeEntries().iterator(); removedNodes.hasNext();) {
                                NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry) removedNodes.next();
                                if (child.getId().equals(n.getNodeId())) {
                                    // found node re-added with different name
                                    moved = child;
                                }
                            }
                            if (moved != null) {
                                NodeTypeImpl nodeType = getNodeType(parent, session);
                                Set mixins = parent.getMixinTypeNames();
                                Path newPath = getPath(state.getId(), hmgr);
                                Path parentPath = getParent(newPath);
                                Path oldPath;
                                try {
                                    if (moved.getIndex() == 0) {
                                        oldPath = Path.create(parentPath, moved.getName(), false);
                                    } else {
                                        oldPath = Path.create(parentPath, moved.getName(), moved.getIndex(), false);
                                    }
                                } catch (MalformedPathException e) {
                                    // should never happen actually
                                    String msg = "Malformed path for item: " + state.getId();
                                    log.error(msg);
                                    throw new ItemStateException(msg, e);
                                }
                                events.add(EventState.childNodeRemoved(parent.getNodeId(),
                                        parentPath,
                                        n.getNodeId(),
                                        oldPath.getNameElement(),
                                        nodeType.getQName(),
                                        mixins,
                                        session));
                                events.add(EventState.childNodeAdded(parent.getNodeId(),
                                        parentPath,
                                        n.getNodeId(),
                                        newPath.getNameElement(),
                                        nodeType.getQName(),
                                        mixins,
                                        session));
                            }
                        }
                    }
                }

                // check if child nodes of modified node state have been reordered
                List reordered = n.getReorderedChildNodeEntries();
                NodeTypeImpl nodeType = getNodeType(n, session);
                Set mixins = n.getMixinTypeNames();
                if (reordered.size() > 0) {
                    // create a node removed and a node added event for every
                    // reorder
                    for (Iterator ro = reordered.iterator(); ro.hasNext();) {
                        NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry) ro.next();
                        QName name = child.getName();
                        int index = (child.getIndex() != 1) ? child.getIndex() : 0;
                        Path parentPath = getPath(n.getNodeId(), hmgr);
                        Path.PathElement addedElem = Path.create(name, index).getNameElement();
                        // get removed index
                        NodeState overlayed = (NodeState) n.getOverlayedState();
                        NodeState.ChildNodeEntry entry = overlayed.getChildNodeEntry(child.getId());
                        if (entry == null) {
                            throw new ItemStateException("Unable to retrieve old child index for item: " + child.getId());
                        }
                        int oldIndex = (entry.getIndex() != 1) ? entry.getIndex() : 0;
                        Path.PathElement removedElem = Path.create(name, oldIndex).getNameElement();

                        events.add(EventState.childNodeRemoved(n.getNodeId(),
                                parentPath,
                                child.getId(),
                                removedElem,
                                nodeType.getQName(),
                                mixins,
                                session));

                        events.add(EventState.childNodeAdded(n.getNodeId(),
                                parentPath,
                                child.getId(),
                                addedElem,
                                nodeType.getQName(),
                                mixins,
                                session));
                    }
                }
            } else {
                // property changed
                Path path = getPath(state.getId(), hmgr);
                NodeState parent = (NodeState) stateMgr.getItemState(state.getParentId());
                NodeTypeImpl nodeType = getNodeType(parent, session);
                Set mixins = parent.getMixinTypeNames();
                events.add(EventState.propertyChanged(state.getParentId(),
                        getParent(path),
                        path.getNameElement(),
                        nodeType.getQName(),
                        mixins,
                        session));
            }
        }

        // 2. removed items

        for (Iterator it = changes.deletedStates(); it.hasNext();) {
            ItemState state = (ItemState) it.next();
            if (state.isNode()) {
                // node deleted
                NodeState n = (NodeState) state;
                NodeState parent = (NodeState) stateMgr.getItemState(n.getParentId());
                NodeTypeImpl nodeType = getNodeType(parent, session);
                Set mixins = parent.getMixinTypeNames();
                Path path = getZombiePath(state.getId(), hmgr);
                events.add(EventState.childNodeRemoved(n.getParentId(),
                        getParent(path),
                        n.getNodeId(),
                        path.getNameElement(),
                        nodeType.getQName(),
                        mixins,
                        session));
            } else {
                // property removed
                // only create an event if node still exists
                try {
                    NodeState n = (NodeState) changes.get(state.getParentId());
                    // node state exists -> only property removed
                    NodeTypeImpl nodeType = getNodeType(n, session);
                    Set mixins = n.getMixinTypeNames();
                    Path path = getZombiePath(state.getId(), hmgr);
                    events.add(EventState.propertyRemoved(state.getParentId(),
                            getParent(path),
                            path.getNameElement(),
                            nodeType.getQName(),
                            mixins,
                            session));
                } catch (NoSuchItemStateException e) {
                    // node removed as well -> do not create an event
                }
            }
        }

        // 3. added items

        for (Iterator it = changes.addedStates(); it.hasNext();) {
            ItemState state = (ItemState) it.next();
            if (state.isNode()) {
                // node created
                NodeState n = (NodeState) state;
                NodeId parentId = n.getParentId();
                NodeState parent;
                // unknown if parent node is also new
                if (stateMgr.hasItemState(parentId)) {
                    parent = (NodeState) stateMgr.getItemState(parentId);
                } else {
                    parent = (NodeState) changes.get(parentId);
                }
                NodeTypeImpl nodeType = getNodeType(parent, session);
                Set mixins = parent.getMixinTypeNames();
                Path path = getPath(n.getNodeId(), hmgr);
                events.add(EventState.childNodeAdded(parentId,
                        getParent(path),
                        n.getNodeId(),
                        path.getNameElement(),
                        nodeType.getQName(),
                        mixins,
                        session));
            } else {
                // property created / set
                NodeState n = (NodeState) changes.get(state.getParentId());
                NodeTypeImpl nodeType = getNodeType(n, session);
                Set mixins = n.getMixinTypeNames();
                Path path = getPath(state.getId(), hmgr);
                events.add(EventState.propertyAdded(state.getParentId(),
                        getParent(path),
                        path.getNameElement(),
                        nodeType.getQName(),
                        mixins,
                        session));
            }
        }
View Full Code Here

                }
            }
            /**
             * build and resolve absolute path
             */
            Path p = PathFormat.parse(getPrimaryPath(), relPath,
                    session.getNamespaceResolver()).getCanonicalPath();
            ItemId id = session.getHierarchyManager().resolvePath(p);
            if (id == null) {
                // path not found
                return null;
View Full Code Here

        try {
            /**
             * first check if relPath is just a name (in which case we don't
             * have to build & resolve absolute path)
             */
            Path p = PathFormat.parse(relPath, session.getNamespaceResolver());
            if (p.getLength() == 1) {
                Path.PathElement pe = p.getNameElement();
                if (pe.denotesName()) {
                    // check if node entry exists
                    NodeState thisState = (NodeState) state;
                    int index = pe.getIndex();
                    if (index == 0) {
View Full Code Here

    protected NodeImpl internalAddNode(String relPath, NodeTypeImpl nodeType,
                                       NodeId id)
            throws ItemExistsException, PathNotFoundException, VersionException,
            ConstraintViolationException, LockException, RepositoryException {
        Path nodePath;
        QName nodeName;
        Path parentPath;
        try {
            nodePath =
                    PathFormat.parse(getPrimaryPath(), relPath,
                            session.getNamespaceResolver()).getCanonicalPath();
            if (nodePath.getNameElement().getIndex() != 0) {
View Full Code Here

    protected NodeImpl internalAddChildNode(QName nodeName,
                                            NodeTypeImpl nodeType, NodeId id)
            throws ItemExistsException, ConstraintViolationException,
            RepositoryException {
        Path nodePath;
        try {
            nodePath = Path.create(getPrimaryPath(), nodeName, true);
        } catch (MalformedPathException e) {
            // should never happen
            String msg = "internal error: invalid path " + safeGetJCRPath();
View Full Code Here

            ConstraintViolationException, ItemNotFoundException, LockException,
            RepositoryException {

        Path.PathElement insertName;
        try {
            Path p = PathFormat.parse(srcName, session.getNamespaceResolver());
            // p must be a relative path of length==depth==1 (to eliminate e.g. "..")
            if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) {
                throw new RepositoryException("invalid name: " + srcName);
            }
            insertName = p.getNameElement();
        } catch (MalformedPathException e) {
            String msg = "invalid name: " + srcName;
            log.debug(msg);
            throw new RepositoryException(msg, e);
        }

        Path.PathElement beforeName;
        if (destName != null) {
            try {
                Path p = PathFormat.parse(destName, session.getNamespaceResolver());
                // p must be a relative path of length==depth==1 (to eliminate e.g. "..")
                if (p.isAbsolute() || p.getLength() != 1 || p.getDepth() != 1) {
                    throw new RepositoryException("invalid name: " + destName);
                }
                beforeName = p.getNameElement();
            } catch (MalformedPathException e) {
                String msg = "invalid name: " + destName;
                log.debug(msg);
                throw new RepositoryException(msg, e);
            }
View Full Code Here

                return m2.getPath();
            }

            String relPath;
            try {
                Path p = m1.getPrimaryPath().computeRelativePath(getPrimaryPath());
                // use prefix mappings of srcSession
                relPath = PathFormat.format(p, srcSession.getNamespaceResolver());
            } catch (NameException be) {
                // should never get here...
                String msg = "internal error: failed to determine relative path";
View Full Code Here

                // check if versionable node exists
                InternalFrozenNode fn = ((VersionImpl) version).getFrozenNode();
                node = (NodeImpl) session.getNodeByUUID(fn.getFrozenUUID());
                if (removeExisting) {
                    try {
                        Path dstPath = PathFormat.parse(getPrimaryPath(),
                                relPath, session.getNamespaceResolver()).getCanonicalPath();
                        // move to respective location
                        session.move(node.getPath(), PathFormat.format(dstPath, session.getNamespaceResolver()));
                        // need to refetch ?
                        node = (NodeImpl) session.getNodeByUUID(fn.getFrozenUUID());
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.name.Path$RootElement

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.