]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.support/src/org/argeo/slc/vfs/VfsResource.java
Remove unused.
[gpl/argeo-slc.git] / cms / org.argeo.slc.support / src / org / argeo / slc / vfs / VfsResource.java
1 package org.argeo.slc.vfs;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.net.URI;
7 import java.net.URISyntaxException;
8 import java.net.URL;
9
10 import org.apache.commons.io.IOExceptionWithCause;
11 import org.apache.commons.vfs2.FileObject;
12 import org.apache.commons.vfs2.FileSystemException;
13 import org.apache.commons.vfs2.NameScope;
14 import org.argeo.slc.SlcException;
15 import org.springframework.core.io.Resource;
16
17 public class VfsResource implements Resource {
18 private FileObject fileObject;
19
20 public VfsResource(FileObject fileObject) {
21 this.fileObject = fileObject;
22 }
23
24 public Resource createRelative(String relativePath) throws IOException {
25 return new VfsResource(fileObject.resolveFile(relativePath,
26 NameScope.DESCENDENT_OR_SELF));
27 }
28
29 public boolean exists() {
30 try {
31 return fileObject.exists();
32 } catch (FileSystemException e) {
33 throw new SlcException("Cannot find out whether " + fileObject
34 + " exists", e);
35 }
36 }
37
38 public String getDescription() {
39 return "VFS resource " + fileObject;
40 }
41
42 public File getFile() throws IOException {
43 throw new IOException("Cannot access " + getDescription()
44 + " as a local file");
45 // TODO: access local files
46 // if(fileObject instanceof LocalFile){
47 // ((LocalFile)fileObject).
48 // }
49 // return null;
50 }
51
52 public String getFilename() {
53 return fileObject.getName().getBaseName();
54 }
55
56 public URI getURI() throws IOException {
57 try {
58 return new URI(fileObject.getName().getURI());
59 } catch (URISyntaxException e) {
60 throw new IOExceptionWithCause(e);
61 }
62 }
63
64 public URL getURL() throws IOException {
65 return fileObject.getURL();
66 }
67
68 public boolean isOpen() {
69 return fileObject.isContentOpen();
70 }
71
72 public boolean isReadable() {
73 try {
74 return fileObject.isReadable();
75 } catch (FileSystemException e) {
76 throw new SlcException("Cannot find out whether " + fileObject
77 + " is readable", e);
78 }
79 }
80
81 public long lastModified() throws IOException {
82 return fileObject.getContent().getLastModifiedTime();
83 }
84
85 public InputStream getInputStream() throws IOException {
86 return fileObject.getContent().getInputStream();
87 }
88
89 public FileObject getFileObject() {
90 return fileObject;
91 }
92
93 public long contentLength(){
94 return -1;
95 }
96 }