KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > servlets > webdav > ApplicationPath


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.servlets.webdav;
30
31 import com.caucho.server.webapp.Application;
32 import com.caucho.util.NullIterator;
33 import com.caucho.vfs.Path;
34
35 import javax.servlet.ServletContext JavaDoc;
36 import javax.servlet.http.HttpServletRequest JavaDoc;
37 import java.io.IOException JavaDoc;
38 import java.io.InputStream JavaDoc;
39 import java.io.OutputStream JavaDoc;
40 import java.util.Iterator JavaDoc;
41
42 /**
43  * Represents a virtual filesystem.
44  */

45 public class ApplicationPath extends AbstractPath {
46   /**
47    * Returns true if the named file is a file.
48    *
49    * @param path the requested relative path
50    */

51   public boolean isFile(String JavaDoc path,
52                         HttpServletRequest JavaDoc request,
53                         ServletContext JavaDoc app)
54     throws IOException JavaDoc
55   {
56     return getPath(path, request, app).isFile();
57   }
58   
59   /**
60    * Returns true if the named file is a directory.
61    *
62    * @param path the requested relative path
63    */

64   public boolean isDirectory(String JavaDoc path,
65                              HttpServletRequest JavaDoc request,
66                              ServletContext JavaDoc app)
67     throws IOException JavaDoc
68   {
69     return getPath(path, request, app).isDirectory();
70   }
71   
72   /**
73    * Returns true if the file can be read.
74    *
75    * @param path the requested relative path
76    */

77   public boolean canRead(String JavaDoc path,
78                          HttpServletRequest JavaDoc request,
79                          ServletContext JavaDoc app)
80     throws IOException JavaDoc
81   {
82     return getPath(path, request, app).canRead();
83   }
84   
85   /**
86    * Returns true if the file exists.
87    *
88    * @param path the requested relative path
89    */

90   public boolean exists(String JavaDoc path,
91                         HttpServletRequest JavaDoc request,
92                         ServletContext JavaDoc app)
93     throws IOException JavaDoc
94   {
95     return getPath(path, request, app).exists();
96   }
97   
98   /**
99    * Returns the length of the named file.
100    *
101    * @param path the requested relative path
102    */

103   public long getLength(String JavaDoc path,
104                         HttpServletRequest JavaDoc request,
105                         ServletContext JavaDoc app)
106     throws IOException JavaDoc
107   {
108     return getPath(path, request, app).getLength();
109   }
110   
111   /**
112    * Returns the last modified time of the named file.
113    *
114    * @param path the requested relative path
115    */

116   public long getLastModified(String JavaDoc path,
117                               HttpServletRequest JavaDoc request,
118                               ServletContext JavaDoc app)
119     throws IOException JavaDoc
120   {
121     return getPath(path, request, app).getLastModified();
122   }
123   
124   /**
125    * Returns an iterator over the attribute names.
126    * Each attribute name is of the type AttributeName.
127    *
128    * @param path the requested relative path
129    * @param request the servlet request
130    * @param app the servlet context
131    */

132   public Iterator getAttributeNames(String JavaDoc path,
133                     HttpServletRequest JavaDoc request,
134                     ServletContext JavaDoc app)
135     throws IOException JavaDoc
136   {
137     return NullIterator.create();
138   }
139   
140   /**
141    * Returns an attribute value.
142    *
143    * @param name the attribute name
144    * @param path the requested relative path
145    * @param request the servlet request
146    * @param app the servlet context
147    */

148   public String JavaDoc getAttribute(AttributeName name,
149                              String JavaDoc path,
150                              HttpServletRequest JavaDoc request,
151                              ServletContext JavaDoc app)
152     throws IOException JavaDoc
153   {
154     return null;
155   }
156   
157   /**
158    * Sets an attribute value.
159    *
160    * @param name the attribute name
161    * @param value the attribute value
162    * @param path the requested relative path
163    * @param request the servlet request
164    * @param app the servlet context
165    *
166    * @return true if the setting was successful
167    */

168   public boolean setAttribute(AttributeName name, String JavaDoc value,
169                               String JavaDoc path,
170                               HttpServletRequest JavaDoc request,
171                               ServletContext JavaDoc app)
172     throws IOException JavaDoc
173   {
174     return false;
175   }
176   
177   /**
178    * Removes an attribute value.
179    *
180    * @param name the attribute name
181    * @param path the requested relative path
182    * @param request the servlet request
183    * @param app the servlet context
184    */

185   public void removeAttribute(String JavaDoc name,
186                               String JavaDoc path,
187                               HttpServletRequest JavaDoc request,
188                               ServletContext JavaDoc app)
189     throws IOException JavaDoc
190   {
191   }
192   
193   /**
194    * Returns a list of the files in the directory.
195    *
196    * @param path the requested relative path
197    */

198   public String JavaDoc []list(String JavaDoc path,
199                        HttpServletRequest JavaDoc request,
200                        ServletContext JavaDoc app)
201     throws IOException JavaDoc
202   {
203     return getPath(path, request, app).list();
204   }
205   
206   /**
207    * Creates the named directory.
208    *
209    * @param path the requested relative path
210    *
211    * @return true if the creation succeeded.
212    */

213   public boolean mkdir(String JavaDoc path,
214                        HttpServletRequest JavaDoc request,
215                        ServletContext JavaDoc app)
216     throws IOException JavaDoc
217   {
218     return getPath(path, request, app).mkdir();
219   }
220   
221   /**
222    * Removes the named directory.
223    *
224    * @param path the requested relative path
225    *
226    * @return true if the remove succeeded.
227    */

228   public boolean rmdir(String JavaDoc path,
229                        HttpServletRequest JavaDoc request,
230                        ServletContext JavaDoc app)
231     throws IOException JavaDoc
232   {
233     return getPath(path, request, app).remove();
234   }
235   
236   /**
237    * Deletes the file
238    *
239    * @param path the requested relative path
240    *
241    * @return true if the remove succeeded.
242    */

243   public boolean remove(String JavaDoc path,
244                         HttpServletRequest JavaDoc request,
245                         ServletContext JavaDoc app)
246     throws IOException JavaDoc
247   {
248     return getPath(path, request, app).remove();
249   }
250   
251   /**
252    * Opens an OutputStream for writing.
253    *
254    * @param path the requested relative path
255    *
256    * @return the output stream to the resource.
257    */

258   public OutputStream JavaDoc openWrite(String JavaDoc path,
259                                 HttpServletRequest JavaDoc request,
260                                 ServletContext JavaDoc app)
261     throws IOException JavaDoc
262   {
263     return getPath(path, request, app).openWrite();
264   }
265   
266   /**
267    * Opens an InputStream for reading
268    *
269    * @param path the requested relative path
270    *
271    * @return the input stream to the resource.
272    */

273   public InputStream JavaDoc openRead(String JavaDoc path,
274                               HttpServletRequest JavaDoc request,
275                               ServletContext JavaDoc app)
276     throws IOException JavaDoc
277   {
278     return getPath(path, request, app).openRead();
279   }
280
281   /**
282    * Returns the underlying path.
283    */

284   protected Path getPath(String JavaDoc path,
285                          HttpServletRequest JavaDoc request,
286                          ServletContext JavaDoc app)
287     throws IOException JavaDoc
288   {
289     Path appDir = ((Application) app).getAppDir();
290
291     return appDir.lookup("./" + path);
292   }
293 }
294
Popular Tags