1 17 package org.alfresco.filesys.smb.server.repo; 18 19 import java.io.FileNotFoundException ; 20 import java.util.List ; 21 22 import org.alfresco.filesys.server.filesys.FileInfo; 23 import org.alfresco.filesys.server.filesys.SearchContext; 24 import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFile; 25 import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFileList; 26 import org.alfresco.service.cmr.repository.NodeRef; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 37 public class ContentSearchContext extends SearchContext 38 { 39 private static final Log logger = LogFactory.getLog(ContentSearchContext.class); 40 41 private CifsHelper cifsHelper; 42 private List <NodeRef> results; 43 private int index = -1; 44 45 47 private PseudoFileList pseudoList; 48 private boolean donePseudoFiles = false; 49 50 52 private int resumeId; 53 54 62 protected ContentSearchContext( 63 CifsHelper cifsHelper, 64 List <NodeRef> results, 65 String searchStr, 66 PseudoFileList pseudoList) 67 { 68 super(); 69 super.setSearchString(searchStr); 70 this.cifsHelper = cifsHelper; 71 this.results = results; 72 this.pseudoList = pseudoList; 73 } 74 75 80 public String toString() 81 { 82 StringBuilder sb = new StringBuilder (60); 83 sb.append("ContentSearchContext") 84 .append("[ searchStr=").append(getSearchString()) 85 .append(", resultCount=").append(results.size()) 86 .append("]"); 87 return sb.toString(); 88 } 89 90 95 public int getResumeId() 96 { 97 return resumeId; 98 } 99 100 105 public boolean hasMoreFiles() 106 { 107 109 if ( donePseudoFiles == false && pseudoList != null && index < (pseudoList.numberOfFiles() - 1)) 110 return true; 111 return index < (results.size() - 1); 112 } 113 114 121 public boolean nextFileInfo(FileInfo info) 122 { 123 125 if (!hasMoreFiles()) 126 return false; 127 128 130 index++; 131 resumeId++; 132 133 135 if ( donePseudoFiles == false && pseudoList != null) 136 { 137 if ( index < pseudoList.numberOfFiles()) 138 { 139 PseudoFile pfile = pseudoList.getFileAt( index); 140 if ( pfile != null) 141 { 142 144 FileInfo pinfo = pfile.getFileInfo(); 145 146 148 info.copyFrom( pinfo); 149 150 152 if ( index == (pseudoList.numberOfFiles() - 1)) 153 { 154 156 donePseudoFiles = true; 157 index = -1; 158 } 159 160 162 return true; 163 } 164 } 165 } 166 167 169 NodeRef nextNodeRef = results.get(index); 170 171 try 172 { 173 175 FileInfo nextInfo = cifsHelper.getFileInformation(nextNodeRef, ""); 176 info.copyFrom(nextInfo); 177 178 180 return true; 181 } 182 catch (FileNotFoundException e) 183 { 184 } 185 186 188 return false; 189 } 190 191 197 public String nextFileName() 198 { 199 201 if (!hasMoreFiles()) 202 return null; 203 204 206 index++; 207 resumeId++; 208 209 211 if ( donePseudoFiles == false && pseudoList != null) 212 { 213 if ( index < pseudoList.numberOfFiles()) 214 { 215 PseudoFile pfile = pseudoList.getFileAt( index); 216 if ( pfile != null) 217 { 218 220 FileInfo pinfo = pfile.getFileInfo(); 221 222 224 return pinfo.getFileName(); 225 } 226 } 227 else 228 { 229 231 donePseudoFiles = true; 232 index = -1; 233 234 if ( results == null || results.size() == 0) 235 return null; 236 } 237 } 238 239 241 NodeRef nextNodeRef = results.get(index); 242 243 try 244 { 245 247 FileInfo nextInfo = cifsHelper.getFileInformation(nextNodeRef, ""); 248 249 251 return nextInfo.getFileName(); 252 } 253 catch (FileNotFoundException e) 254 { 255 } 256 257 259 return null; 260 } 261 262 268 public boolean restartAt(FileInfo info) 269 { 270 272 int resId = 0; 273 274 if (pseudoList != null) 275 { 276 while ( resId < pseudoList.numberOfFiles()) 277 { 278 280 PseudoFile pfile = pseudoList.getFileAt(resId); 281 if ( pfile.getFileName().equals(info.getFileName())) 282 { 283 285 donePseudoFiles = false; 286 index = resId - 1; 287 288 return true; 289 } 290 else 291 resId++; 292 } 293 } 294 295 297 if ( results != null) 298 { 299 int idx = 0; 300 301 while ( idx < results.size()) 302 { 303 305 String fname = cifsHelper.getFileName( results.get( idx)); 306 if ( fname != null && fname.equals( info.getFileName())) 307 { 308 index = idx - 1; 309 resumeId = resId - 1; 310 donePseudoFiles = true; 311 312 return true; 313 } 314 else 315 { 316 idx++; 317 resId++; 318 } 319 } 320 } 321 322 324 return false; 325 } 326 327 333 public boolean restartAt(int resumeId) 334 { 335 337 if (pseudoList != null) 338 { 339 if ( resumeId < pseudoList.numberOfFiles()) 340 { 341 343 index = resumeId; 344 donePseudoFiles = false; 345 346 return true; 347 } 348 else 349 { 350 352 resumeId -= pseudoList.numberOfFiles(); 353 } 354 } 355 356 358 if ( results != null && resumeId < results.size()) 359 { 360 index = resumeId; 361 donePseudoFiles = true; 362 363 return true; 364 } 365 366 368 return false; 369 } 370 } 371 | Popular Tags |