use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionControlledItemCollection method checkin.
//--------------------------------< VersionControlledResource interface >---
/**
* Calls {@link javax.jcr.Node#checkin()} on the underlying repository node.
*
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkin()
*/
@Override
public String checkin() throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
if (!isVersionControlled()) {
throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
}
try {
Version v = getVersionManager().checkin(item.getPath());
String versionHref = getLocatorFromItem(v).getHref(true);
return versionHref;
} catch (RepositoryException e) {
// UnsupportedRepositoryException should not occur
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class LocateByUuidReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
// delegate basic validation to super class
super.init(resource, info);
// make also sure, the info contains a DAV:href child element
if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:locate-by-uuid element must at least contain a single DAV:href child.");
}
// immediately build the final multistatus element
try {
Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
String uuid = DomUtil.getTextTrim(hrefElem);
DavResourceLocator resourceLoc = resource.getLocator();
Node n = getRepositorySession().getNodeByUUID(uuid);
DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath(), false);
DavResource locatedResource = resource.getFactory().createResource(loc, resource.getSession());
ms = new MultiStatus();
ms.addResourceProperties(locatedResource, info.getPropertyNameSet(), info.getDepth());
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class NodeTypesReport method getNodeTypes.
/**
* Parse the Xml element in the info object an return an interator over
* the specified node types.
*
* @return
* @throws RepositoryException
* @throws DavException
*/
private static NodeTypeIterator getNodeTypes(Session session, ReportInfo info) throws RepositoryException, DavException {
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
// check the simple types first...
if (info.containsContentElement(XML_REPORT_ALLNODETYPES, ItemResourceConstants.NAMESPACE)) {
return ntMgr.getAllNodeTypes();
} else if (info.containsContentElement(XML_REPORT_MIXINNODETYPES, ItemResourceConstants.NAMESPACE)) {
return ntMgr.getMixinNodeTypes();
} else if (info.containsContentElement(XML_REPORT_PRIMARYNODETYPES, ItemResourceConstants.NAMESPACE)) {
return ntMgr.getPrimaryNodeTypes();
} else {
// None of the simple types. test if a report for individual
// nodetype was request. If not, the request body is not valid.
List<Element> elemList = info.getContentElements(XML_NODETYPE, ItemResourceConstants.NAMESPACE);
if (elemList.isEmpty()) {
// throw exception if the request body does not contain a single nodetype element
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "NodeTypes report: request body has invalid format.");
}
// todo: find better solution...
List<NodeType> ntList = new ArrayList<NodeType>();
for (Element el : elemList) {
String nodetypeName = DomUtil.getChildTextTrim(el, XML_NODETYPENAME, ItemResourceConstants.NAMESPACE);
if (nodetypeName != null) {
ntList.add(ntMgr.getNodeType(nodetypeName));
}
}
return new NodeTypeIteratorAdapter(ntList);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class TxLockManagerImpl method refreshLock.
/**
* Reset the timeout of the lock identified by the given lock token.
*
* @param lockInfo
* @param lockToken
* @param resource
* @return
* @throws DavException if the lock did not exist or is expired.
*/
private synchronized ActiveLock refreshLock(LockInfo lockInfo, String lockToken, TransactionResource resource) throws DavException {
TransactionMap responsibleMap = getMap(resource);
Transaction tx = responsibleMap.get(lockToken);
if (tx == null) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No valid transaction lock found for resource '" + resource.getResourcePath() + "'");
} else if (tx.getLock().isExpired()) {
removeExpired(tx, responsibleMap, resource);
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Transaction lock for resource '" + resource.getResourcePath() + "' was already expired.");
} else {
tx.getLock().setTimeout(lockInfo.getTimeout());
}
return tx.getLock();
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class AbstractJcrReport method init.
/**
* Performs basic validation checks common to all JCR specific reports.
*
* @param resource
* @param info
* @throws DavException
* @see Report#init(DavResource, ReportInfo)
*/
public void init(DavResource resource, ReportInfo info) throws DavException {
if (resource == null || info == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Unable to run report: WebDAV Resource and ReportInfo must not be null.");
}
if (!getType().isRequestedReportType(info)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Expected report type: '" + getType().getReportName() + "', found: '" + info.getReportName() + ";" + "'.");
}
if (info.getDepth() > DavConstants.DEPTH_0) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid Depth header: " + info.getDepth());
}
DavSession davSession = resource.getSession();
if (davSession == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "The resource must provide a non-null session object in order to create '" + getType().getReportName() + "' report.");
}
session = JcrDavSession.getRepositorySession(resource.getSession());
if (session == null) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal error: Unable to access repository session.");
}
reportInfo = info;
}
Aggregations