Search in sources :

Example 41 with PropertyState

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

the class BatchedItemOperations method verifyCheckedOut.

//----------------------------------------------------< protected methods >
/**
     * Verifies that the node at <code>nodePath</code> is checked-out; throws a
     * <code>VersionException</code> if that's not the case.
     * <p>
     * A node is considered <i>checked-out</i> if it is versionable and
     * checked-out, or is non-versionable but its nearest versionable ancestor
     * is checked-out, or is non-versionable and there are no versionable
     * ancestors.
     *
     * @param nodePath
     * @throws PathNotFoundException
     * @throws VersionException
     * @throws RepositoryException
     */
protected void verifyCheckedOut(Path nodePath) throws PathNotFoundException, VersionException, RepositoryException {
    // search nearest ancestor that is versionable, start with node at nodePath
    /**
         * FIXME should not only rely on existence of jcr:isCheckedOut property
         * but also verify that node.isNodeType("mix:versionable")==true;
         * this would have a negative impact on performance though...
         */
    NodeState nodeState = getNodeState(nodePath);
    while (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
        if (nodePath.denotesRoot()) {
            return;
        }
        nodePath = nodePath.getAncestor(1);
        nodeState = getNodeState(nodePath);
    }
    PropertyId propId = new PropertyId(nodeState.getNodeId(), NameConstants.JCR_ISCHECKEDOUT);
    PropertyState propState;
    try {
        propState = (PropertyState) stateMgr.getItemState(propId);
    } catch (ItemStateException ise) {
        String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(propId);
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
    boolean checkedOut = propState.getValues()[0].getBoolean();
    if (!checkedOut) {
        throw new VersionException(safeGetJCRPath(nodePath) + " is checked-in");
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) VersionException(javax.jcr.version.VersionException)

Example 42 with PropertyState

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

the class AbstractBundlePersistenceManager method load.

/**
     * {@inheritDoc}
     *
     * Loads the state via the appropriate NodePropBundle.
     */
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    NodePropBundle bundle = getBundle(id.getParentId());
    if (bundle != null) {
        PropertyState state = createNew(id);
        PropertyEntry p = bundle.getPropertyEntry(id.getName());
        if (p != null) {
            state.setMultiValued(p.isMultiValued());
            state.setType(p.getType());
            state.setValues(p.getValues());
            state.setModCount(p.getModCount());
        } else if (id.getName().equals(JCR_UUID)) {
            state.setType(PropertyType.STRING);
            state.setMultiValued(false);
            state.setValues(new InternalValue[] { InternalValue.create(id.getParentId().toString()) });
        } else if (id.getName().equals(JCR_PRIMARYTYPE)) {
            state.setType(PropertyType.NAME);
            state.setMultiValued(false);
            state.setValues(new InternalValue[] { InternalValue.create(bundle.getNodeTypeName()) });
        } else if (id.getName().equals(JCR_MIXINTYPES)) {
            state.setType(PropertyType.NAME);
            state.setMultiValued(true);
            Set<Name> mixins = bundle.getMixinTypeNames();
            state.setValues(InternalValue.create(mixins.toArray(new Name[mixins.size()])));
        } else {
            throw new NoSuchItemStateException(id.toString());
        }
        return state;
    } else {
        throw new NoSuchItemStateException(id.toString());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name)

Example 43 with PropertyState

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

the class PersistenceCopier method copy.

/**
     * Copies the given node state and all associated property states
     * to the target persistence manager.
     *
     * @param sourceNode source node state
     * @throws RepositoryException if the copy operation fails
     */
private void copy(NodeState sourceNode) throws RepositoryException {
    try {
        ChangeLog changes = new ChangeLog();
        // Copy the node state
        NodeState targetNode = target.createNew(sourceNode.getNodeId());
        targetNode.setParentId(sourceNode.getParentId());
        targetNode.setNodeTypeName(sourceNode.getNodeTypeName());
        targetNode.setMixinTypeNames(sourceNode.getMixinTypeNames());
        targetNode.setPropertyNames(sourceNode.getPropertyNames());
        targetNode.setChildNodeEntries(sourceNode.getChildNodeEntries());
        if (target.exists(targetNode.getNodeId())) {
            changes.modified(targetNode);
        } else {
            changes.added(targetNode);
        }
        // Copy all associated property states
        for (Name name : sourceNode.getPropertyNames()) {
            PropertyId id = new PropertyId(sourceNode.getNodeId(), name);
            PropertyState sourceState = source.load(id);
            PropertyState targetState = target.createNew(id);
            targetState.setType(sourceState.getType());
            targetState.setMultiValued(sourceState.isMultiValued());
            InternalValue[] values = sourceState.getValues();
            if (sourceState.getType() == PropertyType.BINARY) {
                for (int i = 0; i < values.length; i++) {
                    InputStream stream = values[i].getStream();
                    try {
                        values[i] = InternalValue.create(stream, store);
                    } finally {
                        stream.close();
                    }
                }
            }
            targetState.setValues(values);
            if (target.exists(targetState.getPropertyId())) {
                changes.modified(targetState);
            } else {
                changes.added(targetState);
            }
        }
        // Copy all node references
        if (source.existsReferencesTo(sourceNode.getNodeId())) {
            changes.modified(source.loadReferencesTo(sourceNode.getNodeId()));
        } else if (target.existsReferencesTo(sourceNode.getNodeId())) {
            NodeReferences references = target.loadReferencesTo(sourceNode.getNodeId());
            references.clearAllReferences();
            changes.modified(references);
        }
        // Persist the copied states
        target.store(changes);
    } catch (IOException e) {
        throw new RepositoryException("Unable to copy binary values of " + sourceNode, e);
    } catch (ItemStateException e) {
        throw new RepositoryException("Unable to copy " + sourceNode, e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InputStream(java.io.InputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog)

Example 44 with PropertyState

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

the class SimpleExcerptProvider method getExcerpt.

/**
     * {@inheritDoc}
     */
public String getExcerpt(NodeId id, int maxFragments, int maxFragmentSize) throws IOException {
    StringBuffer text = new StringBuffer();
    try {
        NodeState nodeState = (NodeState) ism.getItemState(id);
        String separator = "";
        Iterator<Name> it = nodeState.getPropertyNames().iterator();
        while (it.hasNext() && text.length() < maxFragmentSize) {
            PropertyId propId = new PropertyId(id, it.next());
            PropertyState propState = (PropertyState) ism.getItemState(propId);
            if (propState.getType() == PropertyType.STRING) {
                text.append(separator);
                separator = " ... ";
                InternalValue[] values = propState.getValues();
                for (InternalValue value : values) {
                    text.append(value.toString());
                }
            }
        }
    } catch (ItemStateException e) {
    // ignore
    }
    if (text.length() > maxFragmentSize) {
        int lastSpace = text.lastIndexOf(" ", maxFragmentSize);
        if (lastSpace != -1) {
            text.setLength(lastSpace);
        } else {
            text.setLength(maxFragmentSize);
        }
        text.append(" ...");
    }
    return "<excerpt><fragment>" + text.toString() + "</fragment></excerpt>";
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 45 with PropertyState

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

the class NodeIndexer method getValue.

/**
     * Utility method that extracts the first value of the named property
     * of the current node. Returns <code>null</code> if the property does
     * not exist or contains no values.
     *
     * @param name property name
     * @return value of the named property, or <code>null</code>
     * @throws ItemStateException if the property can not be accessed
     */
protected InternalValue getValue(Name name) throws ItemStateException {
    try {
        PropertyId id = new PropertyId(node.getNodeId(), name);
        PropertyState property = (PropertyState) stateProvider.getItemState(id);
        InternalValue[] values = property.getValues();
        if (values.length > 0) {
            return values[0];
        } else {
            return null;
        }
    } catch (NoSuchItemStateException e) {
        return null;
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Aggregations

PropertyState (org.apache.jackrabbit.core.state.PropertyState)53 PropertyId (org.apache.jackrabbit.core.id.PropertyId)25 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)25 NodeState (org.apache.jackrabbit.core.state.NodeState)25 RepositoryException (javax.jcr.RepositoryException)22 Name (org.apache.jackrabbit.spi.Name)22 InternalValue (org.apache.jackrabbit.core.value.InternalValue)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)14 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)13 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 ItemExistsException (javax.jcr.ItemExistsException)4 Value (javax.jcr.Value)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)4