use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class RepositoryServiceImpl method loadType.
private int loadType(String propertyURI, HttpClient client, PropertyId propertyId, SessionInfo sessionInfo, NamePathResolver resolver) throws IOException, DavException, RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(propertyURI, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length == 1) {
DavPropertySet props = mresponses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
if (type != null) {
return PropertyType.valueFromName(type.getValue().toString());
} else {
throw new RepositoryException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} else {
throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class RepositoryServiceImpl method getLockInfo.
@Override
public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
// set of Dav-properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DavPropertyName.LOCKDISCOVERY);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_0);
initMethod(request, sessionInfo, false);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length != 1) {
throw new ItemNotFoundException("Unable to retrieve the LockInfo. No such node " + saveGetIdString(nodeId, sessionInfo));
}
DavPropertySet ps = mresponses[0].getProperties(DavServletResponse.SC_OK);
if (ps.contains(DavPropertyName.LOCKDISCOVERY)) {
DavProperty<?> p = ps.get(DavPropertyName.LOCKDISCOVERY);
LockDiscovery ld = LockDiscovery.createFromXml(p.toXml(DomUtil.createDocument()));
NodeId parentId = getParentId(uri, ps, sessionInfo);
return retrieveLockInfo(ld, sessionInfo, nodeId, parentId);
} else {
// no lock present
log.debug("No Lock present on node with id " + saveGetIdString(nodeId, sessionInfo));
return null;
}
} 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();
}
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class WebdavResponseImpl method sendRefreshLockResponse.
/**
* Send response body for a lock request that was intended to refresh one
* or several locks.
*
* @param locks
* @throws java.io.IOException
* @see DavServletResponse#sendRefreshLockResponse(org.apache.jackrabbit.webdav.lock.ActiveLock[])
*/
public void sendRefreshLockResponse(ActiveLock[] locks) throws IOException {
DavPropertySet propSet = new DavPropertySet();
propSet.add(new LockDiscovery(locks));
sendXmlResponse(propSet, SC_OK);
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class RepositoryServiceImpl method obtain.
private SessionInfo obtain(CredentialsWrapper credentials, String workspaceName) throws RepositoryException {
// check if the workspace with the given name is accessible
HttpPropfind request = null;
SessionInfoImpl sessionInfo = new SessionInfoImpl(credentials, workspaceName);
try {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
// for backwards compat. -> retrieve DAV:workspace if the newly
// added property (workspaceName) is not supported by the server.
nameSet.add(DeltaVConstants.WORKSPACE);
nameSet.add(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
request = new HttpPropfind(uriResolver.getWorkspaceUri(workspaceName), nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (responses.length != 1) {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
}
DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> prop = props.get(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
if (prop != null) {
String wspName = prop.getValue().toString();
if (workspaceName == null) {
// login with 'null' workspace name -> retrieve the effective
// workspace name from the property and recreate the SessionInfo.
sessionInfo = new SessionInfoImpl(credentials, wspName);
} else if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name '" + workspaceName + "'.");
}
} else if (props.contains(DeltaVConstants.WORKSPACE)) {
String wspHref = new HrefProperty(props.get(DeltaVConstants.WORKSPACE)).getHrefs().get(0);
String wspName = Text.unescape(Text.getName(wspHref, true));
if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name " + workspaceName);
}
} else {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
}
} catch (IOException e) {
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
// mappings.
if (nsCache.prefixToURI.isEmpty()) {
try {
getRegisteredNamespaces(sessionInfo);
} catch (RepositoryException e) {
// ignore
}
}
// return the sessionInfo
return sessionInfo;
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class RepositoryServiceImpl method getWorkspaceNames.
@Override
public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DeltaVConstants.WORKSPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(uriResolver.getRepositoryUri(), nameSet, DEPTH_1);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
Set<String> wspNames = new HashSet<String>();
for (MultiStatusResponse mresponse : mresponses) {
DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
if (props.contains(DeltaVConstants.WORKSPACE)) {
HrefProperty hp = new HrefProperty(props.get(DeltaVConstants.WORKSPACE));
String wspHref = hp.getHrefs().get(0);
String name = Text.unescape(Text.getName(wspHref, true));
wspNames.add(name);
}
}
return wspNames.toArray(new String[wspNames.size()]);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations