Search in sources :

Example 1 with ItemImpl

use of org.apache.jackrabbit.core.ItemImpl in project jackrabbit by apache.

the class CompiledPermissionsImpl method buildResult.

//------------------------------------< AbstractCompiledPermissions >---
/**
     * @see AbstractCompiledPermissions#buildResult(org.apache.jackrabbit.spi.Path)
     */
@Override
protected Result buildResult(Path absPath) throws RepositoryException {
    boolean existingNode = false;
    NodeImpl node;
    ItemManager itemMgr = session.getItemManager();
    try {
        ItemImpl item = itemMgr.getItem(absPath);
        if (item.isNode()) {
            node = (NodeImpl) item;
            existingNode = true;
        } else {
            node = (NodeImpl) item.getParent();
        }
    } catch (RepositoryException e) {
        // path points to a non-persisted item.
        // -> find the nearest persisted node starting from the root.
        Path.Element[] elems = absPath.getElements();
        NodeImpl parent = (NodeImpl) session.getRootNode();
        for (int i = 1; i < elems.length - 1; i++) {
            Name name = elems[i].getName();
            int index = elems[i].getIndex();
            if (!parent.hasNode(name, index)) {
                // last persisted node reached
                break;
            }
            parent = parent.getNode(name, index);
        }
        node = parent;
    }
    if (node == null) {
        // should never get here
        throw new ItemNotFoundException("Item out of hierarchy.");
    }
    boolean isAcItem = util.isAcItem(absPath);
    return buildResult(node, existingNode, isAcItem, new EntryFilterImpl(principalNames, absPath, session));
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ItemManager(org.apache.jackrabbit.core.ItemManager) ItemImpl(org.apache.jackrabbit.core.ItemImpl) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 2 with ItemImpl

use of org.apache.jackrabbit.core.ItemImpl in project jackrabbit by apache.

the class SessionSaveOperation method perform.

/**
     * Persists transient changes by delegating to the save() method of the
     * root node (or the parent of transient changes if access to the root
     * node is not available to this session).
     */
public Object perform(SessionContext context) throws RepositoryException {
    NodeId id;
    // JCR-2425: check whether session is allowed to read root node
    if (context.getSessionImpl().hasPermission("/", Session.ACTION_READ)) {
        id = context.getRootNodeId();
    } else {
        id = context.getItemStateManager().getIdOfRootTransientNodeState();
    }
    if (LOG.isDebugEnabled()) {
        String path;
        try {
            NodeId transientRoot = context.getItemStateManager().getIdOfRootTransientNodeState();
            ItemImpl item = context.getItemManager().getItem(transientRoot);
            path = item.getPath();
        } catch (Exception e) {
            LOG.warn("Could not get the path", e);
            path = "?";
        }
        if (LOG_WITH_STACKTRACE) {
            LOG.debug("Saving changes under " + path, new Exception());
        } else {
            LOG.debug("Saving changes under " + path);
        }
    }
    if (id != null) {
        context.getItemManager().getItem(id).save();
    }
    return this;
}
Also used : ItemImpl(org.apache.jackrabbit.core.ItemImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)2 ItemImpl (org.apache.jackrabbit.core.ItemImpl)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 ItemManager (org.apache.jackrabbit.core.ItemManager)1 NodeImpl (org.apache.jackrabbit.core.NodeImpl)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 Name (org.apache.jackrabbit.spi.Name)1 Path (org.apache.jackrabbit.spi.Path)1