コード例 #1
0
ファイル: DBExporter.java プロジェクト: GHenry10/jabref
  /**
   * 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);
    }
  }
コード例 #2
0
  @Test
  public void roundtripWithUserCommentBeforeStringAndChange() throws Exception {
    Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
    Charset encoding = StandardCharsets.UTF_8;
    ParserResult result =
        new BibtexParser(importFormatPreferences)
            .parse(Importer.getReader(testBibtexFile, encoding));

    for (BibtexString string : result.getDatabase().getStringValues()) {
      // Mark them as changed
      string.setContent(string.getContent());
    }

    SavePreferences preferences =
        new SavePreferences().withEncoding(encoding).withSaveInOriginalOrder(true);
    BibDatabaseContext context =
        new BibDatabaseContext(
            result.getDatabase(), result.getMetaData(), new Defaults(BibDatabaseMode.BIBTEX));

    StringSaveSession session =
        databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries(), preferences);

    try (Scanner scanner = new Scanner(testBibtexFile, encoding.name())) {
      assertEquals(scanner.useDelimiter("\\A").next(), session.getStringValue());
    }
  }
コード例 #3
0
ファイル: BibtexParser.java プロジェクト: boceckts/jabref
 private void parseBibtexString() throws IOException {
   BibtexString bibtexString = parseString();
   bibtexString.setParsedSerialization(dumpTextReadSoFarToString());
   try {
     database.addString(bibtexString);
   } catch (KeyCollisionException ex) {
     parserResult.addWarning(
         Localization.lang("Duplicate string name") + ": " + bibtexString.getName());
   }
 }
コード例 #4
0
  @Test
  public void reformatStringIfAskedToDoSo() throws Exception {
    BibtexString string = new BibtexString("id", "name", "content");
    string.setParsedSerialization("wrong serialization");
    database.addString(string);

    SavePreferences preferences = new SavePreferences().withReformatFile(true);
    StringSaveSession session =
        databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences);

    assertEquals(OS.NEWLINE + "@String{name = {content}}" + OS.NEWLINE, session.getStringValue());
  }
コード例 #5
0
  @Test
  public void writeSavedSerializationOfStringIfUnchanged() throws Exception {
    BibtexString string = new BibtexString("id", "name", "content");
    string.setParsedSerialization("serialization");
    database.addString(string);

    StringSaveSession session =
        databaseWriter.savePartOfDatabase(
            bibtexContext, Collections.emptyList(), new SavePreferences());

    assertEquals("serialization", session.getStringValue());
  }