use of org.apache.jackrabbit.webdav.property.HrefProperty 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.HrefProperty 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.webdav.property.HrefProperty in project jackrabbit by apache.
the class VersionHistoryResourceImpl method initProperties.
// --------------------------------------------------------------------------
/**
* Fill the property set for this resource.
*/
@Override
protected void initProperties() {
if (!propsInitialized) {
super.initProperties();
// change resource type defined by default item collection
properties.add(new ResourceType(new int[] { ResourceType.COLLECTION, ResourceType.VERSION_HISTORY }));
// required root-version property for version-history resource
try {
String rootVersionHref = getLocatorFromNode(((VersionHistory) getNode()).getRootVersion()).getHref(false);
properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, false));
} catch (RepositoryException e) {
log.error(e.getMessage());
}
// required, protected version-set property for version-history resource
try {
VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
ArrayList<Version> l = new ArrayList<Version>();
while (vIter.hasNext()) {
l.add(vIter.nextVersion());
}
properties.add(getHrefProperty(VersionHistoryResource.VERSION_SET, l.toArray(new Version[l.size()]), true, false));
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
}
use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.
the class VersionControlledResourceImpl method initProperties.
/**
* Fill the property set for this resource.
* @see DavResourceImpl#initProperties()
*/
@Override
protected void initProperties() {
if (!propsInitialized) {
super.initProperties();
if (isVersionControlled()) {
Node n = getNode();
// properties defined by RFC 3253 for version-controlled resources
try {
// DAV:version-history (computed)
String vhHref = getLocatorFromNode(n.getVersionHistory()).getHref(true);
properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));
// DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.
properties.add(new DefaultDavProperty(AUTO_VERSION, null, true));
// baseVersion -> used for DAV:checked-out or DAV:checked-in
String baseVHref = getLocatorFromNode(n.getBaseVersion()).getHref(false);
if (n.isCheckedOut()) {
// DAV:predecessors property
if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
Value[] pv = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
Node[] predecessors = new Node[pv.length];
for (int i = 0; i < pv.length; i++) {
predecessors[i] = n.getSession().getNodeByIdentifier(pv[i].getString());
}
properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, predecessors, true, false));
}
// DAV:checked-out property (protected)
properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));
} else {
// DAV:checked-in property (protected)
properties.add(new HrefProperty(CHECKED_IN, baseVHref, true));
}
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
}
}
use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.
the class VersionResourceImpl method initProperties.
/**
* Fill the property set for this resource.
*/
@Override
protected void initProperties() {
if (!propsInitialized) {
super.initProperties();
Version v = (Version) getNode();
try {
String creationDate = HttpDateFormat.creationDateFormat().format(v.getCreated().getTime());
// replace dummy creation date from default collection
properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE, creationDate));
// required, protected DAV:version-name property
properties.add(new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true));
// required, protected DAV:label-name-set property
String[] labels = getVersionHistoryItem().getVersionLabels(v);
properties.add(new LabelSetProperty(labels));
// required DAV:predecessor-set (protected) and DAV:successor-set (computed) properties
properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true, false));
properties.add(getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true, false));
// required DAV:version-history (computed) property
String vhHref = getLocatorFromNode(getVersionHistoryItem()).getHref(true);
properties.add(new HrefProperty(VersionResource.VERSION_HISTORY, vhHref, true));
// required DAV:checkout-set (computed) property
PropertyIterator it = v.getReferences();
List<Node> nodeList = new ArrayList<Node>();
while (it.hasNext()) {
Property p = it.nextProperty();
if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
Node n = p.getParent();
if (n.isCheckedOut()) {
nodeList.add(n);
}
}
}
properties.add(getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true, false));
} catch (RepositoryException e) {
log.error(e.getMessage());
}
}
}
Aggregations