use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class LocateCorrespondingNodeReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
// general validation checks
super.init(resource, info);
// specific for this report: a workspace href must be provided
Element workspace = info.getContentElement(DeltaVConstants.WORKSPACE.getName(), DeltaVConstants.WORKSPACE.getNamespace());
String workspaceHref = normalizeResourceHref(DomUtil.getChildTextTrim(workspace, DavConstants.XML_HREF, DavConstants.NAMESPACE));
if (workspaceHref == null || "".equals(workspaceHref)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Request body must define the href of a source workspace");
}
// retrieve href of the corresponding resource in the other workspace
try {
this.correspHref = getCorrespondingResourceHref(resource, getRepositorySession(), workspaceHref);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class DavResourceImpl method alterProperty.
private void alterProperty(PropEntry prop) throws DavException {
if (isLocked(this)) {
throw new DavException(DavServletResponse.SC_LOCKED);
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
List<? extends PropEntry> list = Collections.singletonList(prop);
alterProperties(list);
Map<? extends PropEntry, ?> failure = config.getPropertyManager().alterProperties(getPropertyImportContext(list), isCollection());
if (failure.isEmpty()) {
node.save();
} else {
node.refresh(false);
// TODO: retrieve specific error from failure-map
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} catch (RepositoryException e) {
// revert any changes made so far
JcrDavException je = new JcrDavException(e);
try {
node.refresh(false);
} catch (RepositoryException re) {
// should not happen...
}
throw je;
}
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.
the class VersionControlledResourceImpl method checkin.
/**
* Calls {@link javax.jcr.Node#checkin()} on the underlying repository node.
*
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkin()
*/
public String checkin() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
if (!isVersionControlled()) {
throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
}
try {
Version v = getNode().checkin();
String versionHref = getLocatorFromNode(v).getHref(false);
return versionHref;
} catch (RepositoryException e) {
// UnsupportedRepositoryException should not occur
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.jcr.JcrDavException 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.jcr.JcrDavException 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