- Some minor improvements, renamed some classes

This commit is contained in:
Sebastian Stenzel 2015-01-09 15:25:44 +01:00
parent deb10c1256
commit 760b2c028f
6 changed files with 28 additions and 68 deletions

View File

@ -1,36 +0,0 @@
package org.cryptomator.webdav.jackrabbit;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavResource;
import org.apache.jackrabbit.webdav.DavResourceFactory;
import org.apache.jackrabbit.webdav.DavResourceLocator;
import org.apache.jackrabbit.webdav.DavServletRequest;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.DavSession;
abstract class AbstractSessionAwareWebDavResourceFactory implements DavResourceFactory {
@Override
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
final DavSession session = request.getDavSession();
if (session != null && session instanceof WebDavSession) {
return createDavResource(locator, (WebDavSession) session, request, response);
} else {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Unsupported session type.");
}
}
protected abstract DavResource createDavResource(DavResourceLocator locator, WebDavSession session, DavServletRequest request, DavServletResponse response) throws DavException;
@Override
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
if (session != null && session instanceof WebDavSession) {
return createDavResource(locator, (WebDavSession) session);
} else {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Unsupported session type.");
}
}
protected abstract DavResource createDavResource(DavResourceLocator locator, WebDavSession session);
}

View File

@ -21,14 +21,14 @@ import org.cryptomator.crypto.Cryptor;
import org.cryptomator.crypto.CryptorIOSupport;
import org.cryptomator.crypto.SensitiveDataSwipeListener;
class WebDavLocatorFactory extends AbstractLocatorFactory implements SensitiveDataSwipeListener, CryptorIOSupport {
class DavLocatorFactoryImpl extends AbstractLocatorFactory implements SensitiveDataSwipeListener, CryptorIOSupport {
private static final int MAX_CACHED_PATHS = 10000;
private final Path fsRoot;
private final Cryptor cryptor;
private final BidiMap<String, String> pathCache = new BidiLRUMap<>(MAX_CACHED_PATHS); // <decryptedPath, encryptedPath>
WebDavLocatorFactory(String fsRoot, String httpRoot, Cryptor cryptor) {
DavLocatorFactoryImpl(String fsRoot, String httpRoot, Cryptor cryptor) {
super(httpRoot);
this.fsRoot = FileSystems.getDefault().getPath(fsRoot);
this.cryptor = cryptor;

View File

@ -30,13 +30,13 @@ import org.cryptomator.webdav.jackrabbit.resources.NonExistingNode;
import org.cryptomator.webdav.jackrabbit.resources.ResourcePathUtils;
import org.eclipse.jetty.http.HttpHeader;
class WebDavResourceFactory implements DavResourceFactory {
class DavResourceFactoryImpl implements DavResourceFactory {
private final LockManager lockManager = new SimpleLockManager();
private final Cryptor cryptor;
private final boolean checkFileIntegrity;
WebDavResourceFactory(Cryptor cryptor, boolean checkFileIntegrity) {
DavResourceFactoryImpl(Cryptor cryptor, boolean checkFileIntegrity) {
this.cryptor = cryptor;
this.checkFileIntegrity = checkFileIntegrity;
}

View File

@ -8,49 +8,38 @@
******************************************************************************/
package org.cryptomator.webdav.jackrabbit;
import java.util.HashSet;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.WebdavRequest;
class WebDavSession implements DavSession {
private final WebdavRequest request;
WebDavSession(WebdavRequest request) {
this.request = request;
}
class DavSessionImpl implements DavSession {
private final HashSet<String> lockTokens = new HashSet<String>();
private final HashSet<Object> references = new HashSet<Object>();
@Override
public void addReference(Object reference) {
// TODO Auto-generated method stub
references.add(reference);
}
@Override
public void removeReference(Object reference) {
// TODO Auto-generated method stub
references.remove(reference);
}
@Override
public void addLockToken(String token) {
// TODO Auto-generated method stub
lockTokens.add(token);
}
@Override
public String[] getLockTokens() {
// TODO Auto-generated method stub
return null;
return lockTokens.toArray(new String[lockTokens.size()]);
}
@Override
public void removeLockToken(String token) {
// TODO Auto-generated method stub
}
public WebdavRequest getRequest() {
return request;
lockTokens.remove(token);
}
}

View File

@ -9,21 +9,28 @@
package org.cryptomator.webdav.jackrabbit;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavSession;
import org.apache.jackrabbit.webdav.DavSessionProvider;
import org.apache.jackrabbit.webdav.WebdavRequest;
class WebDavSessionProvider implements DavSessionProvider {
class DavSessionProviderImpl implements DavSessionProvider {
@Override
public boolean attachSession(WebdavRequest request) throws DavException {
// every request gets a session
request.setDavSession(new WebDavSession(request));
final DavSession session = new DavSessionImpl();
session.addReference(request);
request.setDavSession(session);
return true;
}
@Override
public void releaseSession(WebdavRequest request) {
// do nothing
final DavSession session = request.getDavSession();
if (session != null) {
session.removeReference(request);
request.setDavSession(null);
}
}
}

View File

@ -39,14 +39,14 @@ public class WebDavServlet extends AbstractWebdavServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
davSessionProvider = new WebDavSessionProvider();
davSessionProvider = new DavSessionProviderImpl();
final String fsRoot = config.getInitParameter(CFG_FS_ROOT);
final String httpRoot = config.getInitParameter(CFG_HTTP_ROOT);
final boolean checkFileIntegrity = Boolean.parseBoolean(config.getInitParameter(CFG_CHECK_FILE_INTEGRITY));
this.davLocatorFactory = new WebDavLocatorFactory(fsRoot, httpRoot, cryptor);
this.davLocatorFactory = new DavLocatorFactoryImpl(fsRoot, httpRoot, cryptor);
this.davResourceFactory = new WebDavResourceFactory(cryptor, checkFileIntegrity);
this.davResourceFactory = new DavResourceFactoryImpl(cryptor, checkFileIntegrity);
}
@Override