use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class AbstractItemResource method getWorkspaceHref.
/**
* @return href of the workspace or <code>null</code> if this resource
* does not represent a repository item.
*
* @see AbstractResource#getWorkspaceHref()
*/
@Override
protected String getWorkspaceHref() {
String workspaceHref = null;
DavResourceLocator locator = getLocator();
if (locator != null && locator.getWorkspacePath() != null) {
String wspPath = locator.getWorkspacePath();
DavResourceLocator wspLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), wspPath, wspPath);
workspaceHref = wspLocator.getHref(true);
}
log.debug(workspaceHref);
return workspaceHref;
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class AbstractItemResource method move.
/**
* Moves the underlying repository item to the indicated destination.
*
* @param destination
* @throws DavException
* @see DavResource#move(DavResource)
* @see javax.jcr.Session#move(String, String)
*/
@Override
public void move(DavResource destination) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
DavResourceLocator destLocator = destination.getLocator();
if (!getLocator().isSameWorkspace(destLocator)) {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
try {
String itemPath = getLocator().getRepositoryPath();
String destItemPath = destination.getLocator().getRepositoryPath();
if (getTransactionId() == null) {
// if not part of a transaction directly import on workspace
getRepositorySession().getWorkspace().move(itemPath, destItemPath);
} else {
// changes will not be persisted unless the tx is completed.
getRepositorySession().move(itemPath, destItemPath);
}
// no use in calling 'complete' that would fail for a moved item anyway.
} catch (PathNotFoundException e) {
// according to rfc 2518
throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage());
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
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());
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class VersionControlledResourceImpl method getVersionHistory.
/**
* Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
* If the node is not versionable an exception is thrown.
*
* @return the {@link VersionHistoryResource} associated with this resource.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
* @see javax.jcr.Node#getVersionHistory()
*/
public VersionHistoryResource getVersionHistory() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
if (!isVersionControlled()) {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
try {
VersionHistory vh = getNode().getVersionHistory();
DavResourceLocator loc = getLocatorFromNode(vh);
DavResource vhr = createResourceFromLocator(loc);
if (vhr instanceof VersionHistoryResource) {
return (VersionHistoryResource) vhr;
} else {
// severe error since resource factory doesn't behave correctly.
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
Aggregations