use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class NodeEntryImpl method getDeepPropertyEntry.
/**
* @see NodeEntry#getDeepPropertyEntry(Path)
*/
public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
NodeEntryImpl entry = this;
Path.Element[] elems = path.getElements();
int i = 0;
for (; i < elems.length - 1; i++) {
Path.Element elem = elems[i];
if (elems[i].denotesRoot()) {
if (entry.getParent() != null) {
throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
}
continue;
}
int index = elem.getNormalizedIndex();
Name name = elem.getName();
// first try to resolve to known node or property entry
NodeEntry cne = entry.getNodeEntry(name, index, false);
if (cne != null) {
entry = (NodeEntryImpl) cne;
} else {
// on the persistent layer.
if (entry.childNodeEntries.isComplete()) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
// -> check for moved child entry in node-attic
// -> check if child points to a removed/moved sns
List<NodeEntry> siblings = entry.childNodeEntries.get(name);
if (entry.containsAtticChild(siblings, name, index)) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
// break out of the loop and start deep loading the property
break;
}
}
int st = entry.getStatus();
PropertyEntry pe;
if (i == elems.length - 1 && Status.INVALIDATED != st && Status._UNDEFINED_ != st) {
// all node entries present in the hierarchy and the direct ancestor
// has already been resolved and isn't invalidated -> no need to
// retrieve property entry from SPI
pe = entry.properties.get(path.getName());
} else {
/*
* Unknown parent entry (not-existing or not yet loaded) or a parent
* entry that has been invalidated:
* Skip all intermediate entries and directly try to load the
* PropertyState (including building the intermediate entries. If that
* fails ItemNotFoundException is thrown.
*/
PathBuilder pb = new PathBuilder(getPathFactory());
for (int j = i; j < elems.length; j++) {
pb.addLast(elems[j]);
}
Path remainingPath = pb.getPath();
IdFactory idFactory = getIdFactory();
NodeId parentId = entry.getWorkspaceId();
if (remainingPath.getLength() != 1) {
parentId = idFactory.createNodeId(parentId, remainingPath.getAncestor(1));
}
PropertyId propId = idFactory.createPropertyId(parentId, remainingPath.getName());
pe = entry.loadPropertyEntry(propId);
}
if (pe == null) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
return pe;
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class RepositoryServiceImpl method getReferences.
@Override
public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences) throws RepositoryException {
// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
String refType = weakReferences ? JcrRemotingConstants.JCR_WEAK_REFERENCES_LN : JcrRemotingConstants.JCR_REFERENCES_LN;
nameSet.add(refType, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_0);
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));
}
List<PropertyId> refIds = Collections.emptyList();
for (MultiStatusResponse mresponse : mresponses) {
if (isSameResource(uri, mresponse)) {
DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
DavProperty<?> p = props.get(refType, ItemResourceConstants.NAMESPACE);
if (p != null) {
refIds = new ArrayList<PropertyId>();
HrefProperty hp = new HrefProperty(p);
for (String propHref : hp.getHrefs()) {
PropertyId propId = uriResolver.getPropertyId(resolve(uri, propHref), sessionInfo);
if (propertyName == null || propertyName.equals(propId.getName())) {
refIds.add(propId);
}
}
}
}
}
return refIds.iterator();
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class RepositoryServiceImpl method buildNodeInfo.
private NodeInfoImpl buildNodeInfo(String baseUri, MultiStatusResponse nodeResponse, NodeId parentId, DavPropertySet propSet, SessionInfo sessionInfo, NamePathResolver resolver) throws RepositoryException {
NodeId id = uriResolver.buildNodeId(parentId, baseUri, nodeResponse, sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
NodeInfoImpl nInfo = new NodeInfoImpl(id, propSet, resolver);
DavProperty p = propSet.get(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
if (p != null) {
HrefProperty refProp = new HrefProperty(p);
for (String propertyHref : refProp.getHrefs()) {
PropertyId propertyId = uriResolver.getPropertyId(propertyHref, sessionInfo);
nInfo.addReference(propertyId);
}
}
return nInfo;
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class URIResolverImpl method buildPropertyId.
PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException {
IdURICache cache = getCache(workspaceName);
if (cache.containsUri(response.getHref())) {
ItemId id = cache.getItemId(response.getHref());
if (!id.denotesNode()) {
return (PropertyId) id;
}
}
try {
DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
Name name = resolver.getQName(propSet.get(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE).getValue().toString());
PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
cache.add(response.getHref(), propertyId);
return propertyId;
} catch (NameException e) {
throw new RepositoryException(e);
}
}
use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.
the class RepositoryServiceImpl method getPath.
private Path getPath(ItemId itemId, SessionInfo sessionInfo, String workspaceName) throws RepositoryException {
if (itemId.denotesNode()) {
Path p = itemId.getPath();
String uid = itemId.getUniqueID();
if (uid == null) {
return p;
} else {
NamePathResolver resolver = getNamePathResolver(sessionInfo);
String uri = super.getItemUri(itemId, sessionInfo, workspaceName);
String rootUri = getRootURI(sessionInfo);
String jcrPath;
if (uri.startsWith(rootUri)) {
jcrPath = uri.substring(rootUri.length());
} else {
log.warn("ItemURI " + uri + " doesn't start with rootURI (" + rootUri + ").");
// fallback:
// calculated uri does not start with the rootURI
// -> search /jcr:root and start sub-string behind.
String rootSegment = Text.escapePath(JcrRemotingConstants.ROOT_ITEM_RESOURCEPATH);
jcrPath = uri.substring(uri.indexOf(rootSegment) + rootSegment.length());
}
jcrPath = Text.unescape(jcrPath);
return resolver.getQPath(jcrPath);
}
} else {
PropertyId pId = (PropertyId) itemId;
Path parentPath = getPath(pId.getParentId(), sessionInfo, workspaceName);
return getPathFactory().create(parentPath, pId.getName(), true);
}
}
Aggregations