use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class LocateByHistoryReport method setInfo.
/**
* Set the <code>ReportInfo</code>
*
* @param info
* @throws DavException if the given <code>ReportInfo</code>
* does not contain a DAV:version-tree element.
*/
private void setInfo(ReportInfo info) throws DavException {
if (info == null || !getType().isRequestedReportType(info)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:locate-by-history element expected.");
}
Element versionHistorySet = info.getContentElement(XML_VERSION_HISTORY_SET, NAMESPACE);
if (versionHistorySet == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "The DAV:locate-by-history element must contain a DAV:version-history-set child.");
}
ElementIterator it = DomUtil.getChildren(versionHistorySet, DavConstants.XML_HREF, DavConstants.NAMESPACE);
while (it.hasNext()) {
String href = DomUtil.getText(it.nextElement());
if (href != null) {
vhHrefSet.add(href);
}
}
this.info = info;
}
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 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 RepositoryServiceImpl method getRegisteredNamespaces.
@Override
public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REGISTERED_NAMESPACES, ItemResourceConstants.NAMESPACE);
HttpReport request = null;
try {
request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), info);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
Document doc = request.getResponseBodyAsDocument(response.getEntity());
Map<String, String> namespaces = new HashMap<String, String>();
if (doc != null) {
Element rootElement = doc.getDocumentElement();
ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_NAMESPACE, ItemResourceConstants.NAMESPACE);
while (nsElems.hasNext()) {
Element elem = nsElems.nextElement();
String prefix = DomUtil.getChildText(elem, JcrRemotingConstants.XML_PREFIX, ItemResourceConstants.NAMESPACE);
String uri = DomUtil.getChildText(elem, JcrRemotingConstants.XML_URI, ItemResourceConstants.NAMESPACE);
// default namespace
if (prefix == null && uri == null) {
prefix = uri = "";
}
// any other uri must not be null
if (uri != null) {
namespaces.put(prefix, uri);
// TODO: not correct since nsRegistry is retrieved from each session
nsCache.add(prefix, uri);
} else {
log.error("Invalid prefix / uri pair: " + prefix + " -> " + uri);
}
}
}
return namespaces;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class RepositoryServiceImpl method resolveMergeConflict.
@Override
public void resolveMergeConflict(SessionInfo sessionInfo, NodeId nodeId, NodeId[] mergeFailedIds, NodeId[] predecessorIds) throws RepositoryException {
HttpProppatch request = null;
try {
List<HrefProperty> changeList = new ArrayList<HrefProperty>();
String[] mergeFailedHref = new String[mergeFailedIds.length];
for (int i = 0; i < mergeFailedIds.length; i++) {
mergeFailedHref[i] = getItemUri(mergeFailedIds[i], sessionInfo);
}
changeList.add(new HrefProperty(VersionControlledResource.AUTO_MERGE_SET, mergeFailedHref, false));
if (predecessorIds != null && predecessorIds.length > 0) {
String[] pdcHrefs = new String[predecessorIds.length];
for (int i = 0; i < predecessorIds.length; i++) {
pdcHrefs[i] = getItemUri(predecessorIds[i], sessionInfo);
}
changeList.add(new HrefProperty(VersionControlledResource.PREDECESSOR_SET, pdcHrefs, false));
}
request = new HttpProppatch(getItemUri(nodeId, sessionInfo), changeList);
initMethod(request, sessionInfo, !isUnLockMethod(request));
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations