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>";
}
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;
}
}
Aggregations