*/
public void init(String resourcePath, Element locateByHistoryElm) throws PreconditionViolationException {
List childrenList = locateByHistoryElm.getChildren();
if (childrenList.size() != 2) {
throw new PreconditionViolationException(
new ViolatedPrecondition("invalid-locate-by-history",
WebdavStatus.SC_BAD_REQUEST,
"DAV:locate-by-history element must have 2 children: DAV:version-history-set and DAV:prop"),
resourcePath
);
}
Element versionHistorySetElm = null;
Element propElm = null;
if ( E_VERSION_HISTORY_SET.equals(((Element)childrenList.get(0)).getName()) &&
E_PROP.equals(((Element)childrenList.get(1)).getName()) ) {
versionHistorySetElm = (Element)childrenList.get(0);
propElm = (Element)childrenList.get(1);
}
else if ( E_PROP.equals(((Element)childrenList.get(0)).getName()) &&
E_VERSION_HISTORY_SET.equals(((Element)childrenList.get(1)).getName()) ) {
propElm = (Element)childrenList.get(0);
versionHistorySetElm = (Element)childrenList.get(1);
}
else {
throw new PreconditionViolationException(
new ViolatedPrecondition("invalid-locate-by-history",
WebdavStatus.SC_BAD_REQUEST,
"DAV:locate-by-history element must have 2 children: DAV:version-history-set and DAV:prop"),
resourcePath
);
}
// <locate-by-history> report can only be applied to collection
if ( ! WebdavUtils.isCollection(token, slideToken, resourcePath) ) {
throw new PreconditionViolationException(
new ViolatedPrecondition("must-be-collection",
WebdavStatus.SC_BAD_REQUEST,
"the request-URI must specify a collection"),
resourcePath
);
}
this.versionHistorySet =
new XMLValue(versionHistorySetElm.getChildren(E_HREF, DNSP));
// check DAV:must-be-version-history
UriHandler uriHandler = null;
String href = null;
boolean isVersionHistory = false;
Iterator iterator = versionHistorySet.getHrefStrings().iterator();
while (iterator.hasNext()) {
href = (String)iterator.next();
uriHandler = UriHandler.getUriHandler(WebdavUtils.getSlidePath(href, contextPath));
isVersionHistory = uriHandler.isHistoryUri();
if (!isVersionHistory) {
break;
}
}
if (!isVersionHistory) {
throw new PreconditionViolationException(
new ViolatedPrecondition(C_MUST_BE_VERSION_HISTORY,
WebdavStatus.SC_CONFLICT),
resourcePath
);
}
try {
this.requestedProperties = new RequestedPropertiesImpl(propElm);
}
catch (PropertyParseException e) {
throw new PreconditionViolationException(
new ViolatedPrecondition("invalid-prop",
WebdavStatus.SC_BAD_REQUEST,
e.getMessage()),
resourcePath
);
}