use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class WorkspaceImpl method importXML.
/**
* @see javax.jcr.Workspace#importXML(String, InputStream, int)
*/
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, InvalidSerializedDataException, LockException, RepositoryException {
session.checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
session.checkIsAlive();
Path parentPath = session.getQPath(parentAbsPath);
NodeState parentState = getHierarchyManager().getNodeState(parentPath);
// make sure the given import target is accessible, not locked and checked out.
int options = ItemStateValidator.CHECK_ACCESS | ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_VERSIONING;
getValidator().checkIsWritable(parentState, options);
try {
// run the import
wspManager.execute(WorkspaceImport.create(parentState, in, uuidBehavior));
} finally {
// JCR-2903
in.close();
}
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class SessionImpl method hasPermission.
/**
* @see Session#hasPermission(String, String)
*/
public boolean hasPermission(String absPath, String actions) throws RepositoryException {
checkIsAlive();
// build the array of actions to be checked
String[] actionsArr = actions.split(",");
Path targetPath = getQPath(absPath);
boolean isGranted;
// The given abs-path may point to a non-existing item
if (itemManager.nodeExists(targetPath)) {
NodeState nState = getHierarchyManager().getNodeState(targetPath);
isGranted = getAccessManager().isGranted(nState, actionsArr);
} else if (itemManager.propertyExists(targetPath)) {
PropertyState pState = getHierarchyManager().getPropertyState(targetPath);
isGranted = getAccessManager().isGranted(pState, actionsArr);
} else {
NodeState parentState = null;
Path parentPath = targetPath;
while (parentState == null) {
parentPath = parentPath.getAncestor(1);
if (itemManager.nodeExists(parentPath)) {
parentState = getHierarchyManager().getNodeState(parentPath);
}
}
// parentState is the nearest existing nodeState or the root state.
Path relPath = parentPath.computeRelativePath(targetPath);
isGranted = getAccessManager().isGranted(parentState, relPath, actionsArr);
}
return isGranted;
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class SessionImporter method startNode.
/**
* {@inheritDoc}
*/
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos, NamePathResolver resolver) throws RepositoryException {
if (isClosed()) {
// workspace-importer only: ignore if import has been aborted before.
return;
}
checkSession();
NodeState parent = parents.peek();
if (parent == null) {
// parent node was skipped, skip this child node also
// push null onto stack for skipped node
parents.push(null);
log.debug("Skipping node '" + nodeInfo.getName() + "'.");
return;
}
NodeEntry parentEntry = (NodeEntry) parent.getHierarchyEntry();
NodeState nodeState = null;
if (parentEntry.hasNodeEntry(nodeInfo.getName())) {
try {
// a valid child node with that name already exists
NodeEntry entry = parentEntry.getNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
NodeState existing = entry.getNodeState();
QNodeDefinition def = existing.getDefinition();
if (!def.allowsSameNameSiblings()) {
// existing doesn't allow same-name siblings, check for conflicts
EffectiveNodeTypeProvider provider = session.getEffectiveNodeTypeProvider();
Name[] ntNames = existing.getAllNodeTypeNames();
EffectiveNodeType entExisting = provider.getEffectiveNodeType(ntNames);
if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
return;
}
if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
// this node has already been auto-created, no need to create it
nodeState = existing;
} else {
throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
}
}
} catch (ItemNotFoundException e) {
// 'existing' doesn't exist any more -> ignore
}
}
if (nodeState == null) {
// node does not exist -> create new one
if (nodeInfo.getUUID() == null) {
// no potential uuid conflict, add new node from given info
nodeState = importNode(nodeInfo, parent);
} else {
// make sure the import does not define a uuid without having
// a primaryType or mixin that makes the new node referenceable
checkIncludesMixReferenceable(nodeInfo);
// potential uuid conflict
try {
NodeId conflictingId = session.getIdFactory().createNodeId(nodeInfo.getUUID());
NodeEntry conflicting = session.getHierarchyManager().getNodeEntry(conflictingId);
// assert that the entry is available
conflicting.getItemState();
nodeState = resolveUUIDConflict(parent, conflicting, nodeInfo);
} catch (ItemNotFoundException e) {
// no conflict: create new with given uuid
nodeState = importNode(nodeInfo, parent);
}
}
}
// node state may be 'null' if applicable def is protected
if (nodeState != null) {
// process properties
for (PropInfo pi : propInfos) {
importProperty(pi, nodeState, resolver);
}
}
// push current nodeState onto stack of parents
parents.push(nodeState);
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class SessionImporter method importNode.
/**
*
* @param nodeInfo
* @param parent
* @return
* @throws ConstraintViolationException
* @throws ItemNotFoundException
* @throws RepositoryException
*/
private NodeState importNode(NodeInfo nodeInfo, NodeState parent) throws ConstraintViolationException, ItemNotFoundException, RepositoryException {
Name[] parentNtNames = parent.getAllNodeTypeNames();
if (parent.hasPropertyName(nodeInfo.getName())) {
/**
* a property with the same name already exists; if this property
* has been imported as well (e.g. through document view import
* where an element can have the same name as one of the attributes
* of its parent element) we have to rename the conflicting property;
*
* see http://issues.apache.org/jira/browse/JCR-61
*/
PropertyState conflicting = parent.getPropertyState(nodeInfo.getName());
if (conflicting.getStatus() == Status.NEW) {
// assume this property has been imported as well;
// rename conflicting property
// TODO: use better reversible escaping scheme to create unique name
Name newName = session.getNameFactory().create(nodeInfo.getName().getNamespaceURI(), nodeInfo.getName().getLocalName() + "_");
if (parent.hasPropertyName(newName)) {
newName = session.getNameFactory().create(newName.getNamespaceURI(), newName.getLocalName() + "_");
}
// since name changes, need to find new applicable definition
QPropertyDefinition propDef;
if (conflicting.getValues().length == 1) {
// could be single- or multi-valued (n == 1)
try {
// try single-valued
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), false);
} catch (ConstraintViolationException cve) {
// try multi-valued
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), true);
}
} else {
// can only be multi-valued (n == 0 || n > 1)
propDef = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, newName, conflicting.getType(), true);
}
Operation ap = AddProperty.create(parent, newName, conflicting.getType(), propDef, conflicting.getValues());
stateMgr.execute(ap);
Operation rm = Remove.create(conflicting);
stateMgr.execute(rm);
}
}
// do create new nodeState
QNodeDefinition def = session.getItemDefinitionProvider().getQNodeDefinition(parentNtNames, nodeInfo.getName(), nodeInfo.getNodeTypeName());
if (def.isProtected()) {
log.debug("Skipping protected nodeState (" + nodeInfo.getName() + ")");
return null;
} else {
Name ntName = nodeInfo.getNodeTypeName();
if (ntName == null) {
// use default node type
ntName = def.getDefaultPrimaryType();
}
Operation an = AddNode.create(parent, nodeInfo.getName(), ntName, nodeInfo.getUUID());
stateMgr.execute(an);
// retrieve id of state that has been created during execution of AddNode
NodeState childState = (NodeState) ((AddNode) an).getAddedStates().get(0);
// and set mixin types
Name[] mixinNames = nodeInfo.getMixinNames();
if (mixinNames != null && mixinNames.length > 0) {
Operation sm = SetMixin.create(childState, nodeInfo.getMixinNames());
stateMgr.execute(sm);
}
return childState;
}
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class VersionHistoryImpl method addVersionLabel.
/**
* @see VersionHistory#addVersionLabel(String, String, boolean)
*/
public void addVersionLabel(String versionName, String label, boolean moveLabel) throws VersionException, RepositoryException {
checkStatus();
Name qLabel = getQLabel(label);
NodeState vState = getVersionState(versionName);
// delegate to version manager that operates on workspace directly
session.getVersionStateManager().addVersionLabel((NodeState) getItemState(), vState, qLabel, moveLabel);
}
Aggregations