Exemple #1
0
 /**
  * Converts a relative filename to an absolute one, if necessary. Returns null if the file does
  * not exist.<br>
  *
  * <p>Uses
  *
  * <ul>
  *   <li>the default directory associated with the extension of the file
  *   <li>the standard file directory
  *   <li>the directory of the bib file
  * </ul>
  *
  * @param metaData The MetaData for the database this file belongs to.
  * @param name The filename, may also be a relative path to the file
  */
 public static File expandFilename(final MetaData metaData, String name) {
   int pos = name.lastIndexOf('.');
   String extension =
       (pos >= 0) && (pos < (name.length() - 1))
           ? name.substring(pos + 1).trim().toLowerCase()
           : null;
   // Find the default directory for this field type, if any:
   String[] dir = metaData.getFileDirectory(extension);
   // Include the standard "file" directory:
   String[] fileDir = metaData.getFileDirectory(Globals.FILE_FIELD);
   // Include the directory of the bib file:
   ArrayList<String> al = new ArrayList<>();
   for (String aDir : dir) {
     if (!al.contains(aDir)) {
       al.add(aDir);
     }
   }
   for (String aFileDir : fileDir) {
     if (!al.contains(aFileDir)) {
       al.add(aFileDir);
     }
   }
   String[] dirs = al.toArray(new String[al.size()]);
   return expandFilename(name, dirs);
 }
  private void applyChanges() {
    boolean changedFieldSet = false; // Watch if we need to rebuild entry editors

    // First remove the mappings for fields that have been deleted.
    // If these were re-added, they will be added below, so it doesn't
    // cause any harm to remove them here.
    for (String fieldName : removedFields) {
      metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName);
      changedFieldSet = true;
    }

    // Cycle through all fields that we have created listmodels for:
    for (String fieldName : wordListModels.keySet()) {
      // For each field name, store the values:
      if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) {
        continue;
      }
      DefaultListModel<String> lm = wordListModels.get(fieldName);
      int start = 0;
      // Avoid storing the <new word> marker if it is there:
      if (!lm.isEmpty()) {
        while ((start < lm.size()) && lm.get(start).equals(WORD_FIRSTLINE_TEXT)) {
          start++;
        }
      }
      Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName);
      boolean bNewField = false;
      if (data == null) {
        bNewField = true;
        data = new Vector<>();
        changedFieldSet = true;

      } else {
        data.clear();
      }
      for (int wrd = start; wrd < lm.size(); wrd++) {
        String word = lm.get(wrd);
        data.add(word);
      }
      if (bNewField) {
        metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data);
      }
    }

    // System.out.println("TODO: remove metadata for removed selector field.");
    panel.markNonUndoableBaseChanged();

    // Update all selectors in the current BasePanel.
    if (changedFieldSet) {
      panel.rebuildAllEntryEditors();
    } else {
      panel.updateAllContentSelectors();
    }
    panel.getAutoCompleters().addContentSelectorValuesToAutoCompleters(panel.metaData);
  }
 /**
  * For all fields with both autocompletion and content selector, add content selector values to
  * the autocompleter list:
  */
 public void addContentSelectorValuesToAutoCompleters(MetaData metaData) {
   for (Map.Entry<String, AutoCompleter> entry : this.autoCompleters.entrySet()) {
     AutoCompleter ac = entry.getValue();
     if (metaData.getData(Globals.SELECTOR_META_PREFIX + entry.getKey()) != null) {
       Vector<String> items = metaData.getData(Globals.SELECTOR_META_PREFIX + entry.getKey());
       if (items != null) {
         for (String item : items) {
           ac.addWordToIndex(item);
         }
       }
     }
   }
 }
Exemple #4
0
  private ParserResult parseFileContent() throws IOException {
    Map<String, String> meta = new HashMap<>();

    while (!eof) {
      boolean found = consumeUncritically('@');
      if (!found) {
        break;
      }

      skipWhitespace();

      // Try to read the entry type
      String entryType = parseTextToken().toLowerCase().trim();

      if ("preamble".equals(entryType)) {
        database.setPreamble(parsePreamble());
        // Consume new line which signals end of preamble
        skipOneNewline();
        // the preamble is saved verbatim anyways, so the text read so far can be dropped
        dumpTextReadSoFarToString();
      } else if ("string".equals(entryType)) {
        parseBibtexString();
      } else if ("comment".equals(entryType)) {
        parseJabRefComment(meta);
      } else {
        // Not a comment, preamble, or string. Thus, it is an entry
        parseAndAddEntry(entryType);
      }

      skipWhitespace();
    }

    // Instantiate meta data:
    try {
      parserResult.setMetaData(MetaData.parse(meta));
    } catch (ParseException exception) {
      parserResult.addWarning(exception.getLocalizedMessage());
    }

    parseRemainingContent();

    return parserResult;
  }
Exemple #5
0
  /**
   * Method for the exportDatabase methods.
   *
   * @param database The DBTYPE of the database
   * @param database The BibtexDatabase to export
   * @param metaData The MetaData object containing the groups information
   * @param keySet The set of IDs of the entries to export.
   * @param out The output (PrintStream or Connection) object to which the DML should be written.
   */
  private void performExport(
      final BibtexDatabase database,
      final MetaData metaData,
      Set<String> keySet,
      Object out,
      String dbName)
      throws Exception {

    List<BibtexEntry> entries = FileActions.getSortedEntries(database, metaData, keySet, false);
    GroupTreeNode gtn = metaData.getGroups();

    int database_id = getDatabaseIDByName(metaData, out, dbName);
    removeAllRecordsForAGivenDB(out, database_id);
    populateEntryTypesTable(out);
    populateEntriesTable(database_id, entries, out);
    populateStringTable(database, out, database_id);
    populateGroupTypesTable(out);
    populateGroupsTable(gtn, 0, 1, out, database_id);
    populateEntryGroupsTable(gtn, 0, 1, out, database_id);
  }
  private void setupWordSelector() {

    // Have we already created a listmodel for this field?
    wordListModel = wordListModels.get(currentField);
    if (wordListModel != null) {
      wordList.setModel(wordListModel);
    } else {
      wordListModel = new DefaultListModel<>();
      wordList.setModel(wordListModel);
      wordListModels.put(currentField, wordListModel);
      // wordListModel.addElement(WORD_FIRSTLINE_TEXT);
      Vector<String> items = metaData.getData(Globals.SELECTOR_META_PREFIX + currentField);
      if (items != null) {
        TreeSet<String> wordSet = new TreeSet<>(items);
        int index = 0;
        for (String s : wordSet) {
          wordListModel.add(index, s);
          index++;
        }
      }
    }
  }
 @Override
 public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
   for (MetaDataChangeUnit unit : changes) {
     switch (unit.type) {
       case ADD:
         md.putData(unit.key, unit.value);
         mdSecondary.putData(unit.key, unit.value);
         break;
       case REMOVE:
         md.remove(unit.key);
         mdSecondary.remove(unit.key);
         break;
       case MODIFY:
         md.putData(unit.key, unit.value);
         mdSecondary.putData(unit.key, unit.value);
         break;
     }
   }
   return true;
 }
 /**
  * Used for updating an existing Dialog
  *
  * @param panel the panel to read the data from
  */
 public void setPanel(BasePanel panel) {
   this.panel = panel;
   this.metaData = panel.metaData();
   AbstractLabelPattern keypatterns = metaData.getLabelPattern();
   labelPatternPanel.setValues(keypatterns);
 }