use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method getRepositoryDescriptors.
@Override
public Map<String, QValue[]> getRepositoryDescriptors() throws RepositoryException {
if (descriptors.isEmpty()) {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REPOSITORY_DESCRIPTORS, ItemResourceConstants.NAMESPACE);
HttpReport request = null;
try {
request = new HttpReport(uriResolver.getRepositoryUri(), info);
HttpResponse response = executeRequest(null, request);
int sc = response.getStatusLine().getStatusCode();
if (sc == HttpStatus.SC_UNAUTHORIZED || sc == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
// JCR-3076: Mandatory authentication prevents us from
// accessing the descriptors on the server, so instead
// of failing with an exception we simply return an empty
// set of descriptors
log.warn("Authentication required to access repository descriptors");
return descriptors;
}
request.checkSuccess(response);
Document doc = request.getResponseBodyAsDocument(response.getEntity());
if (doc != null) {
Element rootElement = doc.getDocumentElement();
ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_DESCRIPTOR, ItemResourceConstants.NAMESPACE);
while (nsElems.hasNext()) {
Element elem = nsElems.nextElement();
String key = DomUtil.getChildText(elem, JcrRemotingConstants.XML_DESCRIPTORKEY, ItemResourceConstants.NAMESPACE);
ElementIterator it = DomUtil.getChildren(elem, JcrRemotingConstants.XML_DESCRIPTORVALUE, ItemResourceConstants.NAMESPACE);
List<QValue> vs = new ArrayList<QValue>();
while (it.hasNext()) {
Element dv = it.nextElement();
String descriptor = DomUtil.getText(dv);
if (key != null && descriptor != null) {
String typeStr = (DomUtil.getAttribute(dv, JcrRemotingConstants.ATTR_VALUE_TYPE, null));
int type = (typeStr == null) ? PropertyType.STRING : PropertyType.valueFromName(typeStr);
vs.add(getQValueFactory().create(descriptor, type));
} else {
log.error("Invalid descriptor key / value pair: " + key + " -> " + descriptor);
}
}
descriptors.put(key, vs.toArray(new QValue[vs.size()]));
}
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
return descriptors;
}
use of org.apache.jackrabbit.webdav.version.report.ReportInfo in project jackrabbit by apache.
the class RepositoryServiceImpl method getQNodeTypeDefinitions.
@Override
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
HttpReport request = null;
try {
ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_NODETYPES, ItemResourceConstants.NAMESPACE);
info.setContentElement(DomUtil.createElement(DomUtil.createDocument(), NodeTypeConstants.XML_REPORT_ALLNODETYPES, ItemResourceConstants.NAMESPACE));
String workspaceUri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
request = new HttpReport(workspaceUri, info);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
Document reportDoc = request.getResponseBodyAsDocument(response.getEntity());
return retrieveQNodeTypeDefinitions(sessionInfo, reportDoc);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (ParserConfigurationException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations