use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class ProtectedItemModifier method addNode.
protected NodeImpl addNode(NodeImpl parentImpl, Name name, Name ntName, NodeId nodeId) throws RepositoryException {
checkPermission(parentImpl, name, getPermission(true, false));
// validation: make sure Node is not locked or checked-in.
parentImpl.checkSetProperty();
NodeTypeImpl nodeType = parentImpl.sessionContext.getNodeTypeManager().getNodeType(ntName);
org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl def = parentImpl.getApplicableChildNodeDefinition(name, ntName);
// check for name collisions
// TODO: improve. copied from NodeImpl
NodeState thisState = parentImpl.getNodeState();
ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
if (cne != null) {
// check same-name sibling setting of new node
if (!def.allowsSameNameSiblings()) {
throw new ItemExistsException();
}
// check same-name sibling setting of existing node
NodeId newId = cne.getId();
NodeImpl n = (NodeImpl) parentImpl.sessionContext.getItemManager().getItem(newId);
if (!n.getDefinition().allowsSameNameSiblings()) {
throw new ItemExistsException();
}
}
return parentImpl.createChildNode(name, nodeType, nodeId);
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class NodeImpl method getSharedSet.
//-------------------------------------------------------< shareable nodes >
/**
* Returns an iterator over all nodes that are in the shared set of this
* node. If this node is not shared then the returned iterator contains
* only this node.
*
* @return a <code>NodeIterator</code>
* @throws RepositoryException if an error occurs.
* @since JCR 2.0
*/
public NodeIterator getSharedSet() throws RepositoryException {
// check state of this instance
sanityCheck();
ArrayList<NodeImpl> list = new ArrayList<NodeImpl>();
if (!isShareable()) {
list.add(this);
} else {
NodeState state = data.getNodeState();
for (NodeId parentId : state.getSharedSet()) {
list.add(itemMgr.getNode(getNodeId(), parentId));
}
}
return new NodeIteratorAdapter(list);
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class EventFilter method blocks.
/**
* Returns <code>true</code> if this <code>EventFilter</code> does not allow
* the specified <code>EventState</code>; <code>false</code> otherwise.
*
* @param eventState the <code>EventState</code> in question.
* @return <code>true</code> if this <code>EventFilter</code> blocks the
* <code>EventState</code>.
* @throws RepositoryException if an error occurs while checking.
*/
boolean blocks(EventState eventState) throws RepositoryException {
// first do cheap checks
// check event type
long type = eventState.getType();
if ((eventTypes & type) == 0) {
return true;
}
// check for session local changes
if (noLocal && session.equals(eventState.getSession())) {
// listener does not wish to get local events
return true;
}
if (noExternal && eventState.isExternal()) {
return true;
}
if (noInternal && !eventState.isExternal()) {
return true;
}
// UUIDs, types, and paths do not need to match for persist
if (eventState.getType() == Event.PERSIST) {
return false;
}
// check UUIDs
NodeId parentId = eventState.getParentId();
if (ids != null) {
boolean match = false;
for (int i = 0; i < ids.length && !match; i++) {
match |= parentId.equals(ids[i]);
}
if (!match) {
return true;
}
}
// check node types
if (nodeTypes != null) {
Set<NodeType> eventTypes = eventState.getNodeTypes(session.getNodeTypeManager());
boolean match = false;
for (int i = 0; i < nodeTypes.length && !match; i++) {
for (NodeType eventType : eventTypes) {
NodeTypeImpl nodeType = (NodeTypeImpl) eventType;
match |= nodeType.getQName().equals(nodeTypes[i].getQName()) || nodeType.isDerivedFrom(nodeTypes[i].getQName());
}
}
if (!match) {
return true;
}
}
// finally check paths
Path eventPath = eventState.getParentPath();
boolean match = false;
for (Path path : paths) {
if (eventPath.equals(path) || isDeep && eventPath.isDescendantOf(path)) {
match = true;
break;
}
}
return !match;
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class VirtualNodeTypeStateManager method recursiveAdd.
/**
* Adds a subtree of itemstates as 'added' to a list of events
*
* @param events
* @param parent
* @param node
* @throws RepositoryException
*/
private void recursiveAdd(List<EventState> events, NodeImpl parent, NodeImpl node) throws RepositoryException {
events.add(EventState.childNodeAdded(parent.getNodeId(), parent.getPrimaryPath(), node.getNodeId(), node.getPrimaryPath().getLastElement(), ((NodeTypeImpl) parent.getPrimaryNodeType()).getQName(), parent.getMixinTypeNames(), node.getSession()));
PropertyIterator iter = node.getProperties();
while (iter.hasNext()) {
PropertyImpl prop = (PropertyImpl) iter.nextProperty();
events.add(EventState.propertyAdded((NodeId) node.getId(), node.getPrimaryPath(), prop.getPrimaryPath().getLastElement(), ((NodeTypeImpl) node.getPrimaryNodeType()).getQName(), node.getMixinTypeNames(), node.getSession()));
}
NodeIterator niter = node.getNodes();
while (niter.hasNext()) {
NodeImpl n = (NodeImpl) niter.nextNode();
recursiveAdd(events, node, n);
}
}
use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.
the class VirtualNodeTypeStateProvider method createPropertyDefState.
/**
* creates a node state for the given property def
*
* @param parent
* @param propDef
* @return
* @throws RepositoryException
*/
private VirtualNodeState createPropertyDefState(VirtualNodeState parent, QPropertyDefinition propDef, QNodeTypeDefinition ntDef, int n) throws RepositoryException {
NodeId id = calculateStableId(ntDef.getName().toString() + "/" + NameConstants.JCR_PROPERTYDEFINITION.toString() + "/" + n);
VirtualNodeState pState = createNodeState(parent, NameConstants.JCR_PROPERTYDEFINITION, id, NameConstants.NT_PROPERTYDEFINITION);
// add properties
if (!propDef.definesResidual()) {
pState.setPropertyValue(NameConstants.JCR_NAME, InternalValue.create(propDef.getName()));
}
pState.setPropertyValue(NameConstants.JCR_AUTOCREATED, InternalValue.create(propDef.isAutoCreated()));
pState.setPropertyValue(NameConstants.JCR_MANDATORY, InternalValue.create(propDef.isMandatory()));
pState.setPropertyValue(NameConstants.JCR_ONPARENTVERSION, InternalValue.create(OnParentVersionAction.nameFromValue(propDef.getOnParentVersion())));
pState.setPropertyValue(NameConstants.JCR_PROTECTED, InternalValue.create(propDef.isProtected()));
pState.setPropertyValue(NameConstants.JCR_MULTIPLE, InternalValue.create(propDef.isMultiple()));
pState.setPropertyValue(NameConstants.JCR_REQUIREDTYPE, InternalValue.create(PropertyType.nameFromValue(propDef.getRequiredType()).toUpperCase()));
InternalValue[] defVals = InternalValue.create(propDef.getDefaultValues());
// retrieve the property type from the first default value present with
// the property definition. in case no default values are defined,
// fallback to PropertyType.STRING in order to avoid creating a property
// with type UNDEFINED which is illegal.
int defValsType = PropertyType.STRING;
if (defVals != null && defVals.length > 0) {
defValsType = defVals[0].getType();
}
if (defVals != null) {
pState.setPropertyValues(NameConstants.JCR_DEFAULTVALUES, defValsType, defVals);
}
QValueConstraint[] vc = propDef.getValueConstraints();
InternalValue[] vals = new InternalValue[vc.length];
for (int i = 0; i < vc.length; i++) {
vals[i] = InternalValue.create(vc[i].getString());
}
pState.setPropertyValues(NameConstants.JCR_VALUECONSTRAINTS, PropertyType.STRING, vals);
return pState;
}
Aggregations