use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class OptionsInfo method createFromXml.
/**
* Build an <code>OptionsInfo</code> object from the root element present
* in the request body.
*
* @param optionsElement
* @return
* @throws DavException if the optionsElement is <code>null</code>
* or not a DAV:options element.
*/
public static OptionsInfo createFromXml(Element optionsElement) throws DavException {
if (!DomUtil.matches(optionsElement, DeltaVConstants.XML_OPTIONS, DeltaVConstants.NAMESPACE)) {
log.warn("DAV:options element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
OptionsInfo oInfo = new OptionsInfo();
ElementIterator it = DomUtil.getChildren(optionsElement);
while (it.hasNext()) {
// todo: not correct since assuming its the deltaV-namespace
oInfo.entriesLocalNames.add(it.nextElement().getLocalName());
}
return oInfo;
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class PrincipalSearchReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
super.init(resource, info);
// make sure the request body contains all mandatory elements
if (!info.containsContentElement(XML_PROPERTY_SEARCH, SecurityConstants.NAMESPACE)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Request body must contain at least a single DAV:property-search element.");
}
List<Element> psElements = info.getContentElements(XML_PROPERTY_SEARCH, SecurityConstants.NAMESPACE);
searchArguments = new SearchArgument[psElements.size()];
int i = 0;
for (Element psElement : psElements) {
searchArguments[i++] = new SearchArgument(psElement);
}
if (info.containsContentElement(XML_APPLY_TO_PRINCIPAL_COLLECTION_SET, SecurityConstants.NAMESPACE)) {
HrefProperty p = new HrefProperty(resource.getProperty(SecurityConstants.PRINCIPAL_COLLECTION_SET));
searchRoots = p.getHrefs().toArray(new String[0]);
} else {
searchRoots = new String[] { resource.getHref() };
}
}
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);
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class RebindInfo method createFromXml.
/**
* Build an <code>RebindInfo</code> object from the root element present
* in the request body.
*
* @param root the root element of the request body
* @return a RebindInfo object containing segment and href
* @throws org.apache.jackrabbit.webdav.DavException if the REBIND request is malformed
*/
public static RebindInfo createFromXml(Element root) throws DavException {
if (!DomUtil.matches(root, BindConstants.XML_REBIND, BindConstants.NAMESPACE)) {
log.warn("DAV:rebind element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
String href = null;
String segment = null;
ElementIterator it = DomUtil.getChildren(root);
while (it.hasNext()) {
Element elt = it.nextElement();
if (DomUtil.matches(elt, BindConstants.XML_SEGMENT, BindConstants.NAMESPACE)) {
if (segment == null) {
segment = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:segment element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else if (DomUtil.matches(elt, BindConstants.XML_HREF, BindConstants.NAMESPACE)) {
if (href == null) {
href = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:href element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else {
log.warn("unexpected element " + elt.getLocalName());
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
}
if (href == null) {
log.warn("DAV:href element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
if (segment == null) {
log.warn("DAV:segment element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
return new RebindInfo(href, segment);
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class UnbindInfo method createFromXml.
/**
* Build an <code>UnbindInfo</code> object from the root element present
* in the request body.
*
* @param root the root element of the request body
* @return a UnbindInfo object containing a segment identifier
* @throws org.apache.jackrabbit.webdav.DavException if the UNBIND request is malformed
*/
public static UnbindInfo createFromXml(Element root) throws DavException {
if (!DomUtil.matches(root, BindConstants.XML_UNBIND, BindConstants.NAMESPACE)) {
log.warn("DAV:unbind element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
String segment = null;
ElementIterator it = DomUtil.getChildren(root);
while (it.hasNext()) {
Element elt = it.nextElement();
if (DomUtil.matches(elt, BindConstants.XML_SEGMENT, BindConstants.NAMESPACE)) {
if (segment == null) {
segment = DomUtil.getText(elt);
} else {
log.warn("unexpected multiple occurrence of DAV:segment element");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
} else {
log.warn("unexpected element " + elt.getLocalName());
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
}
if (segment == null) {
log.warn("DAV:segment element expected");
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
return new UnbindInfo(segment);
}
Aggregations