use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class DavResourceImpl method alterProperties.
public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
if (isLocked(this)) {
throw new DavException(DavServletResponse.SC_LOCKED);
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
try {
Map<? extends PropEntry, ?> failures = config.getPropertyManager().alterProperties(getPropertyImportContext(changeList), isCollection());
if (failures.isEmpty()) {
// save all changes together (reverted in case this fails)
node.save();
} else {
// set/remove of at least a single prop failed: undo modifications.
node.refresh(false);
}
/* loop over list of properties/names that were successfully altered
and them to the multistatus response respecting the result of the
complete action. in case of failure set the status to 'failed-dependency'
in order to indicate, that altering those names/properties would
have succeeded, if no other error occured.*/
for (PropEntry propEntry : changeList) {
int statusCode;
if (failures.containsKey(propEntry)) {
Object error = failures.get(propEntry);
statusCode = (error instanceof RepositoryException) ? new JcrDavException((RepositoryException) error).getErrorCode() : DavServletResponse.SC_INTERNAL_SERVER_ERROR;
} else {
statusCode = (failures.isEmpty()) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;
}
if (propEntry instanceof DavProperty) {
msr.add(((DavProperty<?>) propEntry).getName(), statusCode);
} else {
msr.add((DavPropertyName) propEntry, statusCode);
}
}
return msr;
} catch (RepositoryException e) {
// revert any changes made so far an throw exception
try {
node.refresh(false);
} catch (RepositoryException re) {
// should not happen
}
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException 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.DavException in project jackrabbit by apache.
the class RepositoryServiceImpl method addVersionLabel.
@Override
public void addVersionLabel(SessionInfo sessionInfo, NodeId versionHistoryId, NodeId versionId, Name label, boolean moveLabel) throws RepositoryException {
HttpLabel request = null;
try {
String uri = getItemUri(versionId, sessionInfo);
String strLabel = getNamePathResolver(sessionInfo).getJCRName(label);
request = new HttpLabel(uri, new LabelInfo(strLabel, moveLabel ? LabelInfo.TYPE_SET : LabelInfo.TYPE_ADD));
initMethod(request, sessionInfo, !isUnLockMethod(request));
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException ex) {
throw ExceptionConverter.generate(ex);
} finally {
request.releaseConnection();
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class AclPrincipalReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
super.init(resource, info);
// build the DAV:responses objects.
DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL);
if (!(acl instanceof AclProperty)) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected.");
}
DavResourceLocator loc = resource.getLocator();
Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>();
List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty) acl).getValue();
for (AclProperty.Ace ace : list) {
String href = ace.getPrincipal().getHref();
if (href == null || respMap.containsKey(href)) {
// ignore non-href principals and principals that have been listed before
continue;
}
// href-principal that has not been found before
DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href);
DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession());
respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet()));
}
this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]);
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class PrincipalMatchReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
super.init(resource, info);
if (info.containsContentElement(XML_PRINCIPAL_PROPERTY, SecurityConstants.NAMESPACE)) {
Element pp = info.getContentElement(XML_PRINCIPAL_PROPERTY, SecurityConstants.NAMESPACE);
principalPropertyName = DavPropertyName.createFromXml(DomUtil.getFirstChildElement(pp));
} else if (info.containsContentElement(XML_SELF, SecurityConstants.NAMESPACE)) {
principalPropertyName = SecurityConstants.PRINCIPAL_URL;
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:self or DAV:principal-property element required within report info.");
}
}
Aggregations