KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > AbstractVFSResource


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.vfs;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.apache.commons.vfs.FileObject;
28
29 import com.sslexplorer.policyframework.LaunchSession;
30 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException;
31 import com.sslexplorer.vfs.webdav.DAVMultiStatus;
32 import com.sslexplorer.vfs.webdav.DAVUtilities;
33 import com.sslexplorer.vfs.webdav.methods.GET;
34
35 /**
36  * Abstract implementation of a {@link VFSResource}.
37  *
38  * @author Brett Smith <brett@3sp.com>
39  */

40 public abstract class AbstractVFSResource implements VFSResource {
41     
42     // Private instance variables
43
private boolean collection;
44     private String JavaDoc name;
45     private VFSResource parent;
46     private URI JavaDoc relativeUri;
47     private LaunchSession launchSession;
48     private VFSRepository repository;
49     
50
51     /**
52      * Constructor.
53      *
54      * @param launchSession
55      * @param relativeUri
56      * @param collection
57      * @param name
58      * @param parent
59      * @param repository
60      */

61     public AbstractVFSResource(LaunchSession launchSession, URI JavaDoc relativeUri, boolean collection, String JavaDoc name, VFSResource parent, VFSRepository repository) {
62         super();
63         this.launchSession = launchSession;
64         this.collection = collection;
65         this.name = name;
66         this.parent = parent;
67         this.relativeUri = relativeUri;
68         this.repository = repository;
69     }
70     
71     /* (non-Javadoc)
72      * @see com.sslexplorer.vfs.VFSResource#getLaunchSession()
73      */

74     public LaunchSession getLaunchSession() {
75         return launchSession;
76     }
77     
78     /* (non-Javadoc)
79      * @see com.sslexplorer.vfs.VFSResource#isMount()
80      */

81     public boolean isMount() {
82         return true;
83     }
84
85     /* (non-Javadoc)
86      * @see com.sslexplorer.vfs.VFSResource#verifyAccess()
87      */

88     public void verifyAccess() {
89             
90     }
91     /* (non-Javadoc)
92      * @see com.sslexplorer.vfs.VFSResource#getChildren()
93      */

94     public Iterator JavaDoc<VFSResource> getChildren() throws IOException JavaDoc, DAVAuthenticationRequiredException {
95         return null;
96     }
97     
98     /* (non-Javadoc)
99      * @see com.sslexplorer.vfs.VFSResource#getWebFolderPath()
100      */

101     public String JavaDoc getWebFolderPath() {
102         return parent == null ? "/fs/" : ( parent.getWebFolderPath() + relativeUri.getPath() + "/" );
103     }
104
105     /* (non-Javadoc)
106      * @see com.sslexplorer.vfs.VFSResource#getFile()
107      */

108     public FileObject getFile() throws IOException JavaDoc{
109         return null;
110     }
111
112     /* (non-Javadoc)
113      * @see java.lang.Comparable#compareTo(java.lang.Object)
114      */

115     public int compareTo(Object JavaDoc object) {
116         return toString().compareTo(object.toString());
117     }
118
119     /* (non-Javadoc)
120      * @see com.sslexplorer.vfs.VFSResource#isCollection()
121      */

122     public boolean isCollection() {
123         return collection;
124     }
125
126     /* (non-Javadoc)
127      * @see com.sslexplorer.vfs.VFSResource#isResource()
128      */

129     public boolean isResource() {
130         return !isCollection();
131     }
132
133     /* (non-Javadoc)
134      * @see com.sslexplorer.vfs.VFSResource#getMount()
135      */

136     public VFSMount getMount() {
137         return null;
138     }
139
140     /* (non-Javadoc)
141      * @see org.betaversion.webdav.DAVResource#getDisplayName()
142      */

143     public String JavaDoc getDisplayName() {
144         String JavaDoc name = this.name;
145         if (isCollection()) return (name + "/");
146         return name;
147     }
148
149     /* (non-Javadoc)
150      * @see com.sslexplorer.vfs.VFSResource#getRelativePath()
151      */

152     public String JavaDoc getRelativePath() {
153         return getRelativeURI().getPath();
154     }
155
156     /* (non-Javadoc)
157      * @see com.sslexplorer.vfs.VFSResource#getRelativeURI()
158      */

159     public URI JavaDoc getRelativeURI() {
160         return relativeUri;
161     }
162
163     /* (non-Javadoc)
164      * @see com.sslexplorer.vfs.VFSResource#getParent()
165      */

166     public VFSResource getParent() {
167         try {
168             if(parent == null) {
169                 String JavaDoc parentPath = DAVUtilities.stripLeadingSlash(DAVUtilities.getParentPath(getFullPath()));
170                 if(parentPath == null || parentPath.equals("/")) {
171                     return null;
172                 }
173                 else {
174                     return repository.getResource(getLaunchSession(), parentPath, null);
175                 }
176             }
177         } catch (Throwable JavaDoc throwable) {
178             throwable.printStackTrace();
179         }
180         return parent;
181     }
182
183     /* (non-Javadoc)
184      * @see com.sslexplorer.vfs.VFSResource#getContentType()
185      */

186     public String JavaDoc getContentType() {
187         if (this.isNull()) return null;
188         if (this.isCollection()) return GET.COLLECTION_MIME_TYPE;
189         String JavaDoc mime = DAVUtilities.getMimeType(this.getDisplayName());
190         return mime == null ? "application/octet-stream" : mime;
191     }
192
193     /* (non-Javadoc)
194      * @see com.sslexplorer.vfs.VFSResource#getContentLength()
195      */

196     public Long JavaDoc getContentLength() {
197         return null;
198     }
199
200     /* (non-Javadoc)
201      * @see com.sslexplorer.vfs.VFSResource#getLastModified()
202      */

203     public Date JavaDoc getLastModified() {
204         return new Date JavaDoc();
205     }
206
207     /* (non-Javadoc)
208      * @see com.sslexplorer.vfs.VFSResource#getEntityTag()
209      */

210     public String JavaDoc getEntityTag() {
211         if (this.isNull()) return null;
212         String JavaDoc path = this.getRelativePath();
213         return DAVUtilities.getETAG(path, this.getLastModified());
214     }
215
216     /* (non-Javadoc)
217      * @see com.sslexplorer.vfs.VFSResource#delete()
218      */

219     public void delete() throws DAVMultiStatus {
220     }
221
222     /* (non-Javadoc)
223      * @see com.sslexplorer.vfs.VFSResource#copy(com.sslexplorer.vfs.VFSResource, boolean, boolean)
224      */

225     public void copy(VFSResource dest, boolean overwrite, boolean recursive) throws DAVMultiStatus {
226     }
227
228     /* (non-Javadoc)
229      * @see com.sslexplorer.vfs.VFSResource#move(com.sslexplorer.vfs.VFSResource, boolean)
230      */

231     public void move(VFSResource dest, boolean overwrite) throws DAVMultiStatus {
232     }
233
234     /* (non-Javadoc)
235      * @see com.sslexplorer.vfs.VFSResource#makeCollection()
236      */

237     public void makeCollection() {
238     }
239
240     /* (non-Javadoc)
241      * @see com.sslexplorer.vfs.VFSResource#getInputStream()
242      */

243     public VFSInputStream getInputStream() {
244         return null;
245     }
246
247     /* (non-Javadoc)
248      * @see com.sslexplorer.vfs.VFSResource#getOutputStream()
249      */

250     public VFSOutputStream getOutputStream() {
251         return null;
252     }
253
254     /* (non-Javadoc)
255      * @see com.sslexplorer.vfs.VFSResource#isNull()
256      */

257     public boolean isNull() {
258         return false;
259     }
260
261     /* (non-Javadoc)
262      * @see com.sslexplorer.vfs.VFSResource#getBasename()
263      */

264     public String JavaDoc getBasename() {
265         return name;
266     }
267
268     /* (non-Javadoc)
269      * @see com.sslexplorer.vfs.VFSResource#getFullURI()
270      */

271     public URI JavaDoc getFullURI() {
272         VFSMount mount = getMount();
273         URI JavaDoc uri = URI.create( mount == null ? ( "/" + getRelativeURI() ) : ( "/" + DAVUtilities.encodePath(mount.getMountString(), true) + "/" + DAVUtilities.encodePath(getRelativePath(), true) ) );
274         return uri;
275     }
276     
277     /* (non-Javadoc)
278      * @see java.lang.Object#toString()
279      */

280     public String JavaDoc toString() {
281         return "Rel. URI = " + getRelativeURI() + ", Rel. Path = " + getRelativePath() + ", Name = " + name + " Mount = " + getMount().getMountString();
282     }
283
284     /* (non-Javadoc)
285      * @see com.sslexplorer.vfs.VFSResource#getFullPath()
286      */

287     public String JavaDoc getFullPath() {
288         VFSMount mount = getMount();
289         return mount == null ? ( "/" + getRelativeURI() ) : ( "/" + mount.getMountString() + "/" + getRelativePath());
290     }
291 }
292
Popular Tags