use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionControlledItemCollection method update.
/**
* Perform an update on this resource. Depending on the format of the <code>updateInfo</code>
* this is translated to one of the following methods defined by the JCR API:
* <ul>
* <li>{@link Node#restore(javax.jcr.version.Version, boolean)}</li>
* <li>{@link Node#restore(javax.jcr.version.Version, String, boolean)}</li>
* <li>{@link Node#restoreByLabel(String, boolean)}</li>
* <li>{@link Node#update(String)}</li>
* </ul>
* <p>
* Limitation: note that the <code>MultiStatus</code> returned by this method
* will not list any nodes that have been removed due to an Uuid conflict.
*
* @param updateInfo
* @return
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)
*/
// TODO: with jcr the node must not be versionable in order to perform Node.update.
@Override
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
if (updateInfo == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatus ms = new MultiStatus();
try {
Node node = (Node) item;
Element udElem = updateInfo.getUpdateElement();
boolean removeExisting = DomUtil.hasChildElement(udElem, XML_REMOVEEXISTING, NAMESPACE);
// register eventListener in order to be able to report the modified resources.
EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
registerEventListener(el, node.getPath());
// perform the update/restore according to the update info
if (updateInfo.getVersionHref() != null) {
String[] hrefs = updateInfo.getVersionHref();
if (hrefs.length != 1) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body missing version href or containing multiple version hrefs.");
}
final String href = normalizeResourceHref(hrefs[0]);
String versionPath = getLocatorFromHref(href).getRepositoryPath();
String versionName = getItemName(versionPath);
String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);
if (relPath == null) {
// restore version by name
node.restore(versionName, removeExisting);
} else if (node.hasNode(relPath)) {
Version v = node.getNode(relPath).getVersionHistory().getVersion(versionName);
node.restore(v, relPath, removeExisting);
} else {
Version v = (Version) getRepositorySession().getNode(versionPath);
node.restore(v, relPath, removeExisting);
}
} else if (updateInfo.getLabelName() != null) {
String[] labels = updateInfo.getLabelName();
if (labels.length != 1) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: Multiple labels specified.");
}
node.restoreByLabel(labels[0], removeExisting);
} else if (updateInfo.getWorkspaceHref() != null) {
String href = normalizeResourceHref(obtainAbsolutePathFromUri(updateInfo.getWorkspaceHref()));
String workspaceName = getLocatorFromHref(href).getWorkspaceName();
node.update(workspaceName);
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body.");
}
// unregister the event listener again
unregisterEventListener(el);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
return ms;
}
use of org.apache.jackrabbit.webdav.DavException 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.DavException 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.DavException in project jackrabbit by apache.
the class DefaultItemResource method internalSetProperty.
/**
* Internal method that performs the setting or adding of properties
*
* @param property
* @throws DavException
* @see #setProperty(DavProperty)
* @see #alterProperties(List)
*/
private void internalSetProperty(DavProperty<?> property) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
Property prop = (Property) item;
int defaultType = prop.getType();
ValueFactory vfact = getRepositorySession().getValueFactory();
ValuesProperty vp = new ValuesProperty(property, defaultType, vfact);
if (property.getName().equals(JCR_VALUE)) {
prop.setValue(vp.getJcrValue(vp.getValueType(), vfact));
} else if (property.getName().equals(JCR_VALUES)) {
prop.setValue(vp.getJcrValues());
} else {
throw new DavException(DavServletResponse.SC_CONFLICT);
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class AbstractWebdavServlet method doAcl.
/**
* The ACL method
*
* @param request
* @param response
* @param resource
* @throws DavException
* @throws IOException
*/
protected void doAcl(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
if (!(resource instanceof AclResource)) {
response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
Document doc = request.getRequestDocument();
if (doc == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body.");
}
AclProperty acl = AclProperty.createFromXml(doc.getDocumentElement());
((AclResource) resource).alterAcl(acl);
}
Aggregations