use of org.apache.jackrabbit.webdav.DavException 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.DavException 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.DavException in project jackrabbit by apache.
the class DavSessionProviderImpl method attachSession.
/**
* Acquires a DavSession. Upon success, the WebdavRequest will
* reference that session.
*
* A session will not be available if an exception is thrown.
*
* @param request
* @throws org.apache.jackrabbit.webdav.DavException if a problem occurred while obtaining the session
* @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
*/
public boolean attachSession(WebdavRequest request) throws DavException {
try {
// retrieve the workspace name
String workspaceName = request.getRequestLocator().getWorkspaceName();
// empty workspaceName rather means default -> must be 'null'
if (workspaceName != null && "".equals(workspaceName)) {
workspaceName = null;
}
// login to repository
Session repSession = sesProvider.getSession(request, repository, workspaceName);
if (repSession == null) {
log.debug("Could not to retrieve a repository session.");
return false;
}
DavSession ds = new DavSessionImpl(repSession);
log.debug("Attaching session '" + ds + "' to request '" + request + "'");
request.setDavSession(ds);
return true;
} catch (NoSuchWorkspaceException e) {
// which seems not appropriate here
throw new JcrDavException(e, DavServletResponse.SC_NOT_FOUND);
} catch (RepositoryException e) {
throw new JcrDavException(e);
} catch (ServletException e) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of org.apache.jackrabbit.webdav.DavException 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);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionControlledResourceImpl method addVersionControl.
//------------------------------------------< VersionControlledResource >---
/**
* Adds version control to this resource. If the resource is already under
* version control, this method has no effect. If this resource is a Collection
* resource this method fails with {@link DavServletResponse#SC_METHOD_NOT_ALLOWED}.
*
* @throws org.apache.jackrabbit.webdav.DavException if this resource does not
* exist yet, is a collection or if an error occurs while making the
* underlying node versionable.
* @see org.apache.jackrabbit.webdav.version.VersionableResource#addVersionControl()
*/
public void addVersionControl() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
if (isCollection()) {
// the underlying node was / could be made jcr versionable.
throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
}
if (!isVersionControlled()) {
Node item = getNode();
try {
item.addMixin(JcrConstants.MIX_VERSIONABLE);
item.save();
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
// else: is already version controlled -> ignore
}
Aggregations