]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.support/src/org/argeo/slc/vfs/VfsResource.java
2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.slc
.vfs
;
19 import java
.io
.IOException
;
20 import java
.io
.InputStream
;
22 import java
.net
.URISyntaxException
;
25 import org
.apache
.commons
.io
.IOExceptionWithCause
;
26 import org
.apache
.commons
.vfs2
.FileObject
;
27 import org
.apache
.commons
.vfs2
.FileSystemException
;
28 import org
.apache
.commons
.vfs2
.NameScope
;
29 import org
.argeo
.slc
.SlcException
;
30 import org
.springframework
.core
.io
.Resource
;
32 public class VfsResource
implements Resource
{
33 private FileObject fileObject
;
35 public VfsResource(FileObject fileObject
) {
36 this.fileObject
= fileObject
;
39 public Resource
createRelative(String relativePath
) throws IOException
{
40 return new VfsResource(fileObject
.resolveFile(relativePath
,
41 NameScope
.DESCENDENT_OR_SELF
));
44 public boolean exists() {
46 return fileObject
.exists();
47 } catch (FileSystemException e
) {
48 throw new SlcException("Cannot find out whether " + fileObject
53 public String
getDescription() {
54 return "VFS resource " + fileObject
;
57 public File
getFile() throws IOException
{
58 throw new IOException("Cannot access " + getDescription()
59 + " as a local file");
60 // TODO: access local files
61 // if(fileObject instanceof LocalFile){
62 // ((LocalFile)fileObject).
67 public String
getFilename() {
68 return fileObject
.getName().getBaseName();
71 public URI
getURI() throws IOException
{
73 return new URI(fileObject
.getName().getURI());
74 } catch (URISyntaxException e
) {
75 throw new IOExceptionWithCause(e
);
79 public URL
getURL() throws IOException
{
80 return fileObject
.getURL();
83 public boolean isOpen() {
84 return fileObject
.isContentOpen();
87 public boolean isReadable() {
89 return fileObject
.isReadable();
90 } catch (FileSystemException e
) {
91 throw new SlcException("Cannot find out whether " + fileObject
96 public long lastModified() throws IOException
{
97 return fileObject
.getContent().getLastModifiedTime();
100 public InputStream
getInputStream() throws IOException
{
101 return fileObject
.getContent().getInputStream();
104 public FileObject
getFileObject() {
108 public long contentLength(){