Package net.sf.jabref.autocompleter

Source Code of net.sf.jabref.autocompleter.NameFieldAutoCompleter

package net.sf.jabref.autocompleter;

import net.sf.jabref.AuthorList;
import net.sf.jabref.BibtexEntry;

/**
* Interpretes the given values as names and stores them in different
* permutations so we can complete by beginning with last name or first name.
*
* @author kahlert, cordes
*
*/
public class NameFieldAutoCompleter extends AbstractAutoCompleter {

  private String _fieldName;

  /**
   * @see AutoCompleterFactory
   */
  protected NameFieldAutoCompleter(String fieldName) {
    _fieldName = fieldName;
  }

  public boolean isSingleUnitField() {
    return false;
  }

  public void addBibtexEntry(String fieldValue, BibtexEntry entry) {
    addBibtexEntry(entry);
  }

  public void addBibtexEntry(BibtexEntry entry) {
    if (entry != null) {
      String fieldValue = entry.getField(_fieldName);
      if (fieldValue != null) {
        AuthorList authorList = AuthorList.getAuthorList(fieldValue);
        for (int i = 0; i < authorList.size(); i++) {
          AuthorList.Author author = authorList.getAuthor(i);
          addWordToIndex(author.getLastFirst(true));
          addWordToIndex(author.getLastFirst(false));
          addWordToIndex(author.getFirstLast(true));
          addWordToIndex(author.getFirstLast(false));
        }
      }
    }
  }

  public String[] complete(String str) {
    return super.complete(str);
  }

  public String getFieldName() {
    return _fieldName;
  }
}
TOP

Related Classes of net.sf.jabref.autocompleter.NameFieldAutoCompleter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.