1 19 20 package com.sslexplorer.networkplaces; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 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 50 public class NetworkPlaceVFSResource extends FileObjectVFSResource { 51 52 final static Log log = LogFactory.getLog(NetworkPlaceVFSResource.class); 53 54 65 public NetworkPlaceVFSResource(LaunchSession launchSession, VFSMount mount, VFSResource parent, String relativePath, VFSRepository repository, PasswordCredentials requestCredentials) throws IOException { 66 super(launchSession, mount, parent, relativePath, repository, requestCredentials); 67 } 68 69 72 public void delete() throws DAVMultiStatus, IOException { 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 82 public Iterator <VFSResource> getChildren() throws IOException { 83 if (!this.isCollection()) 84 return null; 85 86 this.getFile().close(); 88 89 FileObject children[] = this.getFile().getChildren(); 90 List <VFSResource> resources = new ArrayList <VFSResource>(children.length); 91 92 for (int x = 0; x < children.length; x++) { 93 String 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 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 130 131 VFSResource r = getMount().getResource(DAVUtilities.concatenatePaths(relativePath, fileName), requestCredentials); 132 if (!((AbstractNetworkPlaceMount)getMount()).getNetworkPlace().isAllowRecursive() && r.isCollection()) 133 continue; 134 resources.add(r); 135 } catch (Exception e) { 136 140 } 141 } 142 return resources.iterator(); 143 } 144 145 148 public String getDisplayName() { 149 if (isMount()) { 150 return ((AbstractNetworkPlaceMount)getMount()).getNetworkPlace().getResourceName() + "/"; 151 } 152 return super.getDisplayName(); 153 } 154 155 158 public boolean isMount() { 159 return getRelativePath().equals(""); 160 } 161 162 165 public String toString() { 166 return "Rel. URI = " + getRelativeURI() + ", Rel. Path = " + getRelativePath(); 167 } 168 } | Popular Tags |