use of org.apache.jackrabbit.webdav.property.DavPropertySet 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.webdav.property.DavPropertySet in project jackrabbit by apache.
the class ValueLoader method loadType.
int loadType(String uri) throws RepositoryException, IOException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DavConstants.DEPTH_0);
HttpResponse response = client.execute(request, context);
request.checkSuccess(response);
MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (responses.length == 1) {
DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
if (type != null) {
return PropertyType.valueFromName(type.getValue().toString());
} else {
throw new RepositoryException("Internal error. Cannot retrieve property type at " + uri);
}
} else {
throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + uri);
}
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet 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.webdav.property.DavPropertySet 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.webdav.property.DavPropertySet in project jackrabbit by apache.
the class URIResolverImpl method buildNodeId.
protected NodeId buildNodeId(NodeId parentId, String baseUri, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException {
IdURICache cache = getCache(workspaceName);
NodeId nodeId;
DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
String uniqueID = service.getUniqueID(propSet);
if (uniqueID != null) {
nodeId = service.getIdFactory().createNodeId(uniqueID);
} else {
Name qName = service.getQName(propSet, resolver);
if (NameConstants.ROOT.equals(qName)) {
nodeId = service.getIdFactory().createNodeId((String) null, service.getPathFactory().getRootPath());
} else {
int index = service.getIndex(propSet);
nodeId = service.getIdFactory().createNodeId(parentId, service.getPathFactory().create(qName, index));
}
}
// cache
cache.add(resolve(baseUri, response.getHref()), nodeId);
return nodeId;
}
Aggregations