Created
October 19, 2017 08:45
-
-
Save PatrickKwinten/4aa15ea09717833bcc9fd1a941d9e5a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wordpress.quintessens.demo.app; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Vector; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import lotus.domino.Directory; | |
import lotus.domino.DirectoryNavigator; | |
import lotus.domino.NotesException; | |
import lotus.domino.Session; | |
import com.ibm.xsp.complex.ValueBindingObjectImpl; | |
import com.ibm.xsp.extlib.component.picker.data.INamePickerData; | |
import com.ibm.xsp.extlib.component.picker.data.IPickerEntry; | |
import com.ibm.xsp.extlib.component.picker.data.IPickerOptions; | |
import com.ibm.xsp.extlib.component.picker.data.IPickerResult; | |
import com.ibm.xsp.extlib.component.picker.data.SimplePickerResult; | |
import com.ibm.xsp.model.domino.DominoUtils; | |
public class NamePickerDirectory extends ValueBindingObjectImpl implements INamePickerData { | |
public String[] getSourceLabels () { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public boolean hasCapability (final int arg0) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
public List<IPickerEntry> loadEntries (final Object[] arg0, final String[] arg1) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public IPickerResult readEntries (final IPickerOptions options) { | |
String startKey = options.getStartKey(); | |
int count = options.getCount(); | |
List<IPickerEntry> entries = new ArrayList<IPickerEntry>(); | |
if (startKey != null) { | |
// User is performing a search | |
try { | |
entries = this.dirLookup(startKey, count); | |
} catch (NotesException e) { | |
System.err.println("Exception trying to perform directory lookup: " + e.getMessage()); | |
e.printStackTrace(); | |
} | |
} | |
return new SimplePickerResult(entries, -1); | |
} | |
private final static Pattern nameAbbreviate = Pattern.compile("((O|OU)=|^CN=)"); | |
public ArrayList<IPickerEntry> dirLookup(final String search, final int limit) throws NotesException { | |
ArrayList<IPickerEntry> result = new ArrayList<IPickerEntry>(); | |
Session sess = DominoUtils.getCurrentSession(); | |
Directory dir = sess.getDirectory(); | |
dir.setSearchAllDirectories(true); | |
Vector<String> itemsToFetch = new Vector<String>(); | |
itemsToFetch.add("FullName"); | |
Vector<String> namesToLookup = new Vector<String>(); | |
namesToLookup.add(search); | |
DirectoryNavigator dirnav = dir.lookupNames("($Users)", namesToLookup, itemsToFetch, true); | |
int count = 0; | |
while (dirnav.isNameLocated()) { | |
while (dirnav.isMatchLocated() && count < limit) { | |
Vector<String> iv = dirnav.getFirstItemValue(); | |
String notesid = iv.get(0); | |
Matcher m = nameAbbreviate.matcher(notesid); | |
String val = m.replaceAll(""); | |
IPickerEntry entry = new SimplePickerResult.Entry(val, val); | |
result.add(entry); | |
dirnav.findNextMatch(); | |
count += 1; | |
} | |
dirnav.findNextName(); | |
} | |
dirnav.recycle(); | |
dir.recycle(); | |
sess.recycle(); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment