1 17 18 package org.alfresco.filesys.smb.server.repo.pseudo; 19 20 import org.alfresco.filesys.server.SrvSession; 21 import org.alfresco.filesys.server.filesys.FileName; 22 import org.alfresco.filesys.server.filesys.TreeConnection; 23 import org.alfresco.filesys.smb.server.SMBSrvSession; 24 import org.alfresco.filesys.smb.server.repo.ContentContext; 25 import org.alfresco.filesys.smb.server.repo.FileState; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 36 public class ContentPseudoFileImpl implements PseudoFileInterface 37 { 38 40 private static final Log logger = LogFactory.getLog(ContentPseudoFileImpl.class); 41 42 50 public boolean isPseudoFile(SrvSession sess, TreeConnection tree, String path) 51 { 52 54 ContentContext ctx = (ContentContext) tree.getContext(); 55 boolean isPseudo = false; 56 57 String [] paths = FileName.splitPath( path); 58 FileState fstate = getStateForPath( ctx, paths[0]); 59 60 if ( fstate != null && fstate.hasPseudoFiles()) 61 { 62 64 PseudoFile pfile = fstate.getPseudoFileList().findFile( paths[1], false); 65 if ( pfile != null) 66 isPseudo = true; 67 } 68 69 71 return isPseudo; 72 } 73 74 82 public PseudoFile getPseudoFile(SrvSession sess, TreeConnection tree, String path) 83 { 84 86 ContentContext ctx = (ContentContext) tree.getContext(); 87 88 String [] paths = FileName.splitPath( path); 89 FileState fstate = getStateForPath( ctx, paths[0]); 90 91 if ( fstate != null && fstate.hasPseudoFiles()) 92 { 93 95 PseudoFile pfile = fstate.getPseudoFileList().findFile( paths[1], false); 96 if ( pfile != null) 97 return pfile; 98 } 99 100 102 return null; 103 } 104 105 113 public int addPseudoFilesToFolder(SrvSession sess, TreeConnection tree, String path) 114 { 115 117 int pseudoCnt = 0; 118 ContentContext ctx = (ContentContext) tree.getContext(); 119 FileState fstate = getStateForPath( ctx, path); 120 121 123 if ( fstate.hasPseudoFiles()) 124 return 0; 125 126 128 boolean isCIFS = sess instanceof SMBSrvSession; 129 130 132 if ( isCIFS && ctx.hasDragAndDropApp()) 133 { 134 136 if ( fstate == null) 137 ctx.getStateTable().findFileState( path, true, true); 138 139 142 String [] allPaths = FileName.splitAllPaths( path); 143 String lastPath = allPaths[allPaths.length - 1].toUpperCase(); 144 145 if ( lastPath.startsWith("DRAG") && fstate.hasPseudoFiles() == false) 146 { 147 149 fstate.addPseudoFile( ctx.getDragAndDropApp()); 150 151 153 pseudoCnt++; 154 155 157 if ( logger.isInfoEnabled()) 158 logger.info("Added drag/drop pseudo file for " + path); 159 } 160 } 161 162 164 if ( isCIFS && ctx.hasURLFile()) 165 { 166 168 if ( fstate.getNodeRef() != null) 169 { 170 172 StringBuilder urlStr = new StringBuilder (); 173 174 urlStr.append("[InternetShortcut]\r\n"); 175 urlStr.append("URL="); 176 urlStr.append(ctx.getURLPrefix()); 177 urlStr.append("navigate/browse/workspace/SpacesStore/"); 178 urlStr.append( fstate.getNodeRef().getId()); 179 urlStr.append("\r\n"); 180 181 183 byte[] urlData = urlStr.toString().getBytes(); 184 185 MemoryPseudoFile urlFile = new MemoryPseudoFile( ctx.getURLFileName(), urlData); 186 fstate.addPseudoFile( urlFile); 187 188 190 pseudoCnt++; 191 192 194 if ( logger.isInfoEnabled()) 195 logger.info("Added URL link pseudo file for " + path); 196 } 197 } 198 199 201 return pseudoCnt; 202 } 203 204 211 public void deletePseudoFile(SrvSession sess, TreeConnection tree, String path) 212 { 213 215 ContentContext ctx = (ContentContext) tree.getContext(); 216 217 219 String [] paths = FileName.splitPath( path); 220 FileState fstate = getStateForPath( ctx, paths[0]); 221 222 224 if ( fstate == null || fstate.hasPseudoFiles() == false) 225 return; 226 227 229 fstate.getPseudoFileList().removeFile( paths[1], false); 230 } 231 232 239 private final FileState getStateForPath(ContentContext ctx, String path) 240 { 241 243 FileState fstate = null; 244 245 if ( ctx.hasStateTable()) 246 { 247 249 fstate = ctx.getStateTable().findFileState(path); 250 } 251 252 254 return fstate; 255 } 256 } 257 | Popular Tags |