Search in sources :

Example 81 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class ItemManager method getDefinition.

NodeDefinitionImpl getDefinition(NodeState state) throws RepositoryException {
    if (state.getId().equals(sessionContext.getRootNodeId())) {
        // special handling required for root node
        return rootNodeDef;
    }
    NodeId parentId = state.getParentId();
    if (parentId == null) {
        // removed state has parentId set to null
        // get from overlayed state
        ItemState overlaid = state.getOverlayedState();
        if (overlaid != null) {
            parentId = overlaid.getParentId();
        } else {
            throw new InvalidItemStateException("Could not find parent of node " + state.getNodeId());
        }
    }
    NodeState parentState = null;
    try {
        // access the parent state circumventing permission check, since
        // read permission on the parent isn't required in order to retrieve
        // a node's definition. see also JCR-2418
        ItemData parentData = getItemData(parentId, null, false);
        parentState = (NodeState) parentData.getState();
        if (state.getParentId() == null) {
            // that used to be the actual parent
            if (parentState.getStatus() == ItemState.STATUS_NEW) {
                // force getting parent from attic
                parentState = null;
            } else {
                parentState = (NodeState) parentState.getOverlayedState();
            }
        }
    } catch (ItemNotFoundException e) {
    // parent probably removed, get it from attic. see below
    }
    if (parentState == null) {
        try {
            // use overlayed state if available
            parentState = (NodeState) sism.getAttic().getItemState(parentId).getOverlayedState();
        } catch (ItemStateException ex) {
            throw new RepositoryException(ex);
        }
    }
    // get child node entry
    ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
    if (cne == null) {
        throw new InvalidItemStateException("Could not find child " + state.getNodeId() + " of node " + parentState.getNodeId());
    }
    NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
    try {
        EffectiveNodeType ent = ntReg.getEffectiveNodeType(parentState.getNodeTypeName(), parentState.getMixinTypeNames());
        QNodeDefinition def;
        try {
            def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
        } catch (ConstraintViolationException e) {
            // fallback to child node definition of a nt:unstructured
            ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
            def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
            log.warn("Fallback to nt:unstructured due to unknown child " + "node definition for type '" + state.getNodeTypeName() + "'");
        }
        return sessionContext.getNodeTypeManager().getNodeDefinition(def);
    } catch (NodeTypeConflictException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeTypeConflictException(org.apache.jackrabbit.core.nodetype.NodeTypeConflictException) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 82 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class HierarchyManagerImpl method buildPath.

/**
     * Adds the path element of an item id to the path currently being built.
     * Recursively invoked method that may be overridden by some subclass to
     * either return cached responses or add response to cache. On exit,
     * <code>builder</code> contains the path of <code>state</code>.
     *
     * @param builder  builder currently being used
     * @param state    item to find path of
     * @param detector path cycle detector
     */
protected void buildPath(PathBuilder builder, ItemState state, CycleDetector detector) throws ItemStateException, RepositoryException {
    // shortcut
    if (state.getId().equals(rootNodeId)) {
        builder.addRoot();
        return;
    }
    NodeId parentId = getParentId(state);
    if (parentId == null) {
        String msg = "failed to build path of " + state.getId() + ": orphaned item";
        log.debug(msg);
        throw new ItemNotFoundException(msg);
    } else if (detector.checkCycle(parentId)) {
        throw new InvalidItemStateException("Path cycle detected: " + parentId);
    }
    NodeState parent = (NodeState) getItemState(parentId);
    // recursively build path of parent
    buildPath(builder, parent, detector);
    if (state.isNode()) {
        NodeState nodeState = (NodeState) state;
        NodeId id = nodeState.getNodeId();
        ChildNodeEntry entry = getChildNodeEntry(parent, id);
        if (entry == null) {
            String msg = "failed to build path of " + state.getId() + ": " + parent.getNodeId() + " has no child entry for " + id;
            log.debug(msg);
            throw new ItemNotFoundException(msg);
        }
        // add to path
        if (entry.getIndex() == 1) {
            builder.addLast(entry.getName());
        } else {
            builder.addLast(entry.getName(), entry.getIndex());
        }
    } else {
        PropertyState propState = (PropertyState) state;
        Name name = propState.getName();
        // add to path
        builder.addLast(name);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name)

Example 83 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class ItemManager method hasChildNodes.

/**
     * @param parentId
     * @return
     * @throws ItemNotFoundException
     * @throws AccessDeniedException
     * @throws RepositoryException
     */
synchronized boolean hasChildNodes(NodeId parentId) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
    sanityCheck();
    ItemData data = getItemData(parentId);
    if (!data.isNode()) {
        String msg = "can't list child nodes of property " + parentId;
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    NodeState state = (NodeState) data.getState();
    for (ChildNodeEntry entry : state.getChildNodeEntries()) {
        // make sure any of the properties can be read.
        if (canRead(data, entry.getId())) {
            return true;
        }
    }
    return false;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) RepositoryException(javax.jcr.RepositoryException)

Example 84 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class ItemManager method getDefinition.

PropertyDefinitionImpl getDefinition(PropertyState state) throws RepositoryException {
    // see also: JCR-2408
    if (state.getStatus() == ItemState.STATUS_EXISTING_REMOVED && state.getName().equals(NameConstants.JCR_UUID)) {
        NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
        QPropertyDefinition def = ntReg.getEffectiveNodeType(NameConstants.MIX_REFERENCEABLE).getApplicablePropertyDef(state.getName(), state.getType());
        return sessionContext.getNodeTypeManager().getPropertyDefinition(def);
    }
    try {
        // retrieve parent in 2 steps in order to avoid the check for
        // read permissions on the parent which isn't required in order
        // to read the property's definition. see also JCR-2418.
        ItemData parentData = getItemData(state.getParentId(), null, false);
        NodeImpl parent = (NodeImpl) createItemInstance(parentData);
        return parent.getApplicablePropertyDefinition(state.getName(), state.getType(), state.isMultiValued(), true);
    } catch (ItemNotFoundException e) {
    // parent probably removed, get it from attic
    }
    try {
        NodeState parent = (NodeState) sism.getAttic().getItemState(state.getParentId()).getOverlayedState();
        NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
        EffectiveNodeType ent = ntReg.getEffectiveNodeType(parent.getNodeTypeName(), parent.getMixinTypeNames());
        QPropertyDefinition def;
        try {
            def = ent.getApplicablePropertyDef(state.getName(), state.getType(), state.isMultiValued());
        } catch (ConstraintViolationException e) {
            ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
            def = ent.getApplicablePropertyDef(state.getName(), state.getType(), state.isMultiValued());
            log.warn("Fallback to nt:unstructured due to unknown property " + "definition for '" + state.getName() + "'");
        }
        return sessionContext.getNodeTypeManager().getPropertyDefinition(def);
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } catch (NodeTypeConflictException e) {
        throw new RepositoryException(e);
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.core.state.NodeState) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) NodeTypeConflictException(org.apache.jackrabbit.core.nodetype.NodeTypeConflictException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 85 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class BatchedItemOperations method removeNode.

/**
     * Removes the specified node, recursively removing its properties and
     * child nodes.
     * <p>
     * <b>Precondition:</b> the state manager needs to be in edit mode.
     *
     * @param nodePath
     * @throws ConstraintViolationException
     * @throws AccessDeniedException
     * @throws VersionException
     * @throws LockException
     * @throws ItemNotFoundException
     * @throws ReferentialIntegrityException
     * @throws RepositoryException
     * @throws IllegalStateException
     */
public void removeNode(Path nodePath) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ReferentialIntegrityException, RepositoryException, IllegalStateException {
    // check precondition
    if (!stateMgr.inEditMode()) {
        throw new IllegalStateException("cannot remove node (" + safeGetJCRPath(nodePath) + ") because manager is not in edit mode");
    }
    // 1. retrieve affected state
    NodeState target = getNodeState(nodePath);
    NodeId parentId = target.getParentId();
    // 2. check if target state can be removed from parent
    checkRemoveNode(target, parentId, CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_REFERENCES | CHECK_HOLD | CHECK_RETENTION);
    // 3. do remove operation
    removeNodeState(target);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId)

Aggregations

NodeState (org.apache.jackrabbit.core.state.NodeState)114 RepositoryException (javax.jcr.RepositoryException)53 NodeId (org.apache.jackrabbit.core.id.NodeId)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)44 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)34 Name (org.apache.jackrabbit.spi.Name)28 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)26 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 Path (org.apache.jackrabbit.spi.Path)24 PropertyId (org.apache.jackrabbit.core.id.PropertyId)23 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)16 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)16 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 ArrayList (java.util.ArrayList)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)12 InternalValue (org.apache.jackrabbit.core.value.InternalValue)12 HashSet (java.util.HashSet)10 ItemExistsException (javax.jcr.ItemExistsException)10 IOException (java.io.IOException)8 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)7