KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > networkplaces > NetworkPlaceVFSResource


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.networkplaces;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.commons.vfs.FileObject;
30 import org.apache.commons.vfs.FileSystemException;
31
32 import com.sslexplorer.policyframework.LaunchSession;
33 import com.sslexplorer.security.PasswordCredentials;
34 import com.sslexplorer.vfs.FileObjectVFSResource;
35 import com.sslexplorer.vfs.VFSMount;
36 import com.sslexplorer.vfs.VFSRepository;
37 import com.sslexplorer.vfs.VFSResource;
38 import com.sslexplorer.vfs.webdav.DAVException;
39 import com.sslexplorer.vfs.webdav.DAVMultiStatus;
40 import com.sslexplorer.vfs.webdav.DAVUtilities;
41
42 /**
43  * Extension of {@link FileObjectVFSResource} for use with resources
44  * controlled by a <i>Network Place</i>
45  *
46  * @author James D Robinson <a HREF="mailto: james@3sp.com">&lt;james@3sp.com&gt;</a> *
47  * @author Lee David Painter <a HREF="mailto: lee@3sp.com">&lt;lee@3sp.com&gt;</a>
48  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
49  */

50 public class NetworkPlaceVFSResource extends FileObjectVFSResource {
51
52     final static Log log = LogFactory.getLog(NetworkPlaceVFSResource.class);
53
54     /**
55      * Constructor.
56      *
57      * @param launchSession
58      * @param mount
59      * @param parent
60      * @param relativePath
61      * @param repository
62      * @param requestCredentials
63      * @throws IOException
64      */

65     public NetworkPlaceVFSResource(LaunchSession launchSession, VFSMount mount, VFSResource parent, String JavaDoc relativePath, VFSRepository repository, PasswordCredentials requestCredentials) throws IOException JavaDoc {
66         super(launchSession, mount, parent, relativePath, repository, requestCredentials);
67     }
68
69     /* (non-Javadoc)
70      * @see com.sslexplorer.vfs.FileObjectVFSResource#delete()
71      */

72     public void delete() throws DAVMultiStatus, IOException JavaDoc {
73         if (((AbstractNetworkPlaceMount) getMount()).getNetworkPlace().isNoDelete()) {
74             throw new DAVException(500, "This resource cannot be deleted because the system policy does not allow deletion.");
75         }
76         super.delete();
77     }
78     
79     /* (non-Javadoc)
80      * @see com.sslexplorer.vfs.FileObjectVFSResource#getChildren()
81      */

82     public Iterator JavaDoc<VFSResource> getChildren() throws IOException JavaDoc {
83         if (!this.isCollection())
84             return null;
85
86         // this forces VFS to re cashe.
87
this.getFile().close();
88
89         FileObject children[] = this.getFile().getChildren();
90         List JavaDoc<VFSResource> resources = new ArrayList JavaDoc<VFSResource>(children.length);
91
92         for (int x = 0; x < children.length; x++) {
93             String JavaDoc fileName = children[x].getName().getBaseName();
94             if (fileName.startsWith(PREFIX) && fileName.endsWith(SUFFIX)) {
95                 continue;
96             }
97             if (fileName.equalsIgnoreCase(PAGEFILE_SYS)) {
98                 continue;
99             }
100             
101             // Test if a file is hidden, but do not fail if this test fails, just exclude the file
102
try {
103                 if (!((AbstractNetworkPlaceMount)getMount()).getNetworkPlace().isShowHidden() && children[x].isHidden()) {
104                     continue;
105                 }
106             }
107             catch(FileSystemException fse) {
108                 log.warn("Could not determine if file " + children[x].getName() + " is hidden.");
109                 continue;
110             }
111             
112             if (!isCollection() && !isResource()) {
113                 continue;
114             }
115             try {
116                 /*
117                  * TODO BPS - I think we have a problem here.
118                  *
119                  * When getting children that require further authentication we
120                  * get a {@link DAVAuthenticationRequiredException} exception.
121                  * We do not want to throw an exception at this point but we do
122                  * want add the child. Its only when children of the child are
123                  * accessed that we want to throw the exception. Because
124                  * DAVMount.getResource() is the one that throws this, a
125                  * resource object can never be created.
126                  *
127                  * This will happen for example when listomg /fs/[store] and a
128                  * network place that requires auth. is hit.
129                  */

130
131                 VFSResource r = getMount().getResource(DAVUtilities.concatenatePaths(relativePath, fileName), requestCredentials/*, transaction*/);
132                 if (!((AbstractNetworkPlaceMount)getMount()).getNetworkPlace().isAllowRecursive() && r.isCollection())
133                     continue;
134                 resources.add(r);
135             } catch (Exception JavaDoc e) {
136                 /*
137                  * NOTE - BPS - We cannot log this exception as it may have user
138                  * information in the URI.
139                  */

140             }
141         }
142         return resources.iterator();
143     }
144
145     /* (non-Javadoc)
146      * @see com.sslexplorer.vfs.FileObjectVFSResource#getDisplayName()
147      */

148     public String JavaDoc getDisplayName() {
149         if (isMount()) {
150             return ((AbstractNetworkPlaceMount)getMount()).getNetworkPlace().getResourceName() + "/";
151         }
152         return super.getDisplayName();
153     }
154
155     /* (non-Javadoc)
156      * @see com.sslexplorer.vfs.FileObjectVFSResource#isMount()
157      */

158     public boolean isMount() {
159         return getRelativePath().equals("");
160     }
161
162     /* (non-Javadoc)
163      * @see java.lang.Object#toString()
164      */

165     public String JavaDoc toString() {
166         return "Rel. URI = " + getRelativeURI() + ", Rel. Path = " + getRelativePath();
167     }
168 }
Popular Tags