use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionItemCollection 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 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 = getLocatorFromItem(vh);
return (VersionHistoryResource) createResourceFromLocator(loc);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionHistoryResourceImpl method removeMember.
/**
* Removing a version resource is achieved by calling <code>removeVersion</code>
* on the versionhistory item this version belongs to.
*
* @throws DavException if the version does not exist or if an error occurs
* while deleting.
* @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
*/
@Override
public void removeMember(DavResource member) throws DavException {
if (exists()) {
VersionHistory versionHistory = (VersionHistory) getNode();
try {
String itemPath = member.getLocator().getRepositoryPath();
// Retrieve the last segment of the given path and removes the index if present.
if (itemPath == null) {
throw new IllegalArgumentException("Cannot retrieve name from a 'null' item path.");
}
String name = Text.getName(itemPath);
// remove index
if (name.endsWith("]")) {
name = name.substring(0, name.lastIndexOf('['));
}
versionHistory.removeVersion(name);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
} else {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionHistoryResourceImpl method getMembers.
// --------------------------------------------------------< DavResource >---
/**
* Show all versions of this history as members.
*
* @return
* @see DavResource#getMembers()
*/
@Override
public DavResourceIterator getMembers() {
ArrayList<DavResource> list = new ArrayList<DavResource>();
if (exists() && isCollection()) {
try {
// only display versions as members of the vh. the jcr:versionLabels
// node is an internal structure.
VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
while (it.hasNext()) {
// omit item filter here. if the version history is visible
// its versions should be visible as well.
Version v = it.nextVersion();
DavResourceLocator vhLocator = getLocator();
DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
DavResource childRes = getFactory().createResource(resourceLocator, getSession());
list.add(childRes);
}
} catch (RepositoryException e) {
// should not occur
log.error("Unexpected error", e);
} catch (DavException e) {
// should not occur
log.error("Unexpected error", e);
}
}
return new DavResourceIteratorImpl(list);
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionHistoryResourceImpl method getVersions.
// ---------------------------------------------< VersionHistoryResource >---
/**
* Return an array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
* present in the underlying JCR version history.
*
* @return array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
* present in the underlying JCR version history.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
*/
public VersionResource[] getVersions() throws DavException {
try {
VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
ArrayList<VersionResource> l = new ArrayList<VersionResource>();
while (vIter.hasNext()) {
DavResourceLocator versionLoc = getLocatorFromNode(vIter.nextVersion());
DavResource vr = createResourceFromLocator(versionLoc);
if (vr instanceof VersionResource) {
l.add((VersionResource) vr);
} else {
// severe error since resource factory doesn't behave correctly.
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
return l.toArray(new VersionResource[l.size()]);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class LocateCorrespondingNodeReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
// general validation checks
super.init(resource, info);
// specific for this report: a workspace href must be provided
Element workspace = info.getContentElement(DeltaVConstants.WORKSPACE.getName(), DeltaVConstants.WORKSPACE.getNamespace());
String workspaceHref = normalizeResourceHref(DomUtil.getChildTextTrim(workspace, DavConstants.XML_HREF, DavConstants.NAMESPACE));
if (workspaceHref == null || "".equals(workspaceHref)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Request body must define the href of a source workspace");
}
// retrieve href of the corresponding resource in the other workspace
try {
this.correspHref = getCorrespondingResourceHref(resource, getRepositorySession(), workspaceHref);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
Aggregations