Example #1
0
  /**
   * Generates the SQL required to populate the strings table with jabref data.
   *
   * @param database BibtexDatabase object used from where the strings will be exported
   * @param out The output (PrintStream or Connection) object to which the DML should be written.
   * @param database_id ID of Jabref database related to the entries to be exported This information
   *     can be gathered using getDatabaseIDByPath(metaData, out)
   * @throws SQLException
   */
  private void populateStringTable(BibtexDatabase database, Object out, int database_id)
      throws SQLException {
    String insert = "INSERT INTO strings (label, content, database_id) VALUES (";

    if (database.getPreamble() != null) {
      String dml =
          insert
              + "'@PREAMBLE', "
              + '\''
              + StringUtil.quote(database.getPreamble(), "'", '\\')
              + "', "
              + '\''
              + database_id
              + "');";
      SQLUtil.processQuery(out, dml);
    }
    for (String key : database.getStringKeySet()) {
      BibtexString string = database.getString(key);
      String dml =
          insert
              + '\''
              + StringUtil.quote(string.getName(), "'", '\\')
              + "', "
              + '\''
              + StringUtil.quote(string.getContent(), "'", '\\')
              + "', "
              + '\''
              + database_id
              + '\''
              + ");";
      SQLUtil.processQuery(out, dml);
    }
  }
  @Test
  @Ignore
  public void testAddEntrysFromFiles() throws Exception {
    ParserResult result =
        BibtexParser.parse(new FileReader(ImportDataTest.UNLINKED_FILES_TEST_BIB));
    BibtexDatabase database = result.getDatabase();

    List<File> files = new ArrayList<File>();

    files.add(ImportDataTest.FILE_NOT_IN_DATABASE);
    files.add(ImportDataTest.NOT_EXISTING_PDF);

    EntryFromFileCreatorManager manager = new EntryFromFileCreatorManager();
    List<String> errors = manager.addEntrysFromFiles(files, database, null, true);

    /** One file doesn't exist, so adding it as an entry should lead to an error message. */
    Assert.assertEquals(1, errors.size());

    boolean file1Found = false;
    boolean file2Found = false;
    for (BibtexEntry entry : database.getEntries()) {
      String filesInfo = entry.getField("file");
      if (filesInfo.contains(files.get(0).getName())) {
        file1Found = true;
      }
      if (filesInfo.contains(files.get(1).getName())) {
        file2Found = true;
      }
    }

    Assert.assertTrue(file1Found);
    Assert.assertFalse(file2Found);
  }
Example #3
0
 @Override
 public boolean makeChange(BasePanel panel, BibtexDatabase secondary, NamedCompound undoEdit) {
   panel.database().removeEntry(memEntry.getId());
   undoEdit.addEdit(new UndoableRemoveEntry(panel.database(), memEntry, panel));
   secondary.removeEntry(tmpEntry.getId());
   return true;
 }
Example #4
0
 /**
  * Goes through all entries in the given database, and if at least one of them is a duplicate of
  * the given entry, as per Util.isDuplicate(BibtexEntry, BibtexEntry), the duplicate is returned.
  * The search is terminated when the first duplicate is found.
  *
  * @param database The database to search.
  * @param entry The entry of which we are looking for duplicates.
  * @return The first duplicate entry found. null if no duplicates are found.
  */
 public static BibtexEntry containsDuplicate(BibtexDatabase database, BibtexEntry entry) {
   for (BibtexEntry other : database.getEntries()) {
     if (DuplicateCheck.isDuplicate(entry, other)) {
       return other; // Duplicate found.
     }
   }
   return null; // No duplicate found.
 }