use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class DefaultItemCollection method buildValuesProperty.
/**
* Tries to parse the given input stream as xml document and build a
* {@link ValuesProperty} out of it.
*
* @param in
* @return values property or 'null' if the given stream cannot be parsed
* into an XML document or if build the property fails.
*/
private ValuesProperty buildValuesProperty(InputStream in) {
String errorMsg = "Cannot parse stream into a 'ValuesProperty'.";
try {
Document reqBody = DomUtil.parseDocument(in);
DavProperty<?> defaultProp = DefaultDavProperty.createFromXml(reqBody.getDocumentElement());
ValuesProperty vp = new ValuesProperty(defaultProp, PropertyType.STRING, getRepositorySession().getValueFactory());
return vp;
} catch (IOException e) {
log.debug(errorMsg, e);
} catch (ParserConfigurationException e) {
log.debug(errorMsg, e);
} catch (SAXException e) {
log.debug(errorMsg, e);
} catch (DavException e) {
log.debug(errorMsg, e);
} catch (RepositoryException e) {
log.debug(errorMsg, e);
}
// cannot parse request body into a 'values' property
return null;
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class AbstractItemResource method getCollection.
/**
* Returns the resource representing the parent item of the repository item
* represented by this resource. If this resoure represents the root item
* a {@link RootCollection} is returned.
*
* @return the collection this resource is internal member of. Except for the
* repository root, the returned collection always represent the parent
* repository node.
* @see org.apache.jackrabbit.webdav.DavResource#getCollection()
*/
@Override
public DavResource getCollection() {
DavResource collection = null;
String parentPath = Text.getRelativeParent(getResourcePath(), 1);
DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), getLocator().getWorkspacePath(), parentPath);
try {
collection = createResourceFromLocator(parentLoc);
} catch (DavException e) {
log.error("Unexpected error while retrieving collection: " + e.getMessage());
}
return collection;
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class AbstractItemResource method copy.
/**
* Copies the underlying repository item to the indicated destination. If
* the locator of the specified destination resource indicates a different
* workspace, {@link Workspace#copy(String, String, String)} is used to perform
* the copy operation, {@link Workspace#copy(String, String)} otherwise.
* <p>
* Note, that this implementation does not support shallow copy.
*
* @param destination
* @param shallow
* @throws DavException
* @see DavResource#copy(DavResource, boolean)
* @see Workspace#copy(String, String)
* @see Workspace#copy(String, String, String)
*/
@Override
public void copy(DavResource destination, boolean shallow) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
// TODO: support shallow and deep copy is required by RFC 2518
if (shallow) {
throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy.");
}
try {
String itemPath = getLocator().getRepositoryPath();
String destItemPath = destination.getLocator().getRepositoryPath();
Workspace workspace = getRepositorySession().getWorkspace();
if (getLocator().isSameWorkspace(destination.getLocator())) {
workspace.copy(itemPath, destItemPath);
} else {
log.error("Copy between workspaces is not yet implemented (src: '" + getHref() + "', dest: '" + destination.getHref() + "')");
throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
}
} catch (PathNotFoundException e) {
// according to RFC 2518, should not occur
throw new DavException(DavServletResponse.SC_NOT_FOUND, e.getMessage());
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class RepositoryServiceImpl method isGranted.
@Override
public boolean isGranted(SessionInfo sessionInfo, ItemId itemId, String[] actions) throws RepositoryException {
HttpReport request = null;
try {
String uri = obtainAbsolutePathFromUri(getItemUri(itemId, sessionInfo));
ReportInfo reportInfo = new ReportInfo(JcrRemotingConstants.REPORT_PRIVILEGES, ItemResourceConstants.NAMESPACE);
reportInfo.setContentElement(DomUtil.hrefToXml(uri, DomUtil.createDocument()));
request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), reportInfo);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (responses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve permissions for item " + saveGetIdString(itemId, sessionInfo));
}
DavProperty<?> p = responses[0].getProperties(DavServletResponse.SC_OK).get(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
if (p == null) {
return false;
}
// build set of privileges from given actions. NOTE: since the actions
// have no qualifying namespace, the {@link ItemResourceConstants#NAMESPACE}
// is used.
Set<Privilege> requiredPrivileges = new HashSet<Privilege>();
for (String action : actions) {
requiredPrivileges.add(Privilege.getPrivilege(action, ItemResourceConstants.NAMESPACE));
}
// build set of privileges granted to the current user.
CurrentUserPrivilegeSetProperty privSet = new CurrentUserPrivilegeSetProperty(p);
Collection<Privilege> privileges = privSet.getValue();
// check privileges present against required privileges.
return privileges.containsAll(requiredPrivileges);
} 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.DavException in project jackrabbit by apache.
the class RepositoryServiceImpl method poll.
private EventBundle[] poll(String uri, String subscriptionId, long timeout, SessionInfoImpl sessionInfo) throws RepositoryException {
HttpPoll request = null;
try {
request = new HttpPoll(uri, subscriptionId, timeout);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
EventDiscovery disc = request.getResponseBodyAsEventDiscovery(response);
EventBundle[] events;
if (disc.isEmpty()) {
events = new EventBundle[0];
} else {
Element discEl = disc.toXml(DomUtil.createDocument());
ElementIterator it = DomUtil.getChildren(discEl, ObservationConstants.N_EVENTBUNDLE);
List<EventBundle> bundles = new ArrayList<EventBundle>();
while (it.hasNext()) {
Element bundleElement = it.nextElement();
String value = DomUtil.getAttribute(bundleElement, ObservationConstants.XML_EVENT_LOCAL, null);
// check if it matches a batch id recently submitted
boolean isLocal = false;
if (value != null) {
isLocal = Boolean.parseBoolean(value);
}
bundles.add(new EventBundleImpl(buildEventList(bundleElement, sessionInfo, uri), isLocal));
}
events = bundles.toArray(new EventBundle[bundles.size()]);
}
return events;
} 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