* @throws PreconditionViolationException
*/
public void init(String resourcePath, Element principalMatchElm) throws PreconditionViolationException {
if (principalMatchElm.getChildren().size() == 0) {
throw new PreconditionViolationException(
new ViolatedPrecondition("at-least-one-child-element",
WebdavStatus.SC_BAD_REQUEST,
"DAV:principal-match element must have at least one child"),
resourcePath
);
}
List principalPropertyElmL = principalMatchElm.getChildren(E_PRINCIPAL_PROPERTY, DNSP);
List selfElmL = principalMatchElm.getChildren(E_SELF, DNSP);
if (principalPropertyElmL.size()+selfElmL.size() != 1) {
throw new PreconditionViolationException(
new ViolatedPrecondition("either-one-principal-property-or-one-self-element",
WebdavStatus.SC_BAD_REQUEST,
"DAV:principal-match element must contain either a DAV:principal-property or a DAV:self element"),
resourcePath
);
}
if (principalPropertyElmL.size() == 1) {
Element principalPropertyElm = (Element)principalPropertyElmL.get(0);
if (principalPropertyElm.getChildren(E_OWNER, DNSP).size() > 0) {
matchSubjectNode = SubjectNode.OWNER;
}
else {
// TODO: support other properties
}
}
else {
matchSubjectNode = SubjectNode.SELF;
}
List propElmL = principalMatchElm.getChildren(E_PROP, DNSP);
if (propElmL.size() > 1) {
throw new PreconditionViolationException(
new ViolatedPrecondition("at-most-one-prop-element",
WebdavStatus.SC_BAD_REQUEST,
"DAV:principal-match element must have at most one DAV:prop child"),
resourcePath
);
}
if (propElmL.size() == 1) {
Element propElm = (Element)propElmL.get(0);
try {
this.requestedProperties = new RequestedPropertiesImpl(propElm);
}
catch (PropertyParseException e) {
throw new PreconditionViolationException(
new ViolatedPrecondition("invalid-prop",
WebdavStatus.SC_BAD_REQUEST,
e.getMessage()),
resourcePath
);
}