use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class RootCollection method getMembers.
/**
* Returns an iterator over the member resources, which are all
* workspace resources available.
*
* @return members of this collection
* @see org.apache.jackrabbit.webdav.DavResource#getMembers()
*/
@Override
public DavResourceIterator getMembers() {
List<DavResource> memberList = new ArrayList();
try {
String[] wsNames = getRepositorySession().getWorkspace().getAccessibleWorkspaceNames();
for (String wsName : wsNames) {
String wspPath = "/" + wsName;
DavResourceLocator childLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), wspPath, wspPath);
memberList.add(createResourceFromLocator(childLoc));
}
} catch (RepositoryException e) {
log.error(e.getMessage());
} catch (DavException e) {
// should never occur
log.error(e.getMessage());
}
return new DavResourceIteratorImpl(memberList);
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class VersionControlledItemCollection method getVersionHistory.
/**
* Returns the {@link 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()
*/
@Override
public VersionHistoryResource getVersionHistory() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
VersionHistory vh = ((Node) item).getVersionHistory();
DavResourceLocator loc = getLocatorFromItem(vh);
return (VersionHistoryResource) createResourceFromLocator(loc);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class JcrRemotingServlet method doPost.
@Override
protected void doPost(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
if (canHandle(DavMethods.DAV_POST, webdavRequest, davResource)) {
// special remoting request: the defined parameters are exclusive
// and cannot be combined.
Session session = getRepositorySession(webdavRequest);
RequestData data = new RequestData(webdavRequest, getTempDirectory(getServletContext()));
String loc = null;
try {
String[] pValues;
// multi-read over POST
String[] includes = null;
if ((pValues = data.getParameterValues(PARAM_CLONE)) != null) {
loc = clone(session, pValues, davResource.getLocator());
} else if ((pValues = data.getParameterValues(PARAM_COPY)) != null) {
loc = copy(session, pValues, davResource.getLocator());
} else if (data.getParameterValues(PARAM_DIFF) != null) {
String targetPath = davResource.getLocator().getRepositoryPath();
processDiff(session, targetPath, data, protectedRemoveManager);
} else if ((pValues = data.getParameterValues(PARAM_INCLUDE)) != null && canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
includes = pValues;
} else {
String targetPath = davResource.getLocator().getRepositoryPath();
loc = modifyContent(session, targetPath, data, protectedRemoveManager);
}
// TODO: append entity
if (loc == null) {
webdavResponse.setStatus(HttpServletResponse.SC_OK);
if (includes != null) {
webdavResponse.setContentType("text/plain;charset=utf-8");
JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
DavResourceLocator locator = davResource.getLocator();
String path = locator.getRepositoryPath();
Node node = session.getNode(path);
int depth = ((WrappingLocator) locator).getDepth();
writeMultiple(writer, node, includes, depth);
}
} else {
webdavResponse.setHeader(DeltaVConstants.HEADER_LOCATION, loc);
webdavResponse.setStatus(HttpServletResponse.SC_CREATED);
}
} catch (RepositoryException e) {
log.warn(e.getMessage(), e);
throw new JcrDavException(e);
} catch (DiffException e) {
log.warn(e.getMessage());
Throwable cause = e.getCause();
if (cause instanceof RepositoryException) {
throw new JcrDavException((RepositoryException) cause);
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid diff format.");
}
} finally {
data.dispose();
}
} else {
super.doPost(webdavRequest, webdavResponse, davResource);
}
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class JcrRemotingServlet method buildLocationHref.
private static String buildLocationHref(Session s, String destPath, DavResourceLocator reqLocator) throws RepositoryException {
if (destPath != null) {
NodeIterator it = s.getRootNode().getNodes(destPath.substring(1));
Node n = null;
while (it.hasNext()) {
n = it.nextNode();
}
if (n != null) {
DavResourceLocator loc = reqLocator.getFactory().createResourceLocator(reqLocator.getPrefix(), reqLocator.getWorkspacePath(), n.getPath(), false);
return loc.getHref(true);
}
}
// unable to determine -> no location header sent back.
return null;
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class JcrRemotingServlet method doGet.
@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
// return json representation of the requested resource
DavResourceLocator locator = davResource.getLocator();
String path = locator.getRepositoryPath();
Session session = getRepositorySession(webdavRequest);
try {
Node node = session.getNode(path);
int depth = ((WrappingLocator) locator).getDepth();
webdavResponse.setContentType("text/plain;charset=utf-8");
webdavResponse.setStatus(DavServletResponse.SC_OK);
JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
if (includes == null) {
if (depth < BatchReadConfig.DEPTH_INFINITE) {
NodeType type = node.getPrimaryNodeType();
depth = brConfig.getDepth(type.getName());
}
writer.write(node, depth);
} else {
writeMultiple(writer, node, includes, depth);
}
} catch (PathNotFoundException e) {
// properties cannot be requested as json object.
throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
} catch (RepositoryException e) {
// should only get here if the item does not exist.
log.debug(e.getMessage());
throw new JcrDavException(e);
}
} else {
super.doGet(webdavRequest, webdavResponse, davResource);
}
}
Aggregations