Search in sources :

Example 61 with InternalValue

use of org.apache.jackrabbit.core.value.InternalValue 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 62 with InternalValue

use of org.apache.jackrabbit.core.value.InternalValue 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

InternalValue (org.apache.jackrabbit.core.value.InternalValue)62 Name (org.apache.jackrabbit.spi.Name)21 NodeId (org.apache.jackrabbit.core.id.NodeId)20 PropertyState (org.apache.jackrabbit.core.state.PropertyState)17 RepositoryException (javax.jcr.RepositoryException)16 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)13 PropertyId (org.apache.jackrabbit.core.id.PropertyId)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)11 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)11 NodeState (org.apache.jackrabbit.core.state.NodeState)10 Value (javax.jcr.Value)9 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)6 ArrayList (java.util.ArrayList)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)4 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)4 Path (org.apache.jackrabbit.spi.Path)4