Example #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);
      }
    }
  }
 /**
  * Return a button opening a content selector for fields where one exists
  *
  * @param frame
  * @param panel
  * @param editor
  * @param contentSelectors
  * @param storeFieldAction
  * @return
  */
 public static Optional<JComponent> getSelectorExtraComponent(
     JabRefFrame frame,
     BasePanel panel,
     FieldEditor editor,
     Set<FieldContentSelector> contentSelectors,
     StoreFieldAction storeFieldAction) {
   FieldContentSelector ws =
       new FieldContentSelector(
           frame,
           panel,
           frame,
           editor,
           storeFieldAction,
           false,
           InternalBibtexFields.getFieldProperties(editor.getFieldName())
                   .contains(FieldProperty.PERSON_NAMES)
               ? " and "
               : ", ");
   contentSelectors.add(ws);
   return Optional.of(ws);
 }
Example #3
0
  @Override
  public List<IntegrityMessage> check(BibEntry entry) {
    List<IntegrityMessage> result = new ArrayList<>();
    for (String field : entry.getFieldNames()) {
      if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES)) {
        Optional<String> value = entry.getField(field);
        if (!value.isPresent()) {
          return Collections.emptyList();
        }

        String valueTrimmedAndLowerCase = value.get().trim().toLowerCase();
        if (valueTrimmedAndLowerCase.startsWith("and ")
            || valueTrimmedAndLowerCase.startsWith(",")) {
          result.add(
              new IntegrityMessage(Localization.lang("should start with a name"), entry, field));
        } else if (valueTrimmedAndLowerCase.endsWith(" and")
            || valueTrimmedAndLowerCase.endsWith(",")) {
          result.add(
              new IntegrityMessage(Localization.lang("should end with a name"), entry, field));
        }
      }
    }
    return result;
  }
Example #4
0
  private static void start(String[] args) {
    JabRefPreferences preferences = JabRefPreferences.getInstance();

    ProxyPreferences proxyPreferences = ProxyPreferences.loadFromPreferences(preferences);
    ProxyRegisterer.register(proxyPreferences);
    if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) {
      Authenticator.setDefault(new ProxyAuthenticator());
    }

    Globals.startBackgroundTasks();
    Globals.prefs = preferences;
    Localization.setLanguage(preferences.get(JabRefPreferences.LANGUAGE));
    Globals.prefs.setLanguageDependentDefaultValues();

    // Update which fields should be treated as numeric, based on preferences:
    InternalBibtexFields.setNumericFields(
        Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));

    /* Build list of Import and Export formats */
    Globals.IMPORT_FORMAT_READER.resetImportFormats();
    CustomEntryTypesManager.loadCustomEntryTypes(preferences);
    ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs));

    // Read list(s) of journal names and abbreviations
    Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();

    // Check for running JabRef
    RemotePreferences remotePreferences = new RemotePreferences(Globals.prefs);
    if (remotePreferences.useRemoteServer()) {
      Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort());

      if (!Globals.REMOTE_LISTENER.isOpen()) {
        // we are not alone, there is already a server out there, try to contact already running
        // JabRef:
        if (RemoteListenerClient.sendToActiveJabRefInstance(args, remotePreferences.getPort())) {
          // We have successfully sent our command line options through the socket to another JabRef
          // instance.
          // So we assume it's all taken care of, and quit.
          LOGGER.info(
              Localization.lang("Arguments passed on to running JabRef instance. Shutting down."));
          JabRefExecutorService.INSTANCE.shutdownEverything();
          return;
        }
      }
      // we are alone, we start the server
      Globals.REMOTE_LISTENER.start();
    }

    // override used newline character with the one stored in the preferences
    // The preferences return the system newline character sequence as default
    OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE);

    // Process arguments
    ArgumentProcessor argumentProcessor =
        new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START);

    // See if we should shut down now
    if (argumentProcessor.shouldShutDown()) {
      JabRefExecutorService.INSTANCE.shutdownEverything();
      return;
    }

    // If not, start GUI
    SwingUtilities.invokeLater(
        () -> new JabRefGUI(argumentProcessor.getParserResults(), argumentProcessor.isBlank()));
  }