Пример #1
0
 private BibtexDatabase getDatabase() {
   Globals.prefs = JabRefPreferences.getInstance();
   File fileToLoad = new File(PATH_TO_TEST_BIBTEX);
   ParserResult pr = JabRef.openBibFile(fileToLoad.getPath(), true);
   BibtexDatabase filledDatabase = pr.getDatabase();
   return filledDatabase;
 }
  @Test
  public void testBasicSearchParsing() {
    Globals.prefs = JabRefPreferences.getInstance();

    BibtexEntry be = makeBibtexEntry();
    ContainBasedSearchRule bsCaseSensitive = new ContainBasedSearchRule(true);
    ContainBasedSearchRule bsCaseInsensitive = new ContainBasedSearchRule(false);
    RegexBasedSearchRule bsCaseSensitiveRegexp = new RegexBasedSearchRule(true);
    RegexBasedSearchRule bsCaseInsensitiveRegexp = new RegexBasedSearchRule(false);

    String query = "marine 2001 shields";

    Assert.assertEquals(false, bsCaseSensitive.applyRule(query, be));
    Assert.assertEquals(true, bsCaseInsensitive.applyRule(query, be));
    Assert.assertEquals(false, bsCaseSensitiveRegexp.applyRule(query, be));
    Assert.assertEquals(true, bsCaseInsensitiveRegexp.applyRule(query, be));

    query = "\"marine larviculture\"";

    Assert.assertEquals(false, bsCaseSensitive.applyRule(query, be));
    Assert.assertEquals(false, bsCaseInsensitive.applyRule(query, be));
    Assert.assertEquals(false, bsCaseSensitiveRegexp.applyRule(query, be));
    Assert.assertEquals(false, bsCaseInsensitiveRegexp.applyRule(query, be));

    query = "\"marine [A-Za-z]* larviculture\"";

    Assert.assertEquals(false, bsCaseSensitive.applyRule(query, be));
    Assert.assertEquals(false, bsCaseInsensitive.applyRule(query, be));
    Assert.assertEquals(false, bsCaseSensitiveRegexp.applyRule(query, be));
    Assert.assertEquals(true, bsCaseInsensitiveRegexp.applyRule(query, be));
  }
Пример #3
0
  public void testAutoCompleterFactory() {
    Globals.prefs = JabRefPreferences.getInstance();
    AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(AUTHOR_FIELD);
    assertTrue(autoCompleter instanceof NameFieldAutoCompleter);

    autoCompleter = AutoCompleterFactory.getFor(OTHER_FIELD);
    assertTrue(autoCompleter instanceof DefaultAutoCompleter);
  }
Пример #4
0
  public void testNameFieldCompleter() {
    Globals.prefs = JabRefPreferences.getInstance();
    AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(AUTHOR_FIELD);
    for (BibtexEntry entry : getDatabase().getEntries()) {
      autoCompleter.addBibtexEntry(entry);
    }

    // tweak preferences to match test cases
    boolean oldAutocomplete = Globals.prefs.getBoolean("autoComplete");
    Globals.prefs.putBoolean("autoComplete", Boolean.TRUE);
    boolean oldAutoCompFF = Globals.prefs.getBoolean("autoCompLF");
    Globals.prefs.putBoolean("autoCompFF", Boolean.FALSE);
    boolean oldAutoCompLF = Globals.prefs.getBoolean("autoCompLF");
    Globals.prefs.putBoolean("autoCompLF", Boolean.FALSE);
    String oldACFM = Globals.prefs.get(JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE);
    Globals.prefs.put(
        JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE,
        JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE_BOTH);

    assertEquals("Kostakos, V.", autoCompleter.complete("Kostakos")[0]);
    assertEquals(2, autoCompleter.complete("Kostakos").length);
    assertEquals("Kostakos, V.", autoCompleter.complete("Kosta")[0]);
    assertEquals(2, autoCompleter.complete("Kosta").length);
    assertEquals("Kostakos, Vassilis", autoCompleter.complete("Kostakos, Va")[0]);
    assertEquals(1, autoCompleter.complete("Kostakos, Va").length);
    assertEquals("Vassilis Kostakos", autoCompleter.complete("Va")[0]);
    assertEquals(1, autoCompleter.complete("Va").length);
    assertEquals(0, autoCompleter.complete("osta").length);
    assertEquals(0, autoCompleter.complete("osta").length);

    assertEquals("Eric von Hippel", autoCompleter.complete("Eric")[0]);
    assertEquals(1, autoCompleter.complete("Eric").length);
    assertEquals("von Hippel, E.", autoCompleter.complete("von")[0]);
    assertEquals(2, autoCompleter.complete("von").length);

    assertEquals("Reagle, Jr., J. M.", autoCompleter.complete("Reagle")[0]);
    assertEquals(2, autoCompleter.complete("Reagle").length);
    assertEquals("Reagle, Jr., Joseph M.", autoCompleter.complete("Reagle, Jr., Jo")[0]);
    assertEquals(1, autoCompleter.complete("Reagle, Jr., Jo").length);
    assertEquals("Joseph M. Reagle, Jr.", autoCompleter.complete("Joseph")[0]);
    assertEquals(1, autoCompleter.complete("Joseph").length);

    assertEquals("van den Huevel, Jr., J. A.", autoCompleter.complete("van den")[0]);
    assertEquals(2, autoCompleter.complete("van den").length);
    assertEquals("Johan A van den Huevel, Jr.", autoCompleter.complete("Joh")[0]);
    assertEquals(1, autoCompleter.complete("Joh").length);

    assertEquals("Jr. Sherry, John F.", autoCompleter.complete("Jr. S")[0]);
    assertEquals(1, autoCompleter.complete("Jr.").length);
    assertEquals("Sherry, John F., J.", autoCompleter.complete("Sherry")[0]);
    assertEquals(2, autoCompleter.complete("Sherry").length);

    // restore settings
    Globals.prefs.putBoolean("autoComplete", oldAutocomplete);
    Globals.prefs.putBoolean("autoCompFF", oldAutoCompFF);
    Globals.prefs.putBoolean("autoCompLF", oldAutoCompLF);
    Globals.prefs.put(JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE, oldACFM);
  }
Пример #5
0
  public BibtexParser(Reader in) {

    if (in == null) {
      throw new NullPointerException();
    }
    if (Globals.prefs == null) {
      Globals.prefs = JabRefPreferences.getInstance();
    }
    _in = new PushbackReader(in, LOOKAHEAD);
  }
Пример #6
0
  /**
   * @param panel (may be null) If not given no toolbar is shown on the right hand side.
   * @param databaseContext (may be null) Used for resolving pdf directories for links.
   * @param layoutFile (must be given) Used for layout
   */
  public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, String layoutFile) {
    super(new BorderLayout(), true);

    this.databaseContext = Optional.ofNullable(databaseContext);
    this.layoutFile = Objects.requireNonNull(layoutFile);
    updateLayout();

    this.closeAction = new CloseAction();
    this.printAction = new PrintAction();
    this.copyPreviewAction = new CopyPreviewAction();

    this.basePanel = Optional.ofNullable(panel);

    createPreviewPane();

    if (panel != null) {
      // dropped files handler only created for main window
      // not for Windows as like the search results window
      this.previewPane.setTransferHandler(
          new PreviewPanelTransferHandler(
              panel.frame(), this, this.previewPane.getTransferHandler()));
    }

    // Set up scroll pane for preview pane
    scrollPane =
        new JScrollPane(
            previewPane,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(null);

    /*
     * If we have been given a panel and the preference option
     * previewPrintButton is set, show the tool bar
     */
    if (this.basePanel.isPresent()
        && JabRefPreferences.getInstance().getBoolean(JabRefPreferences.PREVIEW_PRINT_BUTTON)) {
      add(createToolBar(), BorderLayout.LINE_START);
    }

    add(scrollPane, BorderLayout.CENTER);

    this.createKeyBindings();
  }
Пример #7
0
  @Test
  @Ignore
  public void testInsertTestData() throws Exception {

    entry1 = new BibtexEntry();
    JabRefPreferences jabRefPreferences = JabRefPreferences.getInstance();
    ExternalFileType fileType = jabRefPreferences.getExternalFileTypeByExt("PDF");
    FileListEntry fileListEntry =
        new FileListEntry("", ImportDataTest.FILE_IN_DATABASE.getAbsolutePath(), fileType);

    FileListTableModel model = new FileListTableModel();
    model.addEntry(0, fileListEntry);

    entry1.setField("file", model.getStringRepresentation());

    database.insertEntry(entry1);

    // #################### SETUP END ##################### //

    UnlinkedFilesCrawler crawler = new UnlinkedFilesCrawler(database);
    CheckableTreeNode treeNode =
        crawler.searchDirectory(ImportDataTest.EXISTING_FOLDER, new EntryFromPDFCreator());

    Assert.assertNotNull(treeNode);

    /** Select all nodes manually. */
    @SuppressWarnings("unchecked")
    Enumeration<CheckableTreeNode> enumeration = treeNode.breadthFirstEnumeration();
    while (enumeration.hasMoreElements()) {
      CheckableTreeNode nextElement = enumeration.nextElement();
      nextElement.setSelected(true);
    }

    List<File> resultList = getFileListFromNode(treeNode);

    Assert.assertFalse(resultList.isEmpty());
    Assert.assertTrue(resultList.contains(ImportDataTest.FILE_NOT_IN_DATABASE));
    Assert.assertFalse(resultList.contains(ImportDataTest.FILE_IN_DATABASE));
  }
Пример #8
0
 @Before
 public void setUp() {
   prefs = JabRefPreferences.getInstance();
   backup = prefs;
 }
Пример #9
0
  public void setUp() throws Exception {

    Globals.prefs = JabRefPreferences.getInstance();
    oldUseRegExp = Globals.prefs.getBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY);
    oldAutoLinkExcatKeyOnly = Globals.prefs.getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY);
    oldPdfDirectory = Globals.prefs.get("pdfDirectory");

    Globals.prefs.putBoolean(JabRefPreferences.USE_REG_EXP_SEARCH_KEY, false);
    Globals.prefs.putBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY, false);

    getBibtexEntry();
    assertNotNull(database);
    assertNotNull(entry);

    // Create file structure
    try {
      root = createTempDir("UtilFindFileTest");

      Globals.prefs.put("pdfDirectory", root.getPath());

      File subDir1 = new File(root, "Organization Science");
      subDir1.mkdir();

      File pdf1 = new File(subDir1, "HipKro03 - Hello.pdf");
      pdf1.createNewFile();

      File pdf1a = new File(root, "HipKro03 - Hello.pdf");
      pdf1a.createNewFile();

      File subDir2 = new File(root, "pdfs");
      subDir2.mkdir();

      File subsubDir1 = new File(subDir2, "sub");
      subsubDir1.mkdir();

      File pdf2 = new File(subsubDir1, "HipKro03-sub.pdf");
      pdf2.createNewFile();

      File dir2002 = new File(root, "2002");
      dir2002.mkdir();

      File dir2003 = new File(root, "2003");
      dir2003.mkdir();

      File pdf3 = new File(dir2003, "Paper by HipKro03.pdf");
      pdf3.createNewFile();

      File dirTest = new File(root, "test");
      dirTest.mkdir();

      File pdf4 = new File(dirTest, "HipKro03.pdf");
      pdf4.createNewFile();

      File pdf5 = new File(dirTest, ".TEST");
      pdf5.createNewFile();

      File pdf6 = new File(dirTest, "TEST[");
      pdf6.createNewFile();

      File pdf7 = new File(dirTest, "TE.ST");
      pdf7.createNewFile();

      File foo = new File(dirTest, "foo.dat");
      foo.createNewFile();

      File graphicsDir = new File(root, "graphicsDir");
      graphicsDir.mkdir();

      File graphicsSubDir = new File(graphicsDir, "subDir");
      graphicsSubDir.mkdir();

      File jpg = new File(graphicsSubDir, "HipKro03test.jpg");
      jpg.createNewFile();

      File png = new File(graphicsSubDir, "HipKro03test.png");
      png.createNewFile();

    } catch (Exception e) {
      throw new RuntimeException();
    }
  }
Пример #10
0
 @Before
 public void setUp() throws URISyntaxException {
   Globals.prefs = JabRefPreferences.getInstance();
   xmlFile = Paths.get(MsBibImporter.class.getResource(fileName + ".xml").toURI());
 }
Пример #11
0
 @Before
 public void setUp() throws Exception {
   Globals.prefs = JabRefPreferences.getInstance();
   backup = Globals.prefs;
   Globals.prefs.putBoolean(JabRefPreferences.BIBLATEX_MODE, true);
 }
Пример #12
0
 @Before
 public void setPreferences() {
   Globals.prefs = JabRefPreferences.getInstance();
 }
Пример #13
0
 @Before
 public void setUp() throws Exception {
   if (Globals.prefs == null) {
     Globals.prefs = JabRefPreferences.getInstance();
   }
 }