1 17 package com.sslexplorer.vfs.webdav.methods; 18 19 import java.io.IOException ; 20 import java.util.Date ; 21 22 import com.sslexplorer.boot.Util; 23 import com.sslexplorer.vfs.VFSLockManager; 24 import com.sslexplorer.vfs.VFSResource; 25 import com.sslexplorer.vfs.webdav.DAVMethod; 26 import com.sslexplorer.vfs.webdav.DAVRedirection; 27 import com.sslexplorer.vfs.webdav.DAVTransaction; 28 import com.sslexplorer.vfs.webdav.DAVUtilities; 29 import com.sslexplorer.vfs.webdav.LockedException; 30 31 37 public class HEAD implements DAVMethod { 38 public static final String COLLECTION_MIME_TYPE = "text/html"; 39 42 public HEAD() { 43 super(); 44 } 45 46 49 public void process(DAVTransaction transaction, VFSResource resource) 50 throws LockedException, IOException { 51 String handle = VFSLockManager.getNewHandle(); 52 VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, true, handle); 53 try { 54 doHead(transaction, resource); 55 } finally { 56 VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle); 57 } 58 } 59 60 protected void doHead(DAVTransaction transaction, VFSResource resource) 61 throws LockedException, IOException { 62 63 if (resource.isNull()) { 64 65 69 String mime = COLLECTION_MIME_TYPE + "; charset=\"utf-8\""; 70 transaction.setContentType(mime); 71 Util.noCache(transaction.getResponse()); 72 73 transaction.setStatus(404); 74 75 return; 76 } 77 if (transaction.isRequiredRootRedirect() || !transaction.isResourcePath(resource.getFullPath())) { 78 throw new DAVRedirection(false, resource); 79 } 80 81 82 Date ifmod = transaction.getIfModifiedSince(); 83 Date lsmod = resource.getLastModified(); 84 if (resource.isResource() && (ifmod != null) && (lsmod != null)) { 85 86 lsmod = new Date (((long)(lsmod.getTime() / 1000)) * 1000); 87 } 89 90 91 String ctyp = resource.getContentType(); 92 String etag = resource.getEntityTag(); 93 String lmod = DAVUtilities.format(resource.getLastModified()); 94 String clen = DAVUtilities.format(resource.getContentLength()); 95 96 97 if (ctyp != null) transaction.setContentType(ctyp == null ? "application/octet-stream" : ctyp); 98 if (etag != null) transaction.setHeader("ETag", etag); 99 if (lmod != null) transaction.setHeader("Last-Modified", lmod); 100 if (clen != null) transaction.setHeader("Content-Length", clen); 101 } 102 } 103 | Popular Tags |