Search in sources :

Example 26 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class VersionHistoryImpl method getAllVersions.

/**
     * @see VersionHistory#getAllVersions()
     */
public VersionIterator getAllVersions() throws RepositoryException {
    checkStatus();
    refreshEntry(vhEntry);
    Iterator<NodeEntry> childIter = vhEntry.getNodeEntries();
    List<NodeEntry> versionEntries = new ArrayList<NodeEntry>();
    // all child-nodes except from jcr:versionLabels point to Versions.
    while (childIter.hasNext()) {
        NodeEntry entry = childIter.next();
        if (!NameConstants.JCR_VERSIONLABELS.equals(entry.getName())) {
            versionEntries.add(entry);
        }
    }
    return new LazyItemIterator(getItemManager(), new RangeIteratorAdapter(versionEntries));
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ArrayList(java.util.ArrayList) LazyItemIterator(org.apache.jackrabbit.jcr2spi.LazyItemIterator) RangeIteratorAdapter(org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter)

Example 27 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class VersionHistoryImpl method getVersionState.

/**
     *
     * @param versionName
     * @return
     * @throws VersionException
     * @throws RepositoryException
     */
private NodeState getVersionState(String versionName) throws VersionException, RepositoryException {
    try {
        Name vName = session.getNameResolver().getQName(versionName);
        refreshEntry(vhEntry);
        NodeEntry vEntry = vhEntry.getNodeEntry(vName, Path.INDEX_DEFAULT, true);
        if (vEntry == null) {
            throw new VersionException("Version '" + versionName + "' does not exist in this version history.");
        } else {
            return vEntry.getNodeState();
        }
    } catch (org.apache.jackrabbit.spi.commons.conversion.NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

Example 28 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class VersionHistoryImpl method getRootVersion.

/**
     * @see VersionHistory#getRootVersion()
     */
public Version getRootVersion() throws RepositoryException {
    checkStatus();
    NodeEntry vEntry = vhEntry.getNodeEntry(NameConstants.JCR_ROOTVERSION, Path.INDEX_DEFAULT, true);
    if (vEntry == null) {
        String msg = "Unexpected error: VersionHistory state does not contain a root version child node entry.";
        log.error(msg);
        throw new RepositoryException(msg);
    }
    return (Version) getItemManager().getItem(vEntry);
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException)

Example 29 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class VersionManagerImpl method isCheckedOut.

/**
     * Search nearest ancestor that is versionable. If no versionable ancestor
     * can be found, <code>true</code> is returned.
     *
     * @param nodeState
     * @return
     * @throws RepositoryException
     */
public boolean isCheckedOut(NodeState nodeState) throws RepositoryException {
    // shortcut: if state is new, its ancestor must be checkout
    if (nodeState.getStatus() == Status.NEW) {
        return true;
    }
    NodeEntry nodeEntry = nodeState.getNodeEntry();
    try {
        // save or upon executing the workspace operation.
        while (!nodeEntry.hasPropertyEntry(NameConstants.JCR_ISCHECKEDOUT)) {
            NodeEntry parent = nodeEntry.getParent();
            if (parent == null) {
                // reached root state without finding a jcr:isCheckedOut property
                return true;
            }
            nodeEntry = parent;
        }
        PropertyState propState = nodeEntry.getPropertyEntry(NameConstants.JCR_ISCHECKEDOUT).getPropertyState();
        Boolean b = Boolean.valueOf(propState.getValue().getString());
        return b.booleanValue();
    } catch (ItemNotFoundException e) {
    // error while accessing jcr:isCheckedOut property state.
    // -> assume that checkedOut status is ok. see above for general
    // notes about the capabilities of the jcr2spi implementation.
    }
    return true;
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 30 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class SessionItemStateManager method visit.

/**
     * @see OperationVisitor#visit(SetMixin)
     */
public void visit(SetMixin operation) throws ConstraintViolationException, AccessDeniedException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    // NOTE: nodestate is only modified upon save of the changes!
    Name[] mixinNames = operation.getMixinNames();
    NodeState nState = operation.getNodeState();
    NodeEntry nEntry = nState.getNodeEntry();
    // assert the existence of the property entry and set the array of
    // mixinNames to be set on the corresponding property state
    PropertyEntry mixinEntry = nEntry.getPropertyEntry(NameConstants.JCR_MIXINTYPES);
    if (mixinNames.length > 0) {
        // update/create corresponding property state
        if (mixinEntry != null) {
            // execute value of existing property
            PropertyState pState = mixinEntry.getPropertyState();
            setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME, operation.getOptions());
        } else {
            // create new jcr:mixinTypes property
            ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
            QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState.getAllNodeTypeNames(), NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true);
            QValue[] mixinValue = getQValues(mixinNames, qValueFactory);
            addPropertyState(nState, pd.getName(), pd.getRequiredType(), mixinValue, pd, operation.getOptions());
        }
        nState.markModified();
        transientStateMgr.addOperation(operation);
    } else if (mixinEntry != null) {
        // remove the jcr:mixinTypes property state if already present
        PropertyState pState = mixinEntry.getPropertyState();
        removeItemState(pState, operation.getOptions());
        nState.markModified();
        transientStateMgr.addOperation(operation);
    }
// else: empty Name array and no mixin-prop-entry (should not occur)
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ItemDefinitionProvider(org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)40 RepositoryException (javax.jcr.RepositoryException)13 PropertyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)9 Name (org.apache.jackrabbit.spi.Name)9 Node (javax.jcr.Node)6 ItemExistsException (javax.jcr.ItemExistsException)5 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)4 ArrayList (java.util.ArrayList)3 Version (javax.jcr.version.Version)3 NodeId (org.apache.jackrabbit.spi.NodeId)3 Path (org.apache.jackrabbit.spi.Path)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 EffectiveNodeTypeProvider (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider)2 PropertyState (org.apache.jackrabbit.jcr2spi.state.PropertyState)2 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)2 QValue (org.apache.jackrabbit.spi.QValue)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 AccessDeniedException (javax.jcr.AccessDeniedException)1 Item (javax.jcr.Item)1