@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 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; } }