use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class RepositoryServiceImpl method getPropertyInfo.
/**
* @see RepositoryService#getPropertyInfo(SessionInfo, PropertyId)
*/
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
Path p = getPath(propertyId, sessionInfo);
String uri = getURI(p, sessionInfo);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, LAZY_PROPERTY_NAME_SET, DavConstants.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 PropertyInfo. No such property " + uri);
}
MultiStatusResponse mresponse = mresponses[0];
DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
int propertyType = PropertyType.valueFromName(props.get(JCR_TYPE).getValue().toString());
if (propertyType == PropertyType.BINARY) {
DavProperty<?> lengthsProp = props.get(JCR_LENGTHS);
if (lengthsProp != null) {
// multivalued binary property
long[] lengths = ValueUtil.lengthsFromXml(lengthsProp.getValue());
QValue[] qValues = new QValue[lengths.length];
for (int i = 0; i < lengths.length; i++) {
qValues[i] = getQValueFactory(sessionInfo).create(lengths[i], uri, i);
}
return new PropertyInfoImpl(propertyId, p, propertyType, qValues);
} else {
// single valued binary property
long length = Long.parseLong(props.get(JCR_LENGTH).getValue().toString());
QValue qValue = getQValueFactory(sessionInfo).create(length, uri, QValueFactoryImpl.NO_INDEX);
return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
}
} else if (props.contains(JCR_GET_STRING)) {
// single valued non-binary property
Object v = props.get(JCR_GET_STRING).getValue();
String str = (v == null) ? "" : v.toString();
QValue qValue = ValueFormat.getQValue(str, propertyType, getNamePathResolver(sessionInfo), getQValueFactory(sessionInfo));
return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
} else {
// didn't expose the JCR_GET_STRING dav property.
return super.getPropertyInfo(sessionInfo, propertyId);
}
} catch (IOException e) {
log.error("Internal error while retrieving ItemInfo.", e);
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class URIResolverImpl method getItemUri.
String getItemUri(ItemId itemId, String workspaceName, SessionInfo sessionInfo) throws RepositoryException {
IdURICache cache = getCache(workspaceName);
// check if uri is available from cache
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));
HttpReport request = null;
try {
String wspUri = getWorkspaceUri(workspaceName);
request = new HttpReport(wspUri, rInfo);
HttpResponse response = service.executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatus ms = request.getResponseBodyAsMultiStatus(response);
if (ms.getResponses().length == 1) {
String absoluteUri = resolve(wspUri, ms.getResponses()[0].getHref());
uriBuffer.append(absoluteUri);
cache.add(absoluteUri, 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 (request != null) {
request.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();
if (!cache.containsItemId(itemId)) {
cache.add(itemUri, itemId);
}
return itemUri;
}
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class ItemInfoJsonHandler method endArray.
public void endArray() throws IOException {
try {
if (propertyType == PropertyType.UNDEFINED) {
if (propValues.isEmpty()) {
// make sure that type is set for mv-properties with empty value array.
propertyType = vFactory.retrieveType(getValueURI());
} else {
propertyType = propValues.get(0).getType();
}
}
// create multi-valued property info
NodeInfoImpl parent = getCurrentNodeInfo();
Path p = pFactory.create(parent.getPath(), name, true);
PropertyId id = idFactory.createPropertyId(parent.getId(), name);
PropertyInfoImpl propInfo = new PropertyInfoImpl(id, p, propertyType, propValues.toArray(new QValue[propValues.size()]));
propInfo.checkCompleted();
getCurrentPropInfos().add(propInfo);
} catch (RepositoryException e) {
throw new IOException(e.getMessage());
} finally {
// reset property-related handler state
propertyType = PropertyType.UNDEFINED;
multiValuedProperty = false;
propValues.clear();
name = null;
}
}
use of org.apache.jackrabbit.spi.Path 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);
}
}
use of org.apache.jackrabbit.spi.Path in project jackrabbit by apache.
the class LockManagerImpl method externalLock.
/**
* {@inheritDoc}
*/
public void externalLock(NodeId nodeId, boolean isDeep, String lockOwner) throws RepositoryException {
acquire();
try {
Path path = getPath(sysSession, nodeId);
// create lock token
InternalLockInfo info = new InternalLockInfo(nodeId, false, isDeep, lockOwner, Long.MAX_VALUE);
info.setLive(true);
lockMap.put(path, info);
save();
} finally {
release();
}
}
Aggregations