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