Search in sources :

Example 46 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class Serializer method serialize.

/**
 * Serializes the specified <code>NodeReferences</code> object to the given
 * binary <code>stream</code>.
 *
 * @param refs   object to serialize
 * @param stream the stream where the object should be serialized to
 * @throws Exception if an error occurs during the serialization
 * @see #deserialize(NodeReferences, InputStream)
 */
public static void serialize(NodeReferences refs, OutputStream stream) throws Exception {
    DataOutputStream out = new DataOutputStream(stream);
    // references
    Collection<PropertyId> c = refs.getReferences();
    // count
    out.writeInt(c.size());
    for (Iterator<PropertyId> iter = c.iterator(); iter.hasNext(); ) {
        PropertyId propId = iter.next();
        // propertyId
        out.writeUTF(propId.toString());
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 47 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId 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 48 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId 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)

Example 49 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateEx method reload.

/**
 * reloads the given persistent state recursively
 *
 * @param state node state
 * @throws ItemStateException if an error occurs
 */
private void reload(NodeState state) throws ItemStateException {
    if (state.getStatus() != ItemState.STATUS_EXISTING) {
        // first discard all all transient properties
        for (Name propName : state.getPropertyNames()) {
            PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
            if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
                pstate.discard();
            }
        }
        // now reload all child node entries
        for (ChildNodeEntry entry : state.getChildNodeEntries()) {
            NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
            reload(nstate);
        }
        // and reload itself
        state.discard();
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) Name(org.apache.jackrabbit.spi.Name) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 50 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateEx method removeProperty.

/**
 * removes the property with the given name
 *
 * @param name name of the property
 * @return <code>true</code> if the property was removed.
 * @throws RepositoryException if an error occurs
 */
public boolean removeProperty(Name name) throws RepositoryException {
    try {
        if (!nodeState.hasPropertyName(name)) {
            return false;
        } else {
            PropertyId propId = new PropertyId(nodeState.getNodeId(), name);
            ItemState state = stateMgr.getItemState(propId);
            stateMgr.destroy(state);
            nodeState.removePropertyName(name);
            if (nodeState.getStatus() != ItemState.STATUS_NEW) {
                nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
            }
            return true;
        }
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : ItemState(org.apache.jackrabbit.core.state.ItemState) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

PropertyId (org.apache.jackrabbit.core.id.PropertyId)59 Name (org.apache.jackrabbit.spi.Name)29 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 NodeState (org.apache.jackrabbit.core.state.NodeState)23 RepositoryException (javax.jcr.RepositoryException)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)16 InternalValue (org.apache.jackrabbit.core.value.InternalValue)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 HashSet (java.util.HashSet)10 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)7 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ItemId (org.apache.jackrabbit.core.id.ItemId)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)4