1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.webdav4;
18
19 import org.apache.commons.vfs2.FileContent;
20 import org.apache.commons.vfs2.FileContentInfo;
21 import org.apache.commons.vfs2.FileContentInfoFactory;
22 import org.apache.commons.vfs2.FileSystemException;
23 import org.apache.commons.vfs2.impl.DefaultFileContentInfo;
24 import org.apache.commons.vfs2.provider.GenericURLFileName;
25 import org.apache.commons.vfs2.util.FileObjectUtils;
26 import org.apache.jackrabbit.webdav.property.DavProperty;
27 import org.apache.jackrabbit.webdav.property.DavPropertyName;
28 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
29 import org.apache.jackrabbit.webdav.property.DavPropertySet;
30
31
32
33
34
35
36 public class Webdav4FileContentInfoFactory implements FileContentInfoFactory {
37 @Override
38 public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
39 final Webdav4FileObject../../../org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.html#Webdav4FileObject">Webdav4FileObject file = (Webdav4FileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile());
40
41 String contentType = null;
42 String contentEncoding = null;
43
44 final DavPropertyNameSet nameSet = new DavPropertyNameSet();
45 nameSet.add(DavPropertyName.GETCONTENTTYPE);
46 final DavPropertySet propertySet = file.getProperties((GenericURLFileName) file.getName(), nameSet, true);
47
48 DavProperty property = propertySet.get(DavPropertyName.GETCONTENTTYPE);
49 if (property != null) {
50 contentType = (String) property.getValue();
51 }
52 property = propertySet.get(Webdav4FileObject.RESPONSE_CHARSET);
53 if (property != null) {
54 contentEncoding = (String) property.getValue();
55 }
56
57 return new DefaultFileContentInfo(contentType, contentEncoding);
58 }
59 }