use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class VersionControlledItemCollection method merge.
/**
* Merge the repository node represented by this resource according to the
* information present in the given {@link MergeInfo} object.
*
* @param mergeInfo
* @return <code>MultiStatus</code> recording all repository items modified
* by this merge call as well as the resources that a client must modify to
* complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
* @see Node#merge(String, boolean)
*/
//TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
if (mergeInfo == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatus ms = new MultiStatus();
try {
// NOTE: RFC requires that all modified resources are reported in the
// multistatus response. this doesn't work however with the remoting
// there is no way to distinguish the 'failedId's from any other
// resources that got modified by this merge operation -> omitted.
// todo: RFC allows multiple href elements inside the DAV:source element
String workspaceName = getLocatorFromHref(mergeInfo.getSourceHrefs()[0]).getWorkspaceName();
String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
boolean isShallow = "0".equals(depth);
NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
// add resources to the multistatus, that failed to be merged
while (failed.hasNext()) {
Node failedNode = failed.nextNode();
DavResourceLocator loc = getLocatorFromItem(failedNode);
DavResource res = createResourceFromLocator(loc);
ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
return ms;
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class LocateByUuidReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
// delegate basic validation to super class
super.init(resource, info);
// make also sure, the info contains a DAV:href child element
if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:locate-by-uuid element must at least contain a single DAV:href child.");
}
// immediately build the final multistatus element
try {
Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
String uuid = DomUtil.getTextTrim(hrefElem);
DavResourceLocator resourceLoc = resource.getLocator();
Node n = getRepositorySession().getNodeByUUID(uuid);
DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath(), false);
DavResource locatedResource = resource.getFactory().createResource(loc, resource.getSession());
ms = new MultiStatus();
ms.addResourceProperties(locatedResource, info.getPropertyNameSet(), info.getDepth());
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class JcrPrivilegeReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
// delegate basic validation to super class
super.init(resource, info);
// make also sure, the info contains a DAV:href child element
if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:privileges element must at least contain a single DAV:href child.");
}
// immediately build the final multistatus element
Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
String href = DomUtil.getTextTrim(hrefElem);
// TODO: we should check whether the authority component matches
href = obtainAbsolutePathFromUri(href);
DavResourceLocator resourceLoc = resource.getLocator();
DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), href);
// immediately build the final multistatus element
addResponses(loc);
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class DavResourceImpl method getCollection.
/**
* @see DavResource#getCollection()
*/
public DavResource getCollection() {
DavResource parent = null;
if (getResourcePath() != null && !getResourcePath().equals("/")) {
String parentPath = Text.getRelativeParent(getResourcePath(), 1);
if (parentPath.equals("")) {
parentPath = "/";
}
DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), parentPath);
try {
parent = factory.createResource(parentloc, session);
} catch (DavException e) {
// should not occur
}
}
return parent;
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class LocatorFactoryImplExTest method testCollectionNameEqualsWorkspaceName.
/**
* Test for issue https://issues.apache.org/jira/browse/JCR-1679: An top
* level resource (node directly below the root) whose name equals the
* workspace name results in wrong collection behaviour (garbeled locator
* of child resources).
*/
public void testCollectionNameEqualsWorkspaceName() {
String prefix = "http://localhost:8080/jackrabbit/repository";
String workspacePath = "/default";
String nodePath = "/default/another";
DavResourceLocator locator = factory.createResourceLocator(prefix, workspacePath, nodePath, false);
assertTrue(locator.getHref(true).indexOf("/default/default") > 0);
DavResourceLocator locator2 = factory.createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), locator.getResourcePath());
assertEquals(locator, locator2);
assertEquals(nodePath, locator2.getRepositoryPath());
}
Aggregations