use of org.apache.jackrabbit.webdav.DavException 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);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class DavResourceImpl method bind.
/**
* @see BindableResource#rebind(DavResource, DavResource)
*/
public void bind(DavResource collection, DavResource newBinding) throws DavException {
if (!exists()) {
//DAV:bind-source-exists
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
}
if (isLocked(collection)) {
//DAV:locked-update-allowed?
throw new DavException(DavServletResponse.SC_LOCKED);
}
if (isFilteredResource(newBinding)) {
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
checkSameWorkspace(collection.getLocator());
try {
if (!node.isNodeType(MIX_SHAREABLE)) {
if (!node.canAddMixin(MIX_SHAREABLE)) {
//DAV:binding-allowed
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
}
node.addMixin(MIX_SHAREABLE);
node.save();
}
Workspace workspace = session.getRepositorySession().getWorkspace();
workspace.clone(workspace.getName(), node.getPath(), newBinding.getLocator().getRepositoryPath(), false);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class DavResourceImpl method getMembers.
/**
* @see DavResource#getMembers()
*/
public DavResourceIterator getMembers() {
ArrayList<DavResource> list = new ArrayList<DavResource>();
if (exists() && isCollection()) {
try {
NodeIterator it = node.getNodes();
while (it.hasNext()) {
Node n = it.nextNode();
if (!isFilteredItem(n)) {
DavResourceLocator resourceLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), n.getPath(), false);
DavResource childRes = factory.createResource(resourceLocator, session);
list.add(childRes);
} else {
log.debug("Filtered resource '" + n.getName() + "'.");
}
}
} catch (RepositoryException e) {
// should not occur
} catch (DavException e) {
// should not occur
}
}
return new DavResourceIteratorImpl(list);
}
use of org.apache.jackrabbit.webdav.DavException 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.DavException in project jackrabbit by apache.
the class DavResourceImpl method addMember.
/**
* Adds a new member to this resource.
*
* @see DavResource#addMember(DavResource, org.apache.jackrabbit.webdav.io.InputContext)
*/
public void addMember(DavResource member, InputContext inputContext) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_CONFLICT);
}
if (isLocked(this) || isLocked(member)) {
throw new DavException(DavServletResponse.SC_LOCKED);
}
try {
// item or if the new resource would be filtered out
if (isFilteredResource(member) || node.getDefinition().isProtected()) {
log.debug("Forbidden to add member: " + member.getDisplayName());
throw new DavException(DavServletResponse.SC_FORBIDDEN);
}
String memberName = Text.getName(member.getLocator().getRepositoryPath());
ImportContext ctx = getImportContext(inputContext, memberName);
if (!config.getIOManager().importContent(ctx, member)) {
// any changes should have been reverted in the importer
throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
}
// persist changes after successful import
node.save();
} catch (RepositoryException e) {
log.error("Error while importing resource: " + e.toString());
throw new JcrDavException(e);
} catch (IOException e) {
log.error("Error while importing resource: " + e.toString());
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
Aggregations