use of org.apache.jackrabbit.webdav.DavResource 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.DavResource 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.DavResource in project jackrabbit by apache.
the class ResourceFactoryImpl method createResource.
/**
* Create a new <code>DavResource</code> from the given locator and
* request.
*
* @param locator
* @param request
* @param response
* @return DavResource
* @throws DavException
* @see DavResourceFactory#createResource(DavResourceLocator,
* DavServletRequest, DavServletResponse)
*/
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
try {
Node node = getNode(request.getDavSession(), locator);
DavResource resource;
if (node == null) {
log.debug("Creating resource for non-existing repository node.");
boolean isCollection = DavMethods.isCreateCollectionRequest(request);
resource = createNullResource(locator, request.getDavSession(), isCollection);
} else {
resource = createResource(node, locator, request.getDavSession());
}
resource.addLockManager(lockMgr);
return resource;
} catch (RepositoryException e) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class ResourceFactoryImpl method createResource.
/**
* Tries to retrieve the repository item defined by the locator's resource
* path and build the corresponding WebDAV resource. If the repository
* supports the versioning option different resources are created for
* version, versionhistory and common nodes.
*
* @param node
* @param locator
* @param session
* @return
* @throws DavException
*/
private DavResource createResource(Node node, DavResourceLocator locator, DavSession session) throws DavException {
JcrDavSession.checkImplementation(session);
JcrDavSession sessionImpl = (JcrDavSession) session;
DavResource resource;
if (versioningSupported(sessionImpl.getRepositorySession())) {
// create special resources for Version and VersionHistory
if (node instanceof Version) {
resource = new VersionResourceImpl(locator, this, sessionImpl, resourceConfig, node);
} else if (node instanceof VersionHistory) {
resource = new VersionHistoryResourceImpl(locator, this, sessionImpl, resourceConfig, node);
} else {
resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, node);
}
} else {
resource = new DavResourceImpl(locator, this, session, resourceConfig, node);
}
return resource;
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doMkActivity.
/**
* The MKACTIVITY method
*
* @param request
* @param response
* @param resource
* @throws DavException
* @throws IOException
*/
protected void doMkActivity(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
if (resource.exists()) {
AbstractWebdavServlet.log.warn("Unable to create activity: A resource already exists at the request-URL " + request.getRequestURL());
response.sendError(DavServletResponse.SC_FORBIDDEN);
return;
}
DavResource parentResource = resource.getCollection();
if (parentResource == null || !parentResource.exists() || !parentResource.isCollection()) {
// parent does not exist or is not a collection
response.sendError(DavServletResponse.SC_CONFLICT);
return;
}
// TODO: improve. see http://issues.apache.org/jira/browse/JCR-394
if (!parentResource.getComplianceClass().contains(DavCompliance.ACTIVITY)) {
response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
if (!(resource instanceof ActivityResource)) {
AbstractWebdavServlet.log.error("Unable to create activity: ActivityResource expected");
response.sendError(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// try to add the new activity resource
parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
// Note: mandatory cache control header has already been set upon response creation.
response.setStatus(DavServletResponse.SC_CREATED);
}
Aggregations