Skip to content

Commit

Permalink
Solved #593 and cleaned up the OO-code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Dec 27, 2015
1 parent ad1507f commit 37421b2
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 145 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
### Changed

### Fixed
- Reference list generation works for OpenOffice/LibreOffice again, fixes #593

### Removed

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ public class JabRefPreferences {

public static final String PUSH_TO_APPLICATION = "pushToApplication";

// OpenOffice/LibreOffice preferences
public static final String OO_EXECUTABLE_PATH = "ooExecutablePath";
public static final String OO_UNOIL_PATH = "ooUnoilPath";
public static final String OO_JURT_PATH = "ooJurtPath";

//non-default preferences
private static final String CUSTOM_TYPE_NAME = "customTypeName_";
private static final String CUSTOM_TYPE_REQ = "customTypeReq_";
Expand Down
55 changes: 22 additions & 33 deletions src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.sf.jabref.openoffice;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.gui.worker.AbstractWorker;

import javax.swing.*;
Expand Down Expand Up @@ -66,10 +67,6 @@ public void run() {
foundPaths = autoDetectPaths();
}

public boolean getResult() {
return foundPaths;
}

public boolean cancelled() {
return fileSearchCancelled;
}
Expand All @@ -89,10 +86,10 @@ private boolean autoDetectPaths() {

if (OS.WINDOWS) {
List<File> progFiles = AutoDetectPaths.findProgramFilesDir();
File sOffice = null;
if (fileSearchCancelled) {
return false;
}
File sOffice = null;
List<File> sofficeFiles = new ArrayList<>();
for (File dir : progFiles) {
sOffice = findFileDir(dir, "soffice.exe");
Expand Down Expand Up @@ -156,7 +153,7 @@ public String getDescription() {
} else {
sOffice = sofficeFiles.get(0);
}
Globals.prefs.put("ooExecutablePath", new File(sOffice, "soffice.exe").getPath());
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(sOffice, "soffice.exe").getPath());
File unoil = findFileDir(sOffice.getParentFile(), "unoil.jar");
if (fileSearchCancelled) {
return false;
Expand All @@ -166,8 +163,8 @@ public String getDescription() {
return false;
}
if ((unoil != null) && (jurt != null)) {
Globals.prefs.put("ooUnoilPath", unoil.getPath());
Globals.prefs.put("ooJurtPath", jurt.getPath());
Globals.prefs.put(JabRefPreferences.OO_UNOIL_PATH, unoil.getPath());
Globals.prefs.put(JabRefPreferences.OO_JURT_PATH, jurt.getPath());
return true;
} else {
return false;
Expand All @@ -181,34 +178,27 @@ else if (OS.OS_X) {
for (File file : files) {
if (file.isDirectory() && "OpenOffice.org.app".equals(file.getName())) {
rootDir = file;
//System.out.println("Setting starting dir to: "+file.getPath());
break;
}
}
}
//System.out.println("Searching for soffice.bin");
File sOffice = findFileDir(rootDir, "soffice.bin");
//System.out.println("Found: "+(sOffice != null ? sOffice.getPath() : "-"));
if (fileSearchCancelled) {
return false;
}
if (sOffice != null) {
Globals.prefs.put("ooExecutablePath", new File(sOffice, "soffice.bin").getPath());
//System.out.println("Searching for unoil.jar");
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(sOffice, "soffice.bin").getPath());
File unoil = findFileDir(rootDir, "unoil.jar");
//System.out.println("Found: "+(unoil != null ? unoil.getPath(): "-"));
if (fileSearchCancelled) {
return false;
}
//System.out.println("Searching for jurt.jar");
File jurt = findFileDir(rootDir, "jurt.jar");
//System.out.println("Found: "+(jurt != null ? jurt.getPath(): "-"));
if (fileSearchCancelled) {
return false;
}
if ((unoil != null) && (jurt != null)) {
Globals.prefs.put("ooUnoilPath", unoil.getPath());
Globals.prefs.put("ooJurtPath", jurt.getPath());
Globals.prefs.put(JabRefPreferences.OO_UNOIL_PATH, unoil.getPath());
Globals.prefs.put(JabRefPreferences.OO_JURT_PATH, jurt.getPath());
return true;
} else {
return false;
Expand All @@ -220,7 +210,7 @@ else if (OS.OS_X) {
else {
// Linux:
String usrRoot = "/usr/lib";
File inUsr = findFileDir(new File("/usr/lib"), "soffice");
File inUsr = findFileDir(new File(usrRoot), "soffice");
if (fileSearchCancelled) {
return false;
}
Expand All @@ -242,12 +232,12 @@ else if (OS.OS_X) {
return setupPreferencesForOO(usrRoot, inUsr);
}
else if ((inOpt != null) && (inUsr == null)) {
Globals.prefs.put("ooExecutablePath", new File(inOpt, "soffice.bin").getPath());
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inOpt, "soffice.bin").getPath());
File unoil = findFileDir(new File("/opt"), "unoil.jar");
File jurt = findFileDir(new File("/opt"), "jurt.jar");
if ((unoil != null) && (jurt != null)) {
Globals.prefs.put("ooUnoilPath", unoil.getPath());
Globals.prefs.put("ooJurtPath", jurt.getPath());
Globals.prefs.put(JabRefPreferences.OO_UNOIL_PATH, unoil.getPath());
Globals.prefs.put(JabRefPreferences.OO_JURT_PATH, jurt.getPath());
return true;
} else {
return false;
Expand Down Expand Up @@ -288,7 +278,7 @@ else if (inOpt != null) { // Found both
}

private boolean setupPreferencesForOO(String usrRoot, File inUsr) {
Globals.prefs.put("ooExecutablePath", new File(inUsr, "soffice.bin").getPath());
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inUsr, "soffice.bin").getPath());
File unoil = findFileDir(new File(usrRoot), "unoil.jar");
if (fileSearchCancelled) {
return false;
Expand All @@ -298,8 +288,8 @@ private boolean setupPreferencesForOO(String usrRoot, File inUsr) {
return false;
}
if ((unoil != null) && (jurt != null)) {
Globals.prefs.put("ooUnoilPath", unoil.getPath());
Globals.prefs.put("ooJurtPath", jurt.getPath());
Globals.prefs.put(JabRefPreferences.OO_UNOIL_PATH, unoil.getPath());
Globals.prefs.put(JabRefPreferences.OO_JURT_PATH, jurt.getPath());
return true;
} else {
return false;
Expand All @@ -312,7 +302,7 @@ private boolean setupPreferencesForOO(String usrRoot, File inUsr) {
* Since we are not including a library for Windows integration, this method can't
* find the Program files dir in localized Windows installations.
*/
private static java.util.List<File> findProgramFilesDir() {
private static List<File> findProgramFilesDir() {
List<String> sourceList = new ArrayList<>();
List<File> dirList = new ArrayList<>();

Expand Down Expand Up @@ -340,11 +330,11 @@ private static java.util.List<File> findProgramFilesDir() {

private static boolean checkAutoDetectedPaths() {

if (Globals.prefs.hasKey("ooUnoilPath") && Globals.prefs.hasKey("ooJurtPath")
&& Globals.prefs.hasKey("ooExecutablePath")) {
return new File(Globals.prefs.get("ooUnoilPath"), "unoil.jar").exists()
&& new File(Globals.prefs.get("ooJurtPath"), "jurt.jar").exists()
&& new File(Globals.prefs.get("ooExecutablePath")).exists();
if (Globals.prefs.hasKey(JabRefPreferences.OO_UNOIL_PATH) && Globals.prefs.hasKey(JabRefPreferences.OO_JURT_PATH)
&& Globals.prefs.hasKey(JabRefPreferences.OO_EXECUTABLE_PATH)) {
return new File(Globals.prefs.get(JabRefPreferences.OO_UNOIL_PATH), "unoil.jar").exists()
&& new File(Globals.prefs.get(JabRefPreferences.OO_JURT_PATH), "jurt.jar").exists()
&& new File(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH)).exists();
} else {
return false;
}
Expand Down Expand Up @@ -384,7 +374,6 @@ private File findFileDir(File startDir, String filename) {

public JDialog showProgressDialog(JDialog progressParent, String title, String message, boolean includeCancelButton) {
fileSearchCancelled = false;
final JDialog progressDialog;
JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL);
JButton cancel = new JButton(Localization.lang("Cancel"));
cancel.addActionListener(new ActionListener() {
Expand All @@ -395,7 +384,7 @@ public void actionPerformed(ActionEvent event) {
((JButton) event.getSource()).setEnabled(false);
}
});
progressDialog = new JDialog(progressParent, title, false);
final JDialog progressDialog = new JDialog(progressParent, title, false);
bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
bar.setIndeterminate(true);
if (includeCancelButton) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/sf/jabref/openoffice/BstWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class BstWrapper {

private static final Log LOGGER = LogFactory.getLog(BstWrapper.class);

private static final Pattern BIB_ITEM_TAG = Pattern.compile("\\\\[a-zA-Z]*item\\{.*\\}");


public BstWrapper() {

}
Expand Down Expand Up @@ -74,13 +77,11 @@ public Map<String, String> processEntries(Collection<BibEntry> entries, BibDatab
}


private static final Pattern bibitemTag = Pattern.compile("\\\\[a-zA-Z]*item\\{.*\\}");


private Map<String, String> parseResult(String result) {
Map<String, String> map = new HashMap<>();
// Look through for instances of \bibitem :
Matcher m = BstWrapper.bibitemTag.matcher(result);
Matcher m = BstWrapper.BIB_ITEM_TAG.matcher(result);
ArrayList<Integer> indices = new ArrayList<>();
ArrayList<Integer> endIndices = new ArrayList<>();
ArrayList<String> keys = new ArrayList<>();
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/net/sf/jabref/openoffice/CitationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ static class CitEntry implements Comparable<CitEntry> {

final String refMarkName;
String pageInfo;
final String keyString;
private final String keyString;
final String context;
final String origPageInfo;
final List<String> keys;
private final String origPageInfo;
private final List<String> keys;


public CitEntry(String refMarkName, List<String> keys, String context, String pageInfo) {
Expand All @@ -156,10 +156,10 @@ public boolean pageInfoChanged() {
|| ((pageInfo == null) && (origPageInfo != null))) {
return true;
}
if (pageInfo != null) {
return pageInfo.compareTo(origPageInfo) != 0;
} else {
if (pageInfo == null) {
return false;
} else {
return pageInfo.compareTo(origPageInfo) != 0;
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public Object getColumnValue(CitEntry citEntry, int i) {
case 0:
return citEntry.context;
default:
return citEntry.pageInfo != null ? citEntry.pageInfo : "";
return citEntry.pageInfo == null ? "" : citEntry.pageInfo;
}
}
}
Expand All @@ -217,12 +217,12 @@ public void mouseClicked(MouseEvent e) {

class SingleCitDialog {

final JDialog singleCiteDialog;
final JTextField pageInfo = new JTextField(20);
final JLabel title;
final JButton okButton = new JButton(Localization.lang("OK"));
final JButton cancelButton = new JButton(Localization.lang("Cancel"));
final CitEntry _entry;
private final JDialog singleCiteDialog;
private final JTextField pageInfo = new JTextField(20);
private final JLabel title;
private final JButton okButton = new JButton(Localization.lang("OK"));
private final JButton cancelButton = new JButton(Localization.lang("Cancel"));
private final CitEntry _entry;


public SingleCitDialog(CitEntry entry) {
Expand Down Expand Up @@ -253,10 +253,10 @@ public SingleCitDialog(CitEntry entry) {

@Override
public void actionPerformed(ActionEvent actionEvent) {
if (!pageInfo.getText().trim().isEmpty()) {
_entry.pageInfo = pageInfo.getText().trim();
} else {
if (pageInfo.getText().trim().isEmpty()) {
_entry.pageInfo = null;
} else {
_entry.pageInfo = pageInfo.getText().trim();
}
tableModel.fireTableDataChanged();
singleCiteDialog.dispose();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/openoffice/ComparableMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public ComparableMark(String name, Point position) {

@Override
public int compareTo(ComparableMark other) {
if (position.Y != other.position.Y) {
return position.Y - other.position.Y;
} else {
if (position.Y == other.position.Y) {
return position.X - other.position.X;
} else {
return position.Y - other.position.Y;
}
}

Expand Down

0 comments on commit 37421b2

Please sign in to comment.