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