Search in sources :

Example 6 with NodeTypeImpl

use of org.apache.jackrabbit.core.nodetype.NodeTypeImpl in project jackrabbit by apache.

the class ProtectedItemModifier method addNode.

protected NodeImpl addNode(NodeImpl parentImpl, Name name, Name ntName, NodeId nodeId) throws RepositoryException {
    checkPermission(parentImpl, name, getPermission(true, false));
    // validation: make sure Node is not locked or checked-in.
    parentImpl.checkSetProperty();
    NodeTypeImpl nodeType = parentImpl.sessionContext.getNodeTypeManager().getNodeType(ntName);
    org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl def = parentImpl.getApplicableChildNodeDefinition(name, ntName);
    // check for name collisions
    // TODO: improve. copied from NodeImpl
    NodeState thisState = parentImpl.getNodeState();
    ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
    if (cne != null) {
        // check same-name sibling setting of new node
        if (!def.allowsSameNameSiblings()) {
            throw new ItemExistsException();
        }
        // check same-name sibling setting of existing node
        NodeId newId = cne.getId();
        NodeImpl n = (NodeImpl) parentImpl.sessionContext.getItemManager().getItem(newId);
        if (!n.getDefinition().allowsSameNameSiblings()) {
            throw new ItemExistsException();
        }
    }
    return parentImpl.createChildNode(name, nodeType, nodeId);
}
Also used : NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 7 with NodeTypeImpl

use of org.apache.jackrabbit.core.nodetype.NodeTypeImpl in project jackrabbit by apache.

the class AddMixinOperation method perform.

public Object perform(SessionContext context) throws RepositoryException {
    int permissions = Permission.NODE_TYPE_MNGMT;
    // is required in addition.
    if (MIX_VERSIONABLE.equals(mixinName) || MIX_SIMPLE_VERSIONABLE.equals(mixinName)) {
        permissions |= Permission.VERSION_MNGMT;
    }
    context.getItemValidator().checkModify(node, CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD, permissions);
    NodeTypeManagerImpl ntMgr = context.getNodeTypeManager();
    NodeTypeImpl mixin = ntMgr.getNodeType(mixinName);
    if (!mixin.isMixin()) {
        throw new RepositoryException(context.getJCRName(mixinName) + " is not a mixin node type");
    }
    Name primaryTypeName = node.getNodeState().getNodeTypeName();
    NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName);
    if (primaryType.isDerivedFrom(mixinName)) {
        // new mixin is already included in primary type
        return this;
    }
    // build effective node type of mixin's & primary type in order
    // to detect conflicts
    NodeTypeRegistry ntReg = context.getNodeTypeRegistry();
    EffectiveNodeType entExisting;
    try {
        // existing mixin's
        Set<Name> mixins = new HashSet<Name>(node.getNodeState().getMixinTypeNames());
        // build effective node type representing primary type including
        // existing mixin's
        entExisting = ntReg.getEffectiveNodeType(primaryTypeName, mixins);
        if (entExisting.includesNodeType(mixinName)) {
            // new mixin is already included in existing mixin type(s)
            return this;
        }
        // add new mixin
        mixins.add(mixinName);
        // try to build new effective node type (will throw in case
        // of conflicts)
        ntReg.getEffectiveNodeType(primaryTypeName, mixins);
    } catch (NodeTypeConflictException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
    // try to revert the changes in case an exception occurs
    try {
        // modify the state of this node
        NodeState thisState = (NodeState) node.getOrCreateTransientItemState();
        // add mixin name
        Set<Name> mixins = new HashSet<Name>(thisState.getMixinTypeNames());
        mixins.add(mixinName);
        thisState.setMixinTypeNames(mixins);
        // set jcr:mixinTypes property
        node.setMixinTypesProperty(mixins);
        // add 'auto-create' properties defined in mixin type
        for (PropertyDefinition aPda : mixin.getAutoCreatedPropertyDefinitions()) {
            PropertyDefinitionImpl pd = (PropertyDefinitionImpl) aPda;
            // make sure that the property is not already defined
            // by primary type or existing mixin's
            NodeTypeImpl declaringNT = (NodeTypeImpl) pd.getDeclaringNodeType();
            if (!entExisting.includesNodeType(declaringNT.getQName())) {
                node.createChildProperty(pd.unwrap().getName(), pd.getRequiredType(), pd);
            }
        }
        // recursively add 'auto-create' child nodes defined in mixin type
        for (NodeDefinition aNda : mixin.getAutoCreatedNodeDefinitions()) {
            NodeDefinitionImpl nd = (NodeDefinitionImpl) aNda;
            // make sure that the child node is not already defined
            // by primary type or existing mixin's
            NodeTypeImpl declaringNT = (NodeTypeImpl) nd.getDeclaringNodeType();
            if (!entExisting.includesNodeType(declaringNT.getQName())) {
                node.createChildNode(nd.unwrap().getName(), (NodeTypeImpl) nd.getDefaultPrimaryType(), null);
            }
        }
    } catch (RepositoryException re) {
        // try to undo the modifications by removing the mixin
        try {
            node.removeMixin(mixinName);
        } catch (RepositoryException re1) {
        // silently ignore & fall through
        }
        throw re;
    }
    return this;
}
Also used : NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeState(org.apache.jackrabbit.core.state.NodeState) NodeTypeConflictException(org.apache.jackrabbit.core.nodetype.NodeTypeConflictException) NodeDefinition(javax.jcr.nodetype.NodeDefinition) PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Name(org.apache.jackrabbit.spi.Name) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) NodeTypeManagerImpl(org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl) HashSet(java.util.HashSet)

Example 8 with NodeTypeImpl

use of org.apache.jackrabbit.core.nodetype.NodeTypeImpl in project jackrabbit by apache.

the class EventFilter method blocks.

/**
 * Returns <code>true</code> if this <code>EventFilter</code> does not allow
 * the specified <code>EventState</code>; <code>false</code> otherwise.
 *
 * @param eventState the <code>EventState</code> in question.
 * @return <code>true</code> if this <code>EventFilter</code> blocks the
 *         <code>EventState</code>.
 * @throws RepositoryException if an error occurs while checking.
 */
boolean blocks(EventState eventState) throws RepositoryException {
    // first do cheap checks
    // check event type
    long type = eventState.getType();
    if ((eventTypes & type) == 0) {
        return true;
    }
    // check for session local changes
    if (noLocal && session.equals(eventState.getSession())) {
        // listener does not wish to get local events
        return true;
    }
    if (noExternal && eventState.isExternal()) {
        return true;
    }
    if (noInternal && !eventState.isExternal()) {
        return true;
    }
    // UUIDs, types, and paths do not need to match for persist
    if (eventState.getType() == Event.PERSIST) {
        return false;
    }
    // check UUIDs
    NodeId parentId = eventState.getParentId();
    if (ids != null) {
        boolean match = false;
        for (int i = 0; i < ids.length && !match; i++) {
            match |= parentId.equals(ids[i]);
        }
        if (!match) {
            return true;
        }
    }
    // check node types
    if (nodeTypes != null) {
        Set<NodeType> eventTypes = eventState.getNodeTypes(session.getNodeTypeManager());
        boolean match = false;
        for (int i = 0; i < nodeTypes.length && !match; i++) {
            for (NodeType eventType : eventTypes) {
                NodeTypeImpl nodeType = (NodeTypeImpl) eventType;
                match |= nodeType.getQName().equals(nodeTypes[i].getQName()) || nodeType.isDerivedFrom(nodeTypes[i].getQName());
            }
        }
        if (!match) {
            return true;
        }
    }
    // finally check paths
    Path eventPath = eventState.getParentPath();
    boolean match = false;
    for (Path path : paths) {
        if (eventPath.equals(path) || isDeep && eventPath.isDescendantOf(path)) {
            match = true;
            break;
        }
    }
    return !match;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeType(javax.jcr.nodetype.NodeType) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 9 with NodeTypeImpl

use of org.apache.jackrabbit.core.nodetype.NodeTypeImpl in project jackrabbit by apache.

the class VirtualNodeTypeStateManager method recursiveRemove.

/**
 * Adds a subtree of itemstates as 'removed' to a list of events
 *
 * @param events
 * @param parent
 * @param node
 * @throws RepositoryException
 */
private void recursiveRemove(List<EventState> events, NodeImpl parent, NodeImpl node) throws RepositoryException {
    events.add(EventState.childNodeRemoved(parent.getNodeId(), parent.getPrimaryPath(), node.getNodeId(), node.getPrimaryPath().getLastElement(), ((NodeTypeImpl) parent.getPrimaryNodeType()).getQName(), parent.getMixinTypeNames(), node.getSession()));
    NodeIterator niter = node.getNodes();
    while (niter.hasNext()) {
        NodeImpl n = (NodeImpl) niter.nextNode();
        recursiveRemove(events, node, n);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl)

Example 10 with NodeTypeImpl

use of org.apache.jackrabbit.core.nodetype.NodeTypeImpl in project jackrabbit by apache.

the class VirtualNodeTypeStateManager method recursiveAdd.

/**
 * Adds a subtree of itemstates as 'added' to a list of events
 *
 * @param events
 * @param parent
 * @param node
 * @throws RepositoryException
 */
private void recursiveAdd(List<EventState> events, NodeImpl parent, NodeImpl node) throws RepositoryException {
    events.add(EventState.childNodeAdded(parent.getNodeId(), parent.getPrimaryPath(), node.getNodeId(), node.getPrimaryPath().getLastElement(), ((NodeTypeImpl) parent.getPrimaryNodeType()).getQName(), parent.getMixinTypeNames(), node.getSession()));
    PropertyIterator iter = node.getProperties();
    while (iter.hasNext()) {
        PropertyImpl prop = (PropertyImpl) iter.nextProperty();
        events.add(EventState.propertyAdded((NodeId) node.getId(), node.getPrimaryPath(), prop.getPrimaryPath().getLastElement(), ((NodeTypeImpl) node.getPrimaryNodeType()).getQName(), node.getMixinTypeNames(), node.getSession()));
    }
    NodeIterator niter = node.getNodes();
    while (niter.hasNext()) {
        NodeImpl n = (NodeImpl) niter.nextNode();
        recursiveAdd(events, node, n);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) NodeId(org.apache.jackrabbit.core.id.NodeId) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Aggregations

NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)15 RepositoryException (javax.jcr.RepositoryException)9 Name (org.apache.jackrabbit.spi.Name)8 NodeId (org.apache.jackrabbit.core.id.NodeId)7 NodeState (org.apache.jackrabbit.core.state.NodeState)7 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)5 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)5 Path (org.apache.jackrabbit.spi.Path)5 ItemExistsException (javax.jcr.ItemExistsException)4 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)4 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)4 HashSet (java.util.HashSet)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 NodeDefinition (javax.jcr.nodetype.NodeDefinition)3 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)3 NodeImpl (org.apache.jackrabbit.core.NodeImpl)3 NodeTypeConflictException (org.apache.jackrabbit.core.nodetype.NodeTypeConflictException)3 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)3 AccessManager (org.apache.jackrabbit.core.security.AccessManager)3