1 16 package com.blandware.atleap.search.filters; 17 18 import org.apache.lucene.search.Filter; 19 import org.apache.lucene.index.IndexReader; 20 import org.apache.lucene.document.Document; 21 22 import java.util.BitSet ; 23 import java.util.List ; 24 import java.io.IOException ; 25 26 import com.blandware.atleap.search.SearchManager; 27 import com.blandware.atleap.common.util.ConvertUtil; 28 29 37 public class RolesFilter extends Filter { 38 39 private String userRoles = null; 40 41 46 public RolesFilter(String userRoles) { 47 if (userRoles == null) { 48 this.userRoles = ""; 49 } else { 50 this.userRoles = userRoles.trim(); 51 } 52 } 53 54 57 public BitSet bits(IndexReader reader) throws IOException 58 { 59 BitSet bits = new BitSet (reader.maxDoc()); 60 61 for (int i = 0; i < reader.maxDoc(); i++) { 62 Document document = reader.document(i); 63 String docRoles = document.get(SearchManager.ROLES_FIELD); 64 65 if (docRoles == null) { 66 docRoles = ""; 67 } else { 68 docRoles = docRoles.trim(); 69 } 70 71 if (docRoles.length() == 0) { 72 bits.set(i); 73 } else if (userRoles.length() == 0) { 74 continue; 75 } else { 76 List userRolesList = ConvertUtil.convertStringToList(userRoles, ",", true); 77 List docRolesList = ConvertUtil.convertStringToList(docRoles, ",", true); 78 for (int j = 0; j < docRolesList.size(); j++) { 79 String docRole = (String ) docRolesList.get(j); 80 if (userRolesList.contains(docRole)) { 81 bits.set(i); 82 break; 83 } 84 } 85 } 86 } 87 return bits; 88 } 89 90 } 91 | Popular Tags |