use of org.apache.jackrabbit.webdav.transaction.TransactionResource in project jackrabbit by apache.
the class TxLockManagerImpl method getLock.
/**
* @param lockToken
* @param resource
* @return
*/
private ActiveLock getLock(String lockToken, Scope scope, DavResource resource) {
if (!(resource instanceof TransactionResource)) {
log.warn("TransactionResource expected");
return null;
}
ActiveLock lock = null;
Transaction tx = null;
TransactionMap m = map;
// check if main-map contains that txId
if (m.containsKey(lockToken)) {
tx = m.get(lockToken);
} else {
// look through all the nested tx-maps (i.e. global txs) for the given txId
Iterator<Transaction> it = m.values().iterator();
while (it.hasNext() && tx == null) {
Transaction txMap = it.next();
if (!txMap.isLocal()) {
m = (TransactionMap) txMap;
if (m.containsKey(lockToken)) {
tx = ((TransactionMap) txMap).get(lockToken);
}
}
}
}
if (tx != null) {
if (tx.getLock().isExpired()) {
removeExpired(tx, m, (TransactionResource) resource);
} else if (tx.appliesToResource(resource) && (scope == null || tx.getLock().getScope().equals(scope))) {
lock = tx.getLock();
}
}
return lock;
}
use of org.apache.jackrabbit.webdav.transaction.TransactionResource in project jackrabbit by apache.
the class DavResourceFactoryImpl method createResource.
/**
* Create a new <code>DavResource</code> from the specified locator and request
* objects. Note, that in contrast to
* {@link #createResource(DavResourceLocator, DavSession)} the locator may
* point to a non-existing resource.
* <p>
* If the request contains a {@link org.apache.jackrabbit.webdav.version.DeltaVServletRequest#getLabel()
* Label header}, the resource is build from the indicated
* {@link org.apache.jackrabbit.webdav.version.VersionResource version} instead.
*
* @param locator
* @param request
* @param response
* @return
* @see DavResourceFactory#createResource(org.apache.jackrabbit.webdav.DavResourceLocator, org.apache.jackrabbit.webdav.DavServletRequest, org.apache.jackrabbit.webdav.DavServletResponse)
*/
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
JcrDavSession.checkImplementation(request.getDavSession());
JcrDavSession session = (JcrDavSession) request.getDavSession();
DavResource resource;
String type = request.getParameter("type");
if (locator.isRootLocation()) {
// root
resource = new RootCollection(locator, session, this);
} else if ("journal".equals(type) && locator.getResourcePath().equals(locator.getWorkspacePath())) {
// feed/event journal resource
try {
EventJournal ej = session.getRepositorySession().getWorkspace().getObservationManager().getEventJournal();
if (ej == null) {
throw new DavException(HttpServletResponse.SC_NOT_IMPLEMENTED, "event journal not supported");
}
resource = new EventJournalResourceImpl(ej, locator, session, request, this);
} catch (AccessDeniedException ex) {
// EventJournal only allowed for admin?
throw new DavException(HttpServletResponse.SC_UNAUTHORIZED, ex);
} catch (RepositoryException ex) {
throw new DavException(HttpServletResponse.SC_BAD_REQUEST, ex);
}
} else if (locator.getResourcePath().equals(locator.getWorkspacePath())) {
// workspace resource
resource = new WorkspaceResourceImpl(locator, session, this);
} else {
// resource corresponds to a repository item
try {
resource = createResourceForItem(locator, session);
Item item = getItem(session, locator);
boolean versionable = item.isNode() && ((Node) item).isNodeType(JcrConstants.MIX_VERSIONABLE);
/* if the created resource is version-controlled and the request
contains a Label header, the corresponding Version must be used
instead.*/
if (request instanceof DeltaVServletRequest && versionable) {
String labelHeader = ((DeltaVServletRequest) request).getLabel();
if (labelHeader != null && DavMethods.isMethodAffectedByLabel(request) && isVersionControlled(resource)) {
Version v = ((Node) item).getVersionHistory().getVersionByLabel(labelHeader);
DavResourceLocator vloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), v.getPath(), false);
resource = new VersionItemCollection(vloc, session, this, v);
}
}
} catch (PathNotFoundException e) {
/* item does not exist yet: create the default resources
Note: MKCOL request forces a collection-resource even if there already
exists a repository-property with the given path. the MKCOL will
in that particular case fail with a 405 (method not allowed).*/
if (DavMethods.getMethodCode(request.getMethod()) == DavMethods.DAV_MKCOL) {
resource = new VersionControlledItemCollection(locator, session, this, null);
} else {
resource = new DefaultItemResource(locator, session, this, null);
}
} catch (RepositoryException e) {
log.error("Failed to build resource from item '" + locator.getRepositoryPath() + "'");
throw new JcrDavException(e);
}
}
if (request instanceof TransactionDavServletRequest && resource instanceof TransactionResource) {
((TransactionResource) resource).init(txMgr, ((TransactionDavServletRequest) request).getTransactionId());
}
if (resource instanceof ObservationResource) {
((ObservationResource) resource).init(subsMgr);
}
return resource;
}
use of org.apache.jackrabbit.webdav.transaction.TransactionResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doUnlock.
/**
* The UNLOCK method
*
* @param request
* @param response
* @param resource
* @throws DavException
*/
protected void doUnlock(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException {
// get lock token from header
String lockToken = request.getLockToken();
TransactionInfo tInfo = request.getTransactionInfo();
if (tInfo != null) {
((TransactionResource) resource).unlock(lockToken, tInfo);
} else {
resource.unlock(lockToken);
}
response.setStatus(DavServletResponse.SC_NO_CONTENT);
}
Aggregations