From 37421b2361f7a28546a3f799657edbadb4b840a3 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 27 Dec 2015 12:55:23 +0100 Subject: [PATCH] Solved #593 and cleaned up the OO-code a bit --- CHANGELOG.md | 1 + .../java/net/sf/jabref/JabRefPreferences.java | 5 ++ .../sf/jabref/openoffice/AutoDetectPaths.java | 55 ++++++++----------- .../net/sf/jabref/openoffice/BstWrapper.java | 7 ++- .../sf/jabref/openoffice/CitationManager.java | 32 +++++------ .../sf/jabref/openoffice/ComparableMark.java | 6 +- .../net/sf/jabref/openoffice/OOBibBase.java | 49 +++++++---------- .../net/sf/jabref/openoffice/OOBibStyle.java | 34 ++++++------ .../java/net/sf/jabref/openoffice/OOUtil.java | 32 +++++++---- .../sf/jabref/openoffice/OpenOfficePanel.java | 43 +++++++-------- .../jabref/openoffice/StyleSelectDialog.java | 19 +++---- 11 files changed, 138 insertions(+), 145 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 105678a43235..eaa5cab5ef4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/net/sf/jabref/JabRefPreferences.java b/src/main/java/net/sf/jabref/JabRefPreferences.java index 8b99913e3387..76ca35add985 100644 --- a/src/main/java/net/sf/jabref/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/JabRefPreferences.java @@ -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_"; diff --git a/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java b/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java index e31431141ead..a359db640cc4 100644 --- a/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java +++ b/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java @@ -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.*; @@ -66,10 +67,6 @@ public void run() { foundPaths = autoDetectPaths(); } - public boolean getResult() { - return foundPaths; - } - public boolean cancelled() { return fileSearchCancelled; } @@ -89,10 +86,10 @@ private boolean autoDetectPaths() { if (OS.WINDOWS) { List progFiles = AutoDetectPaths.findProgramFilesDir(); - File sOffice = null; if (fileSearchCancelled) { return false; } + File sOffice = null; List sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { sOffice = findFileDir(dir, "soffice.exe"); @@ -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; @@ -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; @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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; @@ -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 findProgramFilesDir() { + private static List findProgramFilesDir() { List sourceList = new ArrayList<>(); List dirList = new ArrayList<>(); @@ -340,11 +330,11 @@ private static java.util.List 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; } @@ -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() { @@ -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) { diff --git a/src/main/java/net/sf/jabref/openoffice/BstWrapper.java b/src/main/java/net/sf/jabref/openoffice/BstWrapper.java index d0b6e9e58538..a0c7fa71b8a1 100644 --- a/src/main/java/net/sf/jabref/openoffice/BstWrapper.java +++ b/src/main/java/net/sf/jabref/openoffice/BstWrapper.java @@ -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() { } @@ -74,13 +77,11 @@ public Map processEntries(Collection entries, BibDatab } - private static final Pattern bibitemTag = Pattern.compile("\\\\[a-zA-Z]*item\\{.*\\}"); - private Map parseResult(String result) { Map map = new HashMap<>(); // Look through for instances of \bibitem : - Matcher m = BstWrapper.bibitemTag.matcher(result); + Matcher m = BstWrapper.BIB_ITEM_TAG.matcher(result); ArrayList indices = new ArrayList<>(); ArrayList endIndices = new ArrayList<>(); ArrayList keys = new ArrayList<>(); diff --git a/src/main/java/net/sf/jabref/openoffice/CitationManager.java b/src/main/java/net/sf/jabref/openoffice/CitationManager.java index 9d12556ba7a3..616dc4f2bb2e 100644 --- a/src/main/java/net/sf/jabref/openoffice/CitationManager.java +++ b/src/main/java/net/sf/jabref/openoffice/CitationManager.java @@ -129,10 +129,10 @@ static class CitEntry implements Comparable { final String refMarkName; String pageInfo; - final String keyString; + private final String keyString; final String context; - final String origPageInfo; - final List keys; + private final String origPageInfo; + private final List keys; public CitEntry(String refMarkName, List keys, String context, String pageInfo) { @@ -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; } } @@ -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; } } } @@ -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) { @@ -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(); diff --git a/src/main/java/net/sf/jabref/openoffice/ComparableMark.java b/src/main/java/net/sf/jabref/openoffice/ComparableMark.java index 50555c67ef8b..b273163e4832 100644 --- a/src/main/java/net/sf/jabref/openoffice/ComparableMark.java +++ b/src/main/java/net/sf/jabref/openoffice/ComparableMark.java @@ -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; } } diff --git a/src/main/java/net/sf/jabref/openoffice/OOBibBase.java b/src/main/java/net/sf/jabref/openoffice/OOBibBase.java index 9418a300728e..2e9210bce57c 100644 --- a/src/main/java/net/sf/jabref/openoffice/OOBibBase.java +++ b/src/main/java/net/sf/jabref/openoffice/OOBibBase.java @@ -62,17 +62,10 @@ class OOBibBase { private static final String BIB_CITATION = "JR_cite"; private final Pattern citePattern = Pattern.compile(OOBibBase.BIB_CITATION + "\\d*_(\\d*)_(.*)"); - private static final int - AUTHORYEAR_PAR = 1; + private static final int AUTHORYEAR_PAR = 1; private static final int AUTHORYEAR_INTEXT = 2; private static final int INVISIBLE_CIT = 3; - static final String DEFAULT_CONNECTION_STRING = "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"; - final String[] BIB_TYPES = new String[] {"ARTICLE", "BOOK", "BOOKLET", "CONFERENCE", - "INBOOK", "INCOLLECTION", "INPROCEEDINGS", "JOURNAL", "MANUAL", "MASTERTHESIS", - "MISC", "PHDTHESIS", "PROCEEDINGS", "TECHREPORT", "UNPUBLISHED", "EMAIL", "WWW", - "CUSTOM1", "CUSTOM2", "CUSTOM3", "CUSTOM4", "CUSTOM5"}; - private XMultiServiceFactory mxDocFactory; private XTextDocument mxDoc; private XText text; @@ -87,7 +80,7 @@ class OOBibBase { private final AuthorYearTitleComparator entryComparator = new AuthorYearTitleComparator(); private final YearAuthorTitleComparator yearAuthorTitleComparator = new YearAuthorTitleComparator(); - private final HashMap uniquefiers = new HashMap<>(); + private final Map uniquefiers = new HashMap<>(); private String[] sortedReferenceMarks; @@ -138,7 +131,7 @@ else if (ls.size() > 1) { XComponent.class, selected); mxDoc = selected; - com.sun.star.text.XDocumentIndexesSupplier indexesSupp = UnoRuntime.queryInterface( + XDocumentIndexesSupplier indexesSupp = UnoRuntime.queryInterface( XDocumentIndexesSupplier.class, xCurrentComponent); XModel xModel = UnoRuntime.queryInterface(XModel.class, xCurrentComponent); @@ -305,9 +298,7 @@ public void insertEntry(BibEntry[] entries, BibDatabase database, setCustomProperty(bName, pageInfo); } - String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, database, inParenthesis, null, null); - //System.out.println(text+" / "+xViewCursor.getText()); xViewCursor.getText().insertString(xViewCursor, " ", false); if (style.isFormatCitations()) { XPropertySet xCursorProps = UnoRuntime.queryInterface( @@ -325,6 +316,8 @@ public void insertEntry(BibEntry[] entries, BibDatabase database, } } xViewCursor.goLeft((short) 1, false); + String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, database, inParenthesis, + null, null); insertReferenceMark(bName, citeText, xViewCursor, withText, style); //xViewCursor.collapseToEnd(); @@ -457,7 +450,7 @@ else if (style.isNumberEntries()) { if (m.find()) { String typeStr = m.group(1); int type = Integer.parseInt(typeStr); - types[i] = type; // Remember the type in case we need to uniqiefy. + types[i] = type; // Remember the type in case we need to uniquefy. String[] keys = m.group(2).split(","); bibtexKeys[i] = keys; BibEntry[] cEntries = new BibEntry[keys.length]; @@ -855,10 +848,10 @@ private String getUniqueReferenceMarkName(String bibtexKey, int type) { return name; } - private LinkedHashMap findCitedEntries + private Map findCitedEntries (List databases, List keys, - HashMap linkSourceBase) { - LinkedHashMap entries = new LinkedHashMap<>(); + Map linkSourceBase) { + Map entries = new LinkedHashMap<>(); for (String key : keys) { boolean found = false; for (BibDatabase database : databases) { @@ -878,7 +871,7 @@ private String getUniqueReferenceMarkName(String bibtexKey, int type) { return entries; } - private List findCitedKeys() throws com.sun.star.container.NoSuchElementException, WrappedTargetException { + private List findCitedKeys() throws NoSuchElementException, WrappedTargetException { XReferenceMarksSupplier supplier = UnoRuntime.queryInterface( XReferenceMarksSupplier.class, xCurrentComponent); @@ -901,14 +894,12 @@ private List findCitedKeys() throws com.sun.star.container.NoSuchElement return keys; } - private LinkedHashMap getSortedEntriesFromSortedRefMarks - (String[] names, - Map entries, - HashMap linkSourceBase) + private Map getSortedEntriesFromSortedRefMarks(String[] names, + Map entries, Map linkSourceBase) throws BibtexEntryNotFoundException { - LinkedHashMap newList = new LinkedHashMap<>(); - HashMap adaptedEntries = new HashMap<>(); + Map newList = new LinkedHashMap<>(); + Map adaptedEntries = new HashMap<>(); for (String name : names) { Matcher m = citePattern.matcher(name); if (m.find()) { @@ -1058,7 +1049,7 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map { private Layout defaultBibLayout; // reference layout mapped from entry type number: - private final HashMap bibLayout = new HashMap<>(); + private final Map bibLayout = new HashMap<>(); - private final HashMap properties = new HashMap<>(); - private final HashMap citProperties = new HashMap<>(); + private final Map properties = new HashMap<>(); + private final Map citProperties = new HashMap<>(); private final Pattern numPattern = Pattern.compile("-?\\d+"); @@ -186,10 +186,10 @@ private void reload() throws Exception { * @return true if the file has not been modified, false otherwise. */ private boolean isUpToDate() { - if (styleFile != null) { - return styleFile.lastModified() == OOBibStyle.styleFileModificationTime; - } else { + if (styleFile == null) { return true; + } else { + return styleFile.lastModified() == OOBibStyle.styleFileModificationTime; } } @@ -277,7 +277,7 @@ public boolean isValid() { * @throws IOException */ private void handleStructureLine(String line) { - int index = line.indexOf("="); + int index = line.indexOf('='); if ((index > 0) && (index < (line.length() - 1))) { String formatString = line.substring(index + 1); //System.out.println("'"+line.substring(0, index)+"' : '"+formatString+"'"); @@ -308,8 +308,8 @@ private void handleStructureLine(String line) { * @param line The line containing the formatter names. * @throws IOException */ - private void handlePropertiesLine(String line, HashMap map) { - int index = line.indexOf("="); + private void handlePropertiesLine(String line, Map map) { + int index = line.indexOf('='); if ((index > 0) && (index <= (line.length() - 1))) { String propertyName = line.substring(0, index).trim(); String value = line.substring(index + 1); @@ -342,10 +342,10 @@ private void handleJournalsLine(String line) { public Layout getReferenceFormat(String type) { Layout l = bibLayout.get(type.toLowerCase()); - if (l != null) { - return l; - } else { + if (l == null) { return defaultBibLayout; + } else { + return l; } } @@ -618,7 +618,7 @@ private String getAuthorYearParenthesisMarker(BibEntry[] entries, BibDatabase da StringBuffer sb = new StringBuffer(startBrace); for (int j = 0; j < entries.length; j++) { - int unlimA = unlimAuthors != null ? unlimAuthors[j] : -1; + int unlimA = unlimAuthors == null ? -1 : unlimAuthors[j]; int maxAuthors = unlimA > 0 ? unlimA : maxA; BibEntry entry = entries[j]; @@ -690,7 +690,7 @@ private String getAuthorYearInTextMarker(BibEntry[] entries, BibDatabase databas StringBuffer sb = new StringBuffer(); for (int i = 0; i < entries.length; i++) { - int unlimA = unlimAuthors != null ? unlimAuthors[i] : -1; + int unlimA = unlimAuthors == null ? -1 : unlimAuthors[i]; int maxAuthors = unlimA > 0 ? unlimA : maxA; // Check if this entry has been nulled due to grouping with the previous entry(ies): @@ -898,10 +898,10 @@ public int compareTo(OOBibStyle other) { @Override public boolean equals(Object o) { - if (o != null) { - return styleFile.equals(((OOBibStyle) o).styleFile); - } else { + if (o == null) { return false; + } else { + return styleFile.equals(((OOBibStyle) o).styleFile); } } diff --git a/src/main/java/net/sf/jabref/openoffice/OOUtil.java b/src/main/java/net/sf/jabref/openoffice/OOUtil.java index f3f178785671..d7eff939f6f1 100644 --- a/src/main/java/net/sf/jabref/openoffice/OOUtil.java +++ b/src/main/java/net/sf/jabref/openoffice/OOUtil.java @@ -45,9 +45,12 @@ */ class OOUtil { - private static final Pattern htmlTag = Pattern.compile(""); + private static final Pattern HTML_TAG = Pattern.compile(""); + + static final OOPreFormatter POSTFORMATTER = new OOPreFormatter(); + + private static final String UNIQUEFIER_FIELD = "uniq"; - static final OOPreFormatter postformatter = new OOPreFormatter(); /** @@ -65,19 +68,26 @@ public static void insertFullReferenceAtCurrentLocation(XText text, XTextCursor Layout layout, String parStyle, BibEntry entry, BibDatabase database, String uniquefier) throws Exception { - final String UNIQUEFIER_FIELD = "uniq"; - // Backup the value of the uniq field, just in case the entry already has it: String oldUniqVal = entry.getField(UNIQUEFIER_FIELD); + // Set the uniq field with the supplied uniquefier: - entry.setField(UNIQUEFIER_FIELD, uniquefier); + if (uniquefier == null) { + entry.clearField(UNIQUEFIER_FIELD); + } else { + entry.setField(UNIQUEFIER_FIELD, uniquefier); + } // Do the layout for this entry: String lText = layout.doLayout(entry, database); // Afterwards, reset the old value: - entry.setField(UNIQUEFIER_FIELD, oldUniqVal); + if (oldUniqVal == null) { + entry.clearField(UNIQUEFIER_FIELD); + } else { + entry.setField(UNIQUEFIER_FIELD, oldUniqVal); + } // Insert the formatted text: OOUtil.insertOOFormattedTextAtCurrentLocation(text, cursor, lText, parStyle); @@ -117,11 +127,11 @@ public static void insertOOFormattedTextAtCurrentLocation(XText text, XTextCurso //insertTextAtCurrentLocation(text, cursor, "_", // false, false, false, false, false, false); //cursor.goLeft((short)1, true); - Matcher m = OOUtil.htmlTag.matcher(lText); + Matcher m = OOUtil.HTML_TAG.matcher(lText); while (m.find()) { String ss = lText.substring(piv, m.start()); if (!ss.isEmpty()) { - OOUtil.insertTextAtCurrentLocation(text, cursor, ss, bold % 2 > 0, italic % 2 > 0, + OOUtil.insertTextAtCurrentLocation(text, cursor, ss, (bold % 2) > 0, (italic % 2) > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0); } String tag = m.group(); @@ -158,7 +168,7 @@ public static void insertOOFormattedTextAtCurrentLocation(XText text, XTextCurso if (piv < lText.length()) { OOUtil.insertTextAtCurrentLocation(text, cursor, lText.substring(piv), - bold % 2 > 0, italic % 2 > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0); + (bold % 2) > 0, (italic % 2) > 0, mono > 0, smallCaps > 0, sup > 0, sub > 0); } cursor.collapseToEnd(); @@ -307,8 +317,8 @@ public static BibEntry createAdaptedEntry(BibEntry entry) { String value = e.getField(field); // If the running JabRef version doesn't support post-processing in Layout, // preprocess fields instead: - if (!OpenOfficePanel.postLayoutSupported && value != null) { - e.setField(field, OOUtil.postformatter.format(value)); + if (!OpenOfficePanel.postLayoutSupported && (value != null)) { + e.setField(field, OOUtil.POSTFORMATTER.format(value)); } } return e; diff --git a/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java index f0e976c50a94..59db48ccd51b 100644 --- a/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java @@ -130,17 +130,17 @@ private OpenOfficePanel() { OpenOfficePanel.update.setToolTipText(Localization.lang("Sync OO bibliography")); if (OS.WINDOWS) { Globals.prefs.putDefaultValue("ooPath", "C:\\Program Files\\OpenOffice.org 4"); - Globals.prefs.putDefaultValue("ooExecutablePath", + Globals.prefs.putDefaultValue(JabRefPreferences.OO_EXECUTABLE_PATH, "C:\\Program Files\\OpenOffice.org 4\\program\\soffice.exe"); Globals.prefs.putDefaultValue("ooJarsPath", "C:\\Program Files\\OpenOffice.org 4\\program\\classes"); } else if (OS.OS_X) { - Globals.prefs.putDefaultValue("ooExecutablePath", "/Applications/OpenOffice.org.app/Contents/MacOS/soffice.bin"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_EXECUTABLE_PATH, "/Applications/OpenOffice.org.app/Contents/MacOS/soffice.bin"); Globals.prefs.putDefaultValue("ooPath", "/Applications/OpenOffice.org.app"); Globals.prefs.putDefaultValue("ooJarsPath", "/Applications/OpenOffice.org.app/Contents/basis-link"); } else { // Linux //Globals.prefs.putDefaultValue("ooPath", "/usr/lib/openoffice"); Globals.prefs.putDefaultValue("ooPath", "/opt/openoffice.org3"); - Globals.prefs.putDefaultValue("ooExecutablePath", "/usr/lib/openoffice/program/soffice"); + Globals.prefs.putDefaultValue(JabRefPreferences.OO_EXECUTABLE_PATH, "/usr/lib/openoffice/program/soffice"); //Globals.prefs.putDefaultValue("ooJarsPath", "/usr/share/java/openoffice"); Globals.prefs.putDefaultValue("ooJarsPath", "/opt/openoffice.org/basis3.0"); } @@ -512,9 +512,9 @@ private void connect(boolean auto) { } // User clicked Auto, and the system successfully detected paths: - unoilDir = Globals.prefs.get("ooUnoilPath"); - ooBaseDirectory = Globals.prefs.get("ooJurtPath"); - sOffice = Globals.prefs.get("ooExecutablePath"); + unoilDir = Globals.prefs.get(JabRefPreferences.OO_UNOIL_PATH); + ooBaseDirectory = Globals.prefs.get(JabRefPreferences.OO_JURT_PATH); + sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH); //System.out.println("unoilDir: "+unoilDir); //System.out.println("ooBaseDir: "+ooBaseDirectory); @@ -530,7 +530,7 @@ private void connect(boolean auto) { String ooPath = Globals.prefs.get("ooPath"); String ooJars = Globals.prefs.get("ooJarsPath"); - sOffice = Globals.prefs.get("ooExecutablePath"); + sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH); if (OS.WINDOWS) { unoilDir = ooPath + "\\program\\classes"; @@ -592,15 +592,15 @@ else if (OS.OS_X) { OpenOfficePanel.manageCitations.setEnabled(true); OpenOfficePanel.test.setEnabled(true); + } catch (UnsatisfiedLinkError e) { + e.printStackTrace(); + JOptionPane.showMessageDialog(OpenOfficePanel.frame, + Localization.lang("Unable to connect. One possible reason is that JabRef " + + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); } catch (Throwable e) { e.printStackTrace(); - if (e instanceof UnsatisfiedLinkError) { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Unable to connect. One possible reason is that JabRef " - + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); - - } - else { - JOptionPane.showMessageDialog(OpenOfficePanel.frame, Localization.lang("Could not connect to running OpenOffice.") + JOptionPane.showMessageDialog(OpenOfficePanel.frame, + Localization.lang("Could not connect to running OpenOffice.") + "\n" + Localization.lang("Make sure you have installed OpenOffice with Java support.") + "\n" @@ -610,7 +610,6 @@ else if (OS.OS_X) { + Localization.lang("Error message:") + " " + e.getMessage()); } } - } @Override public void run() { @@ -668,7 +667,7 @@ private static void addURL(URL[] u) throws IOException { private void updateConnectionParams(String ooPath, String ooExec, String ooJars, boolean oo3) { Globals.prefs.put("ooPath", ooPath); - Globals.prefs.put("ooExecutablePath", ooExec); + Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, ooExec); Globals.prefs.put("ooJarsPath", ooJars); Globals.prefs.putBoolean("connectToOO3", oo3); } @@ -685,7 +684,7 @@ private void showConnectDialog() { final JTextField ooJars = new JTextField(30); JButton browseOOJars = new JButton(Localization.lang("Browse")); browseOOJars.addActionListener(BrowseAction.buildForDir(ooJars)); - ooExec.setText(Globals.prefs.get("ooExecutablePath")); + ooExec.setText(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH)); ooJars.setText(Globals.prefs.get("ooJarsPath")); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "")); if (OS.WINDOWS || OS.OS_X) { @@ -925,11 +924,11 @@ public void actionPerformed(ActionEvent actionEvent) { @Override public void actionPerformed(ActionEvent actionEvent) { Globals.prefs.clear("ooPAth"); - Globals.prefs.clear("ooExecutablePath"); + Globals.prefs.clear(JabRefPreferences.OO_EXECUTABLE_PATH); Globals.prefs.clear("ooJarsPath"); Globals.prefs.clear("connectToOO3"); - Globals.prefs.clear("ooUnoilPath"); - Globals.prefs.clear("ooJurtPath"); + Globals.prefs.clear(JabRefPreferences.OO_UNOIL_PATH); + Globals.prefs.clear(JabRefPreferences.OO_JURT_PATH); OpenOfficePanel.frame.output(Localization.lang("Cleared connection settings.")); } }); @@ -948,19 +947,17 @@ private void pushEntries(boolean inParenthesis, BibEntry[] entries) { final BibDatabase database = OpenOfficePanel.frame.getCurrentBasePanel().database(); if (entries.length > 0) { - String pageInfo = null; - //if (addPageInfo) { AdvancedCiteDialog acd = new AdvancedCiteDialog(OpenOfficePanel.frame); acd.showDialog(); if (acd.cancelled()) { return; } + String pageInfo = null; if (!acd.getPageInfo().isEmpty()) { pageInfo = acd.getPageInfo(); } inParenthesis = acd.isInParenthesisCite(); - //} try { OpenOfficePanel.ooBase.insertEntry(entries, database, getBaseList(), OpenOfficePanel.style, inParenthesis, true, diff --git a/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java b/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java index 77f1be8b25b6..92dc45324e69 100644 --- a/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java +++ b/src/main/java/net/sf/jabref/openoffice/StyleSelectDialog.java @@ -186,11 +186,11 @@ public void actionPerformed(ActionEvent actionEvent) { ExternalFileType type = Globals.prefs.getExternalFileTypeByExt("jstyle"); String link = tableModel.getElementAt(i).getFile().getPath(); try { - if (type != null) { - JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type); - } else { + if (type == null) { JabRefDesktop.openExternalFileUnknown(frame, null, new MetaData(), link, new UnknownExternalFileType("jstyle")); + } else { + JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type); } } catch (IOException e) { e.printStackTrace(); @@ -402,7 +402,11 @@ private void readStyles() { */ private void selectLastUsed() { // Set the initial selection of the table: - if (initSelection != null) { + if (initSelection == null) { + if (table.getRowCount() > 0) { + table.setRowSelectionInterval(0, 0); + } + } else { boolean found = false; for (int i = 0; i < table.getRowCount(); i++) { if (tableModel.getElementAt(i).getFile().getPath(). @@ -416,11 +420,6 @@ private void selectLastUsed() { table.setRowSelectionInterval(0, 0); } } - else { - if (table.getRowCount() > 0) { - table.setRowSelectionInterval(0, 0); - } - } } /** @@ -577,7 +576,7 @@ private void displayDefaultStyle(boolean authoryear) { StringBuilder sb = new StringBuilder(); while ((line = r.readLine()) != null) { sb.append(line); - sb.append("\n"); + sb.append('\n'); } // Make a dialog box to display the contents: