use of org.apache.jackrabbit.server.util.RequestData 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);
}
}
Aggregations