]>
git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.support/src/org/argeo/slc/vfs/VfsResource.java
1 package org
.argeo
.slc
.vfs
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
7 import java
.net
.URISyntaxException
;
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
;
17 public class VfsResource
implements Resource
{
18 private FileObject fileObject
;
20 public VfsResource(FileObject fileObject
) {
21 this.fileObject
= fileObject
;
24 public Resource
createRelative(String relativePath
) throws IOException
{
25 return new VfsResource(fileObject
.resolveFile(relativePath
,
26 NameScope
.DESCENDENT_OR_SELF
));
29 public boolean exists() {
31 return fileObject
.exists();
32 } catch (FileSystemException e
) {
33 throw new SlcException("Cannot find out whether " + fileObject
38 public String
getDescription() {
39 return "VFS resource " + fileObject
;
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).
52 public String
getFilename() {
53 return fileObject
.getName().getBaseName();
56 public URI
getURI() throws IOException
{
58 return new URI(fileObject
.getName().getURI());
59 } catch (URISyntaxException e
) {
60 throw new IOExceptionWithCause(e
);
64 public URL
getURL() throws IOException
{
65 return fileObject
.getURL();
68 public boolean isOpen() {
69 return fileObject
.isContentOpen();
72 public boolean isReadable() {
74 return fileObject
.isReadable();
75 } catch (FileSystemException e
) {
76 throw new SlcException("Cannot find out whether " + fileObject
81 public long lastModified() throws IOException
{
82 return fileObject
.getContent().getLastModifiedTime();
85 public InputStream
getInputStream() throws IOException
{
86 return fileObject
.getContent().getInputStream();
89 public FileObject
getFileObject() {
93 public long contentLength(){