]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/vfs/VfsResource.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.vfs
;
20 import java
.io
.IOException
;
21 import java
.io
.InputStream
;
23 import java
.net
.URISyntaxException
;
26 import org
.apache
.commons
.io
.IOExceptionWithCause
;
27 import org
.apache
.commons
.vfs
.FileObject
;
28 import org
.apache
.commons
.vfs
.FileSystemException
;
29 import org
.apache
.commons
.vfs
.NameScope
;
30 import org
.argeo
.slc
.SlcException
;
31 import org
.springframework
.core
.io
.Resource
;
33 public class VfsResource
implements Resource
{
34 private FileObject fileObject
;
36 public VfsResource(FileObject fileObject
) {
37 this.fileObject
= fileObject
;
40 public Resource
createRelative(String relativePath
) throws IOException
{
41 return new VfsResource(fileObject
.resolveFile(relativePath
,
42 NameScope
.DESCENDENT_OR_SELF
));
45 public boolean exists() {
47 return fileObject
.exists();
48 } catch (FileSystemException e
) {
49 throw new SlcException("Cannot find out whether " + fileObject
54 public String
getDescription() {
55 return "VFS resource " + fileObject
;
58 public File
getFile() throws IOException
{
59 throw new IOException("Cannot access " + getDescription()
60 + " as a local file");
61 // TODO: access local files
62 // if(fileObject instanceof LocalFile){
63 // ((LocalFile)fileObject).
68 public String
getFilename() {
69 return fileObject
.getName().getBaseName();
72 public URI
getURI() throws IOException
{
74 return new URI(fileObject
.getName().getURI());
75 } catch (URISyntaxException e
) {
76 throw new IOExceptionWithCause(e
);
80 public URL
getURL() throws IOException
{
81 return fileObject
.getURL();
84 public boolean isOpen() {
85 return fileObject
.isContentOpen();
88 public boolean isReadable() {
90 return fileObject
.isReadable();
91 } catch (FileSystemException e
) {
92 throw new SlcException("Cannot find out whether " + fileObject
97 public long lastModified() throws IOException
{
98 return fileObject
.getContent().getLastModifiedTime();
101 public InputStream
getInputStream() throws IOException
{
102 return fileObject
.getContent().getInputStream();
105 public FileObject
getFileObject() {