use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class DefaultHandler method delete.
/**
* @see DeleteHandler#delete(DeleteContext, DavResource)
*/
public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException {
try {
String itemPath = member.getLocator().getRepositoryPath();
Item item = deleteContext.getSession().getItem(itemPath);
if (item instanceof Node) {
((Node) item).removeShare();
} else {
item.remove();
}
deleteContext.getSession().save();
log.debug("default handler deleted {}", member.getResourcePath());
return true;
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class DavResourceImpl method lock.
/**
* @see DavResource#lock(LockInfo)
*/
public ActiveLock lock(LockInfo lockInfo) throws DavException {
ActiveLock lock = null;
if (isLockable(lockInfo.getType(), lockInfo.getScope())) {
// TODO: deal with existing locks, that may have been created, before the node was jcr-lockable...
if (isJcrLockable()) {
try {
javax.jcr.lock.LockManager lockMgr = node.getSession().getWorkspace().getLockManager();
long timeout = lockInfo.getTimeout();
if (timeout == LockInfo.INFINITE_TIMEOUT) {
timeout = Long.MAX_VALUE;
} else {
timeout = timeout / 1000;
}
// try to execute the lock operation
Lock jcrLock = lockMgr.lock(node.getPath(), lockInfo.isDeep(), false, timeout, lockInfo.getOwner());
if (jcrLock != null) {
lock = new JcrActiveLock(jcrLock);
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
} else {
// create a new webdav lock
lock = lockManager.createLock(lockInfo, this);
}
} else {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Unsupported lock type or scope.");
}
return lock;
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class DavResourceImpl method alterProperties.
public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
if (isLocked(this)) {
throw new DavException(DavServletResponse.SC_LOCKED);
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
try {
Map<? extends PropEntry, ?> failures = config.getPropertyManager().alterProperties(getPropertyImportContext(changeList), isCollection());
if (failures.isEmpty()) {
// save all changes together (reverted in case this fails)
node.save();
} else {
// set/remove of at least a single prop failed: undo modifications.
node.refresh(false);
}
/* loop over list of properties/names that were successfully altered
and them to the multistatus response respecting the result of the
complete action. in case of failure set the status to 'failed-dependency'
in order to indicate, that altering those names/properties would
have succeeded, if no other error occured.*/
for (PropEntry propEntry : changeList) {
int statusCode;
if (failures.containsKey(propEntry)) {
Object error = failures.get(propEntry);
statusCode = (error instanceof RepositoryException) ? new JcrDavException((RepositoryException) error).getErrorCode() : DavServletResponse.SC_INTERNAL_SERVER_ERROR;
} else {
statusCode = (failures.isEmpty()) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;
}
if (propEntry instanceof DavProperty) {
msr.add(((DavProperty<?>) propEntry).getName(), statusCode);
} else {
msr.add((DavPropertyName) propEntry, statusCode);
}
}
return msr;
} catch (RepositoryException e) {
// revert any changes made so far an throw exception
try {
node.refresh(false);
} catch (RepositoryException re) {
// should not happen
}
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class SubscriptionManagerImpl method registerSubscription.
/**
* Register the event listener defined by the given subscription to the
* repository's observation manager.
*
* @param subscription
* @param resource
* @throws DavException
*/
private void registerSubscription(SubscriptionImpl subscription, ObservationResource resource) throws DavException {
try {
Session session = getRepositorySession(resource);
ObservationManager oMgr = session.getWorkspace().getObservationManager();
String itemPath = subscription.getLocator().getRepositoryPath();
oMgr.addEventListener(subscription, subscription.getJcrEventTypes(), itemPath, subscription.isDeep(), subscription.getUuidFilters(), subscription.getNodetypeNameFilters(), subscription.isNoLocal());
} catch (RepositoryException e) {
log.error("Unable to register eventlistener: " + e.getMessage());
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class SubscriptionManagerImpl method unregisterSubscription.
/**
* Remove the event listener defined by the specified subscription from
* the repository's observation manager and clean up the references present
* on the <code>DavSession</code>.
*
* @param subscription
* @param resource
* @throws DavException
*/
private void unregisterSubscription(SubscriptionImpl subscription, ObservationResource resource) throws DavException {
try {
Session session = getRepositorySession(resource);
session.getWorkspace().getObservationManager().removeEventListener(subscription);
String sId = subscription.getSubscriptionId();
// clean up any references
subscriptions.remove(sId);
resource.getSession().removeReference(sId);
} catch (RepositoryException e) {
log.error("Unable to remove eventlistener: " + e.getMessage());
throw new JcrDavException(e);
}
}
Aggregations