JabRef support

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@84 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2011-01-25 15:56:13 +00:00
parent 8b7154ca6b
commit 905918aaf2
26 changed files with 315 additions and 188 deletions

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2010 by Henrik Just
* Copyright: 2002-2011 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2010-10-10)
* Version 1.2 (2011-01-24)
*
*/
@ -85,18 +85,18 @@ public final class BibliographyDialog
if (sMethod.equals("external_event") ){
return handleExternalEvent(dlg, event);
}
else if (sMethod.equals("BibTeXDirClick")) {
return bibTeXDirClick(dlg);
}
else if (sMethod.equals("ConvertZoteroCitationsChange")) {
return convertZoteroCitationsChange(dlg);
}
else if (sMethod.equals("ZoteroBibTeXDirClick")) {
return zoteroBibTeXDirClick(dlg);
else if (sMethod.equals("ConvertJabRefCitationsChange")) {
return convertJabRefCitationsChange(dlg);
}
else if (sMethod.equals("UseExternalBibTeXFilesChange")) {
return useExternalBibTeXFilesChange(dlg);
}
else if (sMethod.equals("ExternalBibTeXDirClick")) {
return externalBibTeXDirClick(dlg);
}
}
catch (com.sun.star.uno.RuntimeException e) {
throw e;
@ -108,7 +108,8 @@ public final class BibliographyDialog
}
public String[] getSupportedMethodNames() {
String[] sNames = { "external_event", "ConvertZoteroCitationsChange", "ZoteroBibTeXDirClick", "UseExternalBibTeXFilesChange", "ExternalBibTeXDirClick" };
String[] sNames = { "external_event", "UseExternalBibTeXFilesChange", "ConvertZoteroCitationsChange",
"ConvertJabRefCitationsChange", "ExternalBibTeXDirClick" };
return sNames;
}
@ -153,16 +154,16 @@ public final class BibliographyDialog
try {
Object view = registry.getRegistryView(REGISTRY_PATH, false);
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
dlg.setCheckBoxStateAsBoolean("ConvertZoteroCitations",
XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations"));
dlg.setTextFieldText("ZoteroBibTeXDir",
XPropertySetHelper.getPropertyValueAsString(xProps, "ZoteroBibTeXDir"));
dlg.setTextFieldText("NatbibOptions",
XPropertySetHelper.getPropertyValueAsString(xProps, "NatbibOptions"));
dlg.setCheckBoxStateAsBoolean("UseExternalBibTeXFiles",
XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseExternalBibTeXFiles"));
dlg.setTextFieldText("ExternalBibTeXDir",
XPropertySetHelper.getPropertyValueAsString(xProps, "ExternalBibTeXDir"));
dlg.setCheckBoxStateAsBoolean("ConvertZoteroCitations",
XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations"));
dlg.setCheckBoxStateAsBoolean("ConvertJabRefCitations",
XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertJabRefCitations"));
dlg.setTextFieldText("NatbibOptions",
XPropertySetHelper.getPropertyValueAsString(xProps, "NatbibOptions"));
dlg.setTextFieldText("BibTeXDir",
XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir"));
registry.disposeRegistryView(view);
}
catch (Exception e) {
@ -180,11 +181,11 @@ public final class BibliographyDialog
try {
Object view = registry.getRegistryView(REGISTRY_PATH, true);
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
XPropertySetHelper.setPropertyValue(xProps, "ConvertZoteroCitations", dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations"));
XPropertySetHelper.setPropertyValue(xProps, "ZoteroBibTeXDir", dlg.getTextFieldText("ZoteroBibTeXDir"));
XPropertySetHelper.setPropertyValue(xProps, "NatbibOptions", dlg.getTextFieldText("NatbibOptions"));
XPropertySetHelper.setPropertyValue(xProps, "UseExternalBibTeXFiles", dlg.getCheckBoxStateAsBoolean("UseExternalBibTeXFiles"));
XPropertySetHelper.setPropertyValue(xProps, "ExternalBibTeXDir", dlg.getTextFieldText("ExternalBibTeXDir"));
XPropertySetHelper.setPropertyValue(xProps, "ConvertZoteroCitations", dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations"));
XPropertySetHelper.setPropertyValue(xProps, "ConvertJabRefCitations", dlg.getCheckBoxStateAsBoolean("ConvertJabRefCitations"));
XPropertySetHelper.setPropertyValue(xProps, "NatbibOptions", dlg.getTextFieldText("NatbibOptions"));
XPropertySetHelper.setPropertyValue(xProps, "BibTeXDir", dlg.getTextFieldText("BibTeXDir"));
// Commit registry changes
XChangesBatch xUpdateContext = (XChangesBatch)
@ -203,45 +204,44 @@ public final class BibliographyDialog
}
}
private boolean convertZoteroCitationsChange(DialogAccess dlg) {
// Update dialog according to the current setting of the checkbox
boolean bConvert = dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations");
dlg.setControlEnabled("ZoteroBibTeXDirLabel", bConvert);
dlg.setControlEnabled("ZoteroBibTeXDir", bConvert);
dlg.setControlEnabled("ZoteroBibTeXDirButton", bConvert);
dlg.setControlEnabled("NatbibOptionsLabel", bConvert);
dlg.setControlEnabled("NatbibOptions", bConvert);
return true;
}
private boolean zoteroBibTeXDirClick(DialogAccess dlg) {
String sPath = folderPicker.getPath();
if (sPath!=null) {
try {
dlg.setTextFieldText("ZoteroBibTeXDir", new File(new URI(sPath)).getCanonicalPath());
}
catch (IOException e) {
}
catch (URISyntaxException e) {
}
}
return true;
}
private boolean useExternalBibTeXFilesChange(DialogAccess dlg) {
// Update dialog according to the current setting of the checkbox
boolean bExternal = dlg.getCheckBoxStateAsBoolean("UseExternalBibTeXFiles");
dlg.setControlEnabled("ExternalBibTeXDirLabel", bExternal);
dlg.setControlEnabled("ExternalBibTeXDir", bExternal);
dlg.setControlEnabled("ExternalBibTeXDirButton", bExternal);
enableBibTeXDir(dlg);
return true;
}
private boolean externalBibTeXDirClick(DialogAccess dlg) {
private boolean convertZoteroCitationsChange(DialogAccess dlg) {
enableNatbibOptions(dlg);
enableBibTeXDir(dlg);
return true;
}
private boolean convertJabRefCitationsChange(DialogAccess dlg) {
enableNatbibOptions(dlg);
enableBibTeXDir(dlg);
return true;
}
private void enableNatbibOptions(DialogAccess dlg) {
boolean bConvertZotero = dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations");
boolean bConvertJabRef = dlg.getCheckBoxStateAsBoolean("ConvertJabRefCitations");
dlg.setControlEnabled("NatbibOptionsLabel", bConvertZotero || bConvertJabRef);
dlg.setControlEnabled("NatbibOptions", bConvertZotero || bConvertJabRef);
}
private void enableBibTeXDir(DialogAccess dlg) {
boolean bExternal = dlg.getCheckBoxStateAsBoolean("UseExternalBibTeXFiles");
boolean bConvertZotero = dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations");
boolean bConvertJabRef = dlg.getCheckBoxStateAsBoolean("ConvertJabRefCitations");
dlg.setControlEnabled("BibTeXDirLabel", bExternal || bConvertZotero || bConvertJabRef);
dlg.setControlEnabled("BibTeXDir", bExternal || bConvertZotero || bConvertJabRef);
dlg.setControlEnabled("BibTeXDirButton", bExternal|| bConvertZotero || bConvertJabRef);
}
private boolean bibTeXDirClick(DialogAccess dlg) {
String sPath = folderPicker.getPath();
if (sPath!=null) {
try {
dlg.setTextFieldText("ExternalBibTeXDir", new File(new URI(sPath)).getCanonicalPath());
dlg.setTextFieldText("BibTeXDir", new File(new URI(sPath)).getCanonicalPath());
}
catch (IOException e) {
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2010 by Henrik Just
* Copyright: 2002-2011 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2010-10-11)
* Version 1.2 (2011-01-25)
*
*/
@ -31,6 +31,7 @@ import java.io.IOException;
import java.lang.Process;
import java.lang.ProcessBuilder;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
@ -99,11 +100,12 @@ public class ExternalApps {
* @param sAppName the name of the application to execute
* @param sFileName the file name to use
* @param workDir the working directory to use
* @param env map of environment variables to set (or null if no variables needs to be set)
* @param bWaitFor true if the method should wait for the execution to finish
* @return error code
*/
public int execute(String sAppName, String sFileName, File workDir, boolean bWaitFor) {
return execute(sAppName, "", sFileName, workDir, bWaitFor);
public int execute(String sAppName, String sFileName, File workDir, Map<String,String> env, boolean bWaitFor) {
return execute(sAppName, "", sFileName, workDir, env, bWaitFor);
}
/** Execute an external application
@ -111,10 +113,11 @@ public class ExternalApps {
* @param sCommand subcommand/option to pass to the command
* @param sFileName the file name to use
* @param workDir the working directory to use
* @param env map of environment variables to set (or null if no variables needs to be set)
* @param bWaitFor true if the method should wait for the execution to finish
* @return error code
*/
public int execute(String sAppName, String sCommand, String sFileName, File workDir, boolean bWaitFor) {
public int execute(String sAppName, String sCommand, String sFileName, File workDir, Map<String,String> env, boolean bWaitFor) {
// Assemble the command
String[] sApp = getApplication(sAppName);
if (sApp==null) { return 1; }
@ -129,6 +132,12 @@ public class ExternalApps {
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(workDir);
if (env!=null) {
pb.environment().putAll(env);
if (env.containsKey("BIBINPUTS")) {
System.out.println("Running "+sApp[0]+" with BIBINPUTS="+env.get("BIBINPUTS"));
}
}
Process proc = pb.start();
// Gobble the error stream of the application

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2009-06-19)
* Version 1.2 (2011-01-25)
*
*/
@ -291,7 +291,7 @@ public class TeXImportFilter extends WeakBase implements XInitialization, XNamed
System.out.println("Executing tex4ht with command "+sCommand+" on file "+file.getName());
externalApps.execute(ExternalApps.MK4HT, sCommand, file.getName(), file.getParentFile(), true);
externalApps.execute(ExternalApps.MK4HT, sCommand, file.getName(), file.getParentFile(), null, true);
if (xStatus!=null) { nStep+=5; xStatus.setValue(nStep); }

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2009-11-29)
* Version 1.2 (2011-01-25)
*
*/
@ -28,10 +28,12 @@ package org.openoffice.da.comp.writer4latex;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.sun.star.uno.XComponentContext;
/** This class builds LaTeX documents into dvi, postscript or pdf and displays
/** This class builds LaTeX documents into DVI, Postscript or PDF and displays
* the result.
*/
public final class TeXify {
@ -74,12 +76,13 @@ public final class TeXify {
/** Process a document
* @param file the LaTeX file to process
* @param sBibinputs value for the BIBINPUTS environment variable (or null if it should not be extended)
* @param nBackend the desired backend format (generic, dvips, pdftex)
* @param bView set the true if the result should be displayed in the viewer
* @throws IOException if the document cannot be read
* @return true if the first LaTeX run was succesful
* @return true if the first LaTeX run was successful
*/
public boolean process(File file, short nBackend, boolean bView) throws IOException {
public boolean process(File file, String sBibinputs, short nBackend, boolean bView) throws IOException {
// Remove extension from file
if (file.getName().endsWith(".tex")) {
file = new File(file.getParentFile(),
@ -92,38 +95,38 @@ public final class TeXify {
// Process LaTeX document
boolean bResult = false;
if (nBackend==GENERIC) {
bResult = doTeXify(genericTexify, file);
bResult = doTeXify(genericTexify, file, sBibinputs);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.DVIVIEWER,
new File(file.getParentFile(),file.getName()+".dvi").getPath(),
file.getParentFile(), false)>0) {
file.getParentFile(), null, false)>0) {
throw new IOException("Error executing dvi viewer");
}
}
else if (nBackend==PDFTEX) {
bResult = doTeXify(pdfTexify, file);
bResult = doTeXify(pdfTexify, file, sBibinputs);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.PDFVIEWER,
new File(file.getParentFile(),file.getName()+".pdf").getPath(),
file.getParentFile(), false)>0) {
file.getParentFile(), null, false)>0) {
throw new IOException("Error executing pdf viewer");
}
}
else if (nBackend==DVIPS) {
bResult = doTeXify(dvipsTexify, file);
bResult = doTeXify(dvipsTexify, file, sBibinputs);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.POSTSCRIPTVIEWER,
new File(file.getParentFile(),file.getName()+".ps").getPath(),
file.getParentFile(), false)>0) {
file.getParentFile(), null, false)>0) {
throw new IOException("Error executing postscript viewer");
}
}
else if (nBackend==XETEX) {
bResult = doTeXify(xeTexify, file);
bResult = doTeXify(xeTexify, file, sBibinputs);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.PDFVIEWER,
new File(file.getParentFile(),file.getName()+".pdf").getPath(),
file.getParentFile(), false)>0) {
file.getParentFile(), null, false)>0) {
throw new IOException("Error executing pdf viewer");
}
}
@ -131,11 +134,16 @@ public final class TeXify {
}
private boolean doTeXify(String[] sAppList, File file) throws IOException {
private boolean doTeXify(String[] sAppList, File file, String sBibinputs) throws IOException {
for (int i=0; i<sAppList.length; i++) {
// Execute external application
Map<String,String> env =null;
if (ExternalApps.BIBTEX.equals(sAppList[i])) {
env = new HashMap<String,String>();
env.put("BIBINPUTS", sBibinputs);
}
int nReturnCode = externalApps.execute(
sAppList[i], file.getName(), file.getParentFile(), true);
sAppList[i], file.getName(), file.getParentFile(), env, true);
System.out.println("Return code from "+sAppList[i]+": "+nReturnCode);
if (i==0 && nReturnCode>0) {
return false;

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2010 by Henrik Just
* Copyright: 2002-2011 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2010-10-13)
* Version 1.2 (2011-01-25)
*
*/
@ -44,6 +44,7 @@ import com.sun.star.task.XStatusIndicator;
import com.sun.star.task.XStatusIndicatorFactory;
import com.sun.star.ui.dialogs.ExecutableDialogResults;
import com.sun.star.ui.dialogs.XExecutableDialog;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
@ -54,6 +55,7 @@ import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
import writer2latex.util.CSVList;
import writer2latex.util.Misc;
/** This class implements the ui (dispatch) commands provided by Writer4LaTeX.
* The actual processing is done by the three core classes <code>TeXify</code>,
@ -202,6 +204,8 @@ public final class Writer4LaTeX extends WeakBase
// First work a bit on the FilterData (get the backend and set bibliography options)
String sBackend = "generic";
String sBibinputs = null;
PropertyHelper mediaHelper = new PropertyHelper(mediaProps);
Object filterData = mediaHelper.get("FilterData");
if (filterData instanceof PropertyValue[]) {
@ -217,14 +221,24 @@ public final class Writer4LaTeX extends WeakBase
try {
Object view = registry.getRegistryView(BibliographyDialog.REGISTRY_PATH, false);
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
String sBibTeXFiles = getFileList(XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir"));
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations")) {
filterHelper.put("zotero_bibtex_files", getFileList(XPropertySetHelper.getPropertyValueAsString(xProps, "ZoteroBibTeXDir")));
filterHelper.put("zotero_bibtex_files", sBibTeXFiles);
filterHelper.put("natbib_options", XPropertySetHelper.getPropertyValueAsString(xProps, "NatbibOptions"));
}
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertJabRefCitations")) {
filterHelper.put("jabref_bibtex_files", sBibTeXFiles);
filterHelper.put("natbib_options", XPropertySetHelper.getPropertyValueAsString(xProps, "NatbibOptions"));
}
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseExternalBibTeXFiles")) {
filterHelper.put("external_bibtex_files", getFileList(XPropertySetHelper.getPropertyValueAsString(xProps, "ExternalBibTeXDir")));
filterHelper.put("external_bibtex_files", sBibTeXFiles);
}
mediaHelper.put("FilterData",filterHelper.toArray());
String sBibTeXDir = XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir");
if (sBibTeXDir.length()>0) {
sBibinputs = sBibTeXDir+":";
}
mediaHelper.put("FilterData",filterHelper.toArray());
mediaProps = mediaHelper.toArray();
registry.disposeRegistryView(view);
}
@ -255,16 +269,16 @@ public final class Writer4LaTeX extends WeakBase
try {
if (sBackend=="pdftex") {
bResult = texify.process(file, TeXify.PDFTEX, true);
bResult = texify.process(file, sBibinputs, TeXify.PDFTEX, true);
}
else if (sBackend=="dvips") {
bResult = texify.process(file, TeXify.DVIPS, true);
bResult = texify.process(file, sBibinputs, TeXify.DVIPS, true);
}
else if (sBackend=="xetex") {
bResult = texify.process(file, TeXify.XETEX, true);
bResult = texify.process(file, sBibinputs, TeXify.XETEX, true);
}
else if (sBackend=="generic") {
bResult = texify.process(file, TeXify.GENERIC, true);
bResult = texify.process(file, sBibinputs, TeXify.GENERIC, true);
}
}
catch (IOException e) {
@ -289,11 +303,13 @@ public final class Writer4LaTeX extends WeakBase
File[] files = dir.listFiles();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".bib")) {
filelist.addValue(file.getAbsolutePath());
//filelist.addValue(file.getAbsolutePath());
filelist.addValue(Misc.removeExtension(file.getName()));
}
}
}
return filelist.toString();
String sFileList = filelist.toString();
return sFileList.length()>0 ? sFileList : "dummy";
}
private void viewLog() {