예제 #1
0
  private void parseField(BibEntry entry) throws IOException {
    String key = parseTextToken().toLowerCase();

    skipWhitespace();
    consume('=');
    String content = parseFieldContent(key);
    if (!content.isEmpty()) {
      if (entry.hasField(key)) {
        // The following hack enables the parser to deal with multiple
        // author or
        // editor lines, stringing them together instead of getting just
        // one of them.
        // Multiple author or editor lines are not allowed by the bibtex
        // format, but
        // at least one online database exports bibtex like that, making
        // it inconvenient
        // for users if JabRef didn't accept it.
        if (InternalBibtexFields.getFieldExtras(key).contains(FieldProperties.PERSON_NAMES)) {
          entry.setField(key, entry.getFieldOptional(key).get() + " and " + content);
        } else if (FieldName.KEYWORDS.equals(key)) {
          // multiple keywords fields should be combined to one
          entry.addKeyword(content, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));
        }
      } else {
        entry.setField(key, content);
      }
    }
  }
예제 #2
0
  /**
   * Unabbreviate the journal name of the given entry.
   *
   * @param entry The entry to be treated.
   * @param fieldName The field name (e.g. "journal")
   * @param ce If the entry is changed, add an edit to this compound.
   * @return true if the entry was changed, false otherwise.
   */
  public boolean unabbreviate(
      BibDatabase database, BibEntry entry, String fieldName, CompoundEdit ce) {
    if (!entry.hasField(fieldName)) {
      return false;
    }
    String text = entry.getFieldOptional(fieldName).get();
    String origText = text;
    if (database != null) {
      text = database.resolveForStrings(text);
    }

    if (!journalAbbreviationRepository.isKnownName(text)) {
      return false; // cannot do anything if it is not known
    }

    if (!journalAbbreviationRepository.isAbbreviatedName(text)) {
      return false; // cannot unabbreviate unabbreviated name.
    }

    Abbreviation abbreviation =
        journalAbbreviationRepository.getAbbreviation(text).get(); // must be here
    String newText = abbreviation.getName();
    entry.setField(fieldName, newText);
    ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText));
    return true;
  }
예제 #3
0
 private Icon getFileIconForSelectedEntry() {
   if (panel.getMainTable().getSelectedRowCount() == 1) {
     BibEntry entry = panel.getMainTable().getSelected().get(0);
     if (entry.hasField(FieldName.FILE)) {
       JLabel label =
           FileListTableModel.getFirstLabel(entry.getFieldOptional(FieldName.FILE).get());
       if (label != null) {
         return label.getIcon();
       }
     }
   }
   return IconTheme.JabRefIcon.FILE.getSmallIcon();
 }
예제 #4
0
  @Override
  public void actionPerformed(ActionEvent actionEvent) {
    setEnabled(false);
    panel.output(Localization.lang("Writing XMP-metadata..."));
    panel.frame().setProgressBarIndeterminate(true);
    panel.frame().setProgressBarVisible(true);
    BibEntry entry = editor.getEntry();

    // Make a list of all PDFs linked from this entry:
    List<File> files = new ArrayList<>();

    // First check the (legacy) "pdf" field:
    entry
        .getField(FieldName.PDF)
        .ifPresent(
            pdf ->
                FileUtil.expandFilename(
                        pdf,
                        panel
                            .getBibDatabaseContext()
                            .getFileDirectory(
                                FieldName.PDF, Globals.prefs.getFileDirectoryPreferences()))
                    .ifPresent(files::add));

    // Then check the "file" field:
    List<String> dirs =
        panel.getBibDatabaseContext().getFileDirectory(Globals.prefs.getFileDirectoryPreferences());
    if (entry.hasField(FieldName.FILE)) {
      FileListTableModel tm = new FileListTableModel();
      entry.getField(FieldName.FILE).ifPresent(tm::setContent);
      for (int j = 0; j < tm.getRowCount(); j++) {
        FileListEntry flEntry = tm.getEntry(j);
        if ((flEntry.type.isPresent()) && "pdf".equalsIgnoreCase(flEntry.type.get().getName())) {
          FileUtil.expandFilename(flEntry.link, dirs).ifPresent(files::add);
        }
      }
    }

    // We want to offload the actual work to a background thread, so we have a worker
    // thread:
    AbstractWorker worker = new WriteXMPWorker(files, entry);
    // Using Spin, we get a thread that gets synchronously offloaded to a new thread,
    // blocking the execution of this method:
    worker.getWorker().run();
    // After the worker thread finishes, we are unblocked and ready to print the
    // status message:
    panel.output(message);
    panel.frame().setProgressBarVisible(false);
    setEnabled(true);
  }
예제 #5
0
  @Override
  public List<IntegrityMessage> check(BibEntry entry) {
    if (!entry.hasField(FieldName.ISSN)) {
      return Collections.emptyList();
    }

    // Check that the ISSN is on the correct form
    String issnString = entry.getFieldOptional(FieldName.ISSN).get().trim();

    ISSN issn = new ISSN(issnString);
    if (!issn.isValidFormat()) {
      return Collections.singletonList(
          new IntegrityMessage(Localization.lang("incorrect format"), entry, FieldName.ISSN));
    }

    if (issn.isValidChecksum()) {
      return Collections.emptyList();
    } else {
      return Collections.singletonList(
          new IntegrityMessage(
              Localization.lang("incorrect control digit"), entry, FieldName.ISSN));
    }
  }