@Override public void pushEntries( BibtexDatabase database, final BibtexEntry[] entries, final String keyString, MetaData metaData) { couldNotFindPipe = false; couldNotWrite = false; String lyxpipeSetting = Globals.prefs.get(JabRefPreferences.LYXPIPE); if (!lyxpipeSetting.endsWith(".in")) { lyxpipeSetting = lyxpipeSetting + ".in"; } File lp = new File(lyxpipeSetting); // this needs to fixed because it gives "asdf" when going // prefs.get("lyxpipe") if (!lp.exists() || !lp.canWrite()) { // See if it helps to append ".in": lp = new File(lyxpipeSetting + ".in"); if (!lp.exists() || !lp.canWrite()) { couldNotFindPipe = true; return; } } final File lyxpipe = lp; JabRefExecutorService.INSTANCE.executeAndWait( new Runnable() { @Override public void run() { try { FileWriter fw = new FileWriter(lyxpipe); BufferedWriter lyx_out = new BufferedWriter(fw); String citeStr; citeStr = "LYXCMD:sampleclient:citation-insert:" + keyString; lyx_out.write(citeStr + "\n"); lyx_out.close(); } catch (IOException excep) { couldNotWrite = true; } } }); }
@Override public void actionPerformed(ActionEvent e) { panel = frame.getCurrentBasePanel(); // Check if a BasePanel exists: if (panel == null) { return; } // Check if any entries are selected: entries = panel.getSelectedEntries(); if (entries.length == 0) { JOptionPane.showMessageDialog( frame, Localization.lang("This operation requires one or more entries to be selected."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); return; } // If required, check that all entries have BibTeX keys defined: if (operation.requiresBibtexKeys()) { for (BibEntry entry : entries) { if ((entry.getCiteKey() == null) || entry.getCiteKey().trim().isEmpty()) { JOptionPane.showMessageDialog( frame, Localization.lang( "This operation requires all selected entries to have BibTex keys defined."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); return; } } } // All set, call the operation in a new thread: JabRefExecutorService.INSTANCE.execute(this); }
@Override public void pushEntries( BibDatabase database, List<BibEntry> entries, String keys, MetaData metaData) { couldNotConnect = false; couldNotCall = false; notDefined = false; initParameters(); commandPath = Globals.prefs.get(commandPathPreferenceKey); if ((commandPath == null) || commandPath.trim().isEmpty()) { notDefined = true; return; } commandPath = Globals.prefs.get(commandPathPreferenceKey); String[] addParams = Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS).split(" "); try { String[] com = new String[addParams.length + 2]; com[0] = commandPath; System.arraycopy(addParams, 0, com, 1, addParams.length); String prefix; String suffix; if (Globals.prefs.getBoolean(JabRefPreferences.EMACS_23)) { prefix = "(with-current-buffer (window-buffer) (insert "; suffix = "))"; } else { prefix = "(insert "; suffix = ")"; } com[com.length - 1] = OS.WINDOWS ? // Windows gnuclient escaping: // java string: "(insert \\\"\\\\cite{Blah2001}\\\")"; // so cmd receives: (insert \"\\cite{Blah2001}\") // so emacs receives: (insert "\cite{Blah2001}") prefix .concat( "\\\"\\" + getCiteCommand().replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\\\"") .concat(suffix) : // Linux gnuclient escaping: // java string: "(insert \"\\\\cite{Blah2001}\")" // so sh receives: (insert "\\cite{Blah2001}") // so emacs receives: (insert "\cite{Blah2001}") prefix .concat( "\"" + getCiteCommand().replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\"") .concat(suffix); final Process p = Runtime.getRuntime().exec(com); Runnable errorListener = new Runnable() { @Override public void run() { try (InputStream out = p.getErrorStream()) { // try { // if (out.available() <= 0) // out = p.getInputStream(); // } catch (Exception e) { // } int c; StringBuilder sb = new StringBuilder(); try { while ((c = out.read()) != -1) { sb.append((char) c); } } catch (IOException e) { LOGGER.warn("Could not read from stderr.", e); } // Error stream has been closed. See if there were any errors: if (!sb.toString().trim().isEmpty()) { LOGGER.warn("Push to Emacs error: " + sb); couldNotConnect = true; } } catch (IOException e) { LOGGER.warn("File problem.", e); } } }; JabRefExecutorService.INSTANCE.executeAndWait(errorListener); } catch (IOException excep) { couldNotCall = true; } }
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())); }