if (cache.containsItemId(itemId)) {
return cache.getUri(itemId);
} else {
StringBuffer uriBuffer = new StringBuffer();
Path path = itemId.getPath();
String uniqueID = itemId.getUniqueID();
// resolver uuid part
if (uniqueID != null) {
ItemId uuidId = (path == null) ? itemId : service.getIdFactory().createNodeId(uniqueID);
if (path != null & cache.containsItemId(uuidId)) {
// append uri of parent node, that is already cached
uriBuffer.append(cache.getUri(uuidId));
} else {
// try to request locate-by-uuid report to build the uri
ReportInfo rInfo = new ReportInfo(JcrRemotingConstants.REPORT_LOCATE_BY_UUID, ItemResourceConstants.NAMESPACE);
rInfo.setContentElement(DomUtil.hrefToXml(uniqueID, domFactory));
ReportMethod rm = null;
try {
String wspUri = getWorkspaceUri(workspaceName);
rm = new ReportMethod(wspUri, rInfo);
service.getClient(sessionInfo).executeMethod(rm);
MultiStatus ms = rm.getResponseBodyAsMultiStatus();
if (ms.getResponses().length == 1) {
uriBuffer.append(ms.getResponses()[0].getHref());
cache.add(ms.getResponses()[0].getHref(), uuidId);
} else {
throw new ItemNotFoundException("Cannot identify item with uniqueID " + uniqueID);
}
} catch (IOException e) {
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (rm != null) {
rm.releaseConnection();
}
}
}
} else {
// start build uri from root-item
uriBuffer.append(getRootItemUri(workspaceName));
}
// resolve relative-path part unless it denotes the root-item
if (path != null && !path.denotesRoot()) {
String jcrPath = service.getNamePathResolver(sessionInfo).getJCRPath(path);
if (!path.isAbsolute() && !uriBuffer.toString().endsWith("/")) {
uriBuffer.append("/");
}
uriBuffer.append(Text.escapePath(jcrPath));
}
String itemUri = uriBuffer.toString();