use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class RepositoryServiceImpl method buildPropertyInfos.
private List<PropertyInfo> buildPropertyInfos(NodeInfo nInfo) throws RepositoryException {
List<PropertyInfo> l = new ArrayList<PropertyInfo>(3);
NodeId nid = nInfo.getId();
Path nPath = nInfo.getPath();
if (nid.getPath() == null) {
PropertyId id = getIdFactory().createPropertyId(nid, NameConstants.JCR_UUID);
QValue[] vs = new QValue[] { getQValueFactory().create(nid.getUniqueID(), PropertyType.STRING) };
Path p = getPathFactory().create(nPath, NameConstants.JCR_UUID, true);
PropertyInfo pi = new PropertyInfoImpl(id, p, PropertyType.STRING, false, vs);
l.add(pi);
}
Name pName = NameConstants.JCR_PRIMARYTYPE;
QValue[] vs = new QValue[] { getQValueFactory().create(nInfo.getNodetype()) };
PropertyInfo pi = new PropertyInfoImpl(getIdFactory().createPropertyId(nid, pName), getPathFactory().create(nPath, pName, true), PropertyType.NAME, false, vs);
l.add(pi);
Name[] mixins = nInfo.getMixins();
if (mixins.length > 0) {
pName = NameConstants.JCR_MIXINTYPES;
vs = new QValue[mixins.length];
for (int i = 0; i < mixins.length; i++) {
vs[i] = getQValueFactory().create(mixins[i]);
}
pi = new PropertyInfoImpl(getIdFactory().createPropertyId(nid, pName), getPathFactory().create(nPath, pName, true), PropertyType.NAME, true, vs);
l.add(pi);
}
return l;
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class RepositoryServiceImpl method getNodeInfo.
@Override
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_PRIMARYNODETYPE_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_MIXINNODETYPES_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_PATH_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(DavPropertyName.RESOURCETYPE);
HttpPropfind request = null;
try {
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_1);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(nodeId, sessionInfo));
}
MultiStatusResponse nodeResponse = null;
List<MultiStatusResponse> childResponses = new ArrayList<MultiStatusResponse>();
for (MultiStatusResponse mresponse : mresponses) {
if (isSameResource(uri, mresponse)) {
nodeResponse = mresponse;
} else {
childResponses.add(mresponse);
}
}
if (nodeResponse == null) {
throw new ItemNotFoundException("Unable to retrieve the node " + saveGetIdString(nodeId, sessionInfo));
}
DavPropertySet propSet = nodeResponse.getProperties(DavServletResponse.SC_OK);
Object type = propSet.get(DavPropertyName.RESOURCETYPE).getValue();
if (type == null) {
// the given id points to a Property instead of a Node
throw new ItemNotFoundException("No node for id " + saveGetIdString(nodeId, sessionInfo));
}
NamePathResolver resolver = getNamePathResolver(sessionInfo);
NodeId parentId = getParentId(uri, propSet, sessionInfo);
NodeInfoImpl nInfo = buildNodeInfo(uri, nodeResponse, parentId, propSet, sessionInfo, resolver);
for (MultiStatusResponse resp : childResponses) {
DavPropertySet childProps = resp.getProperties(DavServletResponse.SC_OK);
if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
// any other resource type than default (empty) is represented by a node item
// --> build child info object
nInfo.addChildInfo(buildChildInfo(childProps, sessionInfo));
} else {
PropertyId childId = uriResolver.buildPropertyId(nInfo.getId(), resp, sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
nInfo.addPropertyId(childId);
}
}
return nInfo;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} catch (NameException e) {
throw new RepositoryException(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class ItemInfoJsonHandler method object.
public void object() throws IOException {
if (name != null) {
try {
NodeInfo current = getCurrentNodeInfo();
Path relPath = pFactory.create(name, index);
NodeId id = idFactory.createNodeId(current.getId(), relPath);
Path currentPath = current.getPath();
Path p = pFactory.create(currentPath, relPath, true);
NodeInfo nInfo = new NodeInfoImpl(id, p);
nodeInfos.push(nInfo);
propInfoLists.push(new ArrayList<PropertyInfoImpl>(8));
} catch (RepositoryException e) {
throw new IOException(e.getMessage());
}
}
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class URIResolverImpl method getPropertyId.
/**
* @inheritDoc
*/
public PropertyId getPropertyId(String uri, SessionInfo sessionInfo) throws RepositoryException {
IdURICache cache = getCache(sessionInfo.getWorkspaceName());
ItemId id = cache.getItemId(uri);
if (id != null) {
if (!id.denotesNode()) {
return (PropertyId) id;
}
}
// separate parent uri and property JCRName
String parentUri = Text.getRelativeParent(uri, 1, true);
// make sure propName is unescaped
String propName = Text.unescape(Text.getName(uri, true));
// retrieve parent node id
NodeId parentId = getNodeId(parentUri, sessionInfo, false);
// build property id
try {
Name name = service.getNamePathResolver(sessionInfo).getQName(propName);
PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
cache.add(uri, propertyId);
return propertyId;
} catch (NameException e) {
throw new RepositoryException(e);
}
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class RepositoryServiceImpl method restore.
/**
* {@inheritDoc}
*/
public void restore(final SessionInfo sessionInfo, final NodeId nodeId, final NodeId versionId, final boolean removeExisting) throws VersionException, PathNotFoundException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
Version v = (Version) getNode(versionId, sInfo);
if (hasNode(sessionInfo, nodeId)) {
Node n = getNode(nodeId, sInfo);
n.restore(v, removeExisting);
} else {
// restore with rel-Path part
Node n = null;
Path relPath = null;
Path path = nodeId.getPath();
if (nodeId.getUniqueID() != null) {
n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
relPath = (path.isAbsolute()) ? getPathFactory().getRootPath().computeRelativePath(nodeId.getPath()) : path;
} else {
int degree = 0;
while (degree < path.getLength()) {
Path ancestorPath = path.getAncestor(degree);
NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(), ancestorPath);
if (hasNode(sessionInfo, parentId)) {
n = getNode(parentId, sInfo);
relPath = ancestorPath.computeRelativePath(path);
}
degree++;
}
}
if (n == null) {
throw new PathNotFoundException("Path not found " + nodeId);
} else {
n.restore(v, sInfo.getNamePathResolver().getJCRPath(relPath), removeExisting);
}
}
return null;
}
}, sInfo);
}
Aggregations