1 17 package com.sslexplorer.vfs.webdav; 18 19 import java.io.IOException ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import com.sslexplorer.boot.Util; 28 import com.sslexplorer.policyframework.LaunchSession; 29 import com.sslexplorer.policyframework.LaunchSessionFactory; 30 import com.sslexplorer.security.SessionInfo; 31 import com.sslexplorer.vfs.VFSRepository; 32 import com.sslexplorer.vfs.VFSResource; 33 import com.sslexplorer.vfs.webdav.methods.COPY; 34 import com.sslexplorer.vfs.webdav.methods.DELETE; 35 import com.sslexplorer.vfs.webdav.methods.GET; 36 import com.sslexplorer.vfs.webdav.methods.HEAD; 37 import com.sslexplorer.vfs.webdav.methods.MKCOL; 38 import com.sslexplorer.vfs.webdav.methods.MOVE; 39 import com.sslexplorer.vfs.webdav.methods.OPTIONS; 40 import com.sslexplorer.vfs.webdav.methods.PROPFIND; 41 import com.sslexplorer.vfs.webdav.methods.PROPPATCH; 42 import com.sslexplorer.vfs.webdav.methods.PUT; 43 44 50 public class DAVProcessor { 51 final static Log log = LogFactory.getLog(DAVProcessor.class); 52 53 54 public static final String METHODS = "COPY,DELETE,GET,HEAD,MKCOL,MOVE,OPTIONS,PROPFIND,PROPPATCH,PUT"; 55 56 private VFSRepository repository = null; 57 private Map methods = null; 58 private SessionInfo session; 59 60 private static Map methodImpls = new HashMap (); 61 62 63 public static void addDAVMethod(Class cls) { 64 65 methodImpls.put(Util.getSimpleClassName(cls), cls); 66 } 67 68 public static void removeDAVMethod(Class cls) { 69 methodImpls.remove(Util.getSimpleClassName(cls)); 70 } 71 72 77 public DAVProcessor(VFSRepository repository, SessionInfo session) { 78 this.repository = repository; 79 this.session = session; 80 initialiseProcessor(); 81 } 82 83 86 public void initialiseProcessor(){ 87 this.methods = new HashMap (); 88 this.methods.put("DELETE", new DELETE()); 89 this.methods.put("GET", new GET()); 90 this.methods.put("HEAD", new HEAD()); 91 this.methods.put("MKCOL", new MKCOL()); 92 this.methods.put("MOVE", new MOVE()); 93 this.methods.put("OPTIONS", new OPTIONS()); 94 this.methods.put("PROPFIND", new PROPFIND()); 95 this.methods.put("PROPPATCH", new PROPPATCH()); 96 this.methods.put("PUT", new PUT()); 97 this.methods.put("COPY", new COPY()); 98 99 Map.Entry entry; 100 for(Iterator it = methodImpls.entrySet().iterator(); it.hasNext();) { 101 try { 102 entry = (Map.Entry ) it.next(); 103 this.methods.put(entry.getKey(), ((Class ) entry.getValue()).newInstance()); 104 } catch (InstantiationException e) { 105 log.error("Could not create DAVMethod implementation", e); 106 } catch (IllegalAccessException e) { 107 log.error("Could not create DAVMethod implementation", e); 108 } 109 } 110 } 111 112 117 public SessionInfo getSession() { 118 return session; 119 } 120 121 125 public void process(DAVTransaction transaction) 126 throws Exception { 127 128 String method = transaction.getMethod(); 129 if (this.methods.containsKey(method)) { 130 String path = transaction.getPath(); 131 if(log.isDebugEnabled()) 132 log.debug("Looking for resource for '" + path + "'"); 133 134 LaunchSession launchSession = null; 136 String launchId = transaction.getRequest().getParameter(LaunchSession.LAUNCH_ID); 137 if(launchId != null) { 138 launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId); 139 } 140 if(launchSession == null) { 141 launchSession = new LaunchSession(transaction.getSessionInfo()); 142 } 143 144 VFSResource resource = repository.getResource(launchSession, path, transaction.getCredentials()); 145 146 149 resource.verifyAccess(); 150 151 154 155 DAVMethod instance = ((DAVMethod)this.methods.get(method)); 156 instance.process(transaction, resource); 157 } else { 158 String message = "Method \"" + method + "\" not implemented"; 159 throw new DAVException(501, message); 160 } 161 } 162 163 166 public VFSRepository getRepository() { 167 return repository; 168 } 169 } 170 | Popular Tags |