use of org.apache.jackrabbit.webdav.jcr.JcrDavException 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.jcr.JcrDavException 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
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException 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.jcr.JcrDavException in project jackrabbit by apache.
the class VersionResourceImpl method getVersionHistory.
/**
* Returns the {@link VersionHistory} associated with the repository version.
* Note: in contrast to a versionable node, the version history of a version
* item is always represented by its nearest ancestor.
*
* @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
* @see javax.jcr.Item#getParent()
*/
public VersionHistoryResource getVersionHistory() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
VersionHistory vh = getVersionHistoryItem();
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