Skip to content

Commit

Permalink
use JabRefException for prefs export
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Nov 25, 2015
1 parent 58065d8 commit 8a554b3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/JabRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public Vector<ParserResult> processArguments(String[] args, boolean initialStart
if (cli.isPreferencesExport()) {
try {
Globals.prefs.exportPreferences(cli.getPreferencesExport());
} catch (IOException ex) {
} catch (JabRefException ex) {
LOGGER.error("Cannot export preferences", ex);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/sf/jabref/JabRefException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class JabRefException extends Exception {

private String localizedMessage;
Expand All @@ -30,7 +29,7 @@ public JabRefException(String message, String localizedMessage, Throwable cause)

@Override
public String getLocalizedMessage() {
if(localizedMessage==null) {
if (localizedMessage == null) {
LOGGER.warn("No localized message exception message defined. Falling back to getMessage().");
return getMessage();
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,8 @@ public void flush() {
if (getBoolean(MEMORY_STICK_MODE)) {
try {
exportPreferences("jabref.xml");
} catch (IOException e) {
LOGGER.info("Could not save preferences for memory stick mode: " + e.getLocalizedMessage(), e);
} catch (JabRefException e) {
LOGGER.warn("Could not export preferences for memory stick mode: " + e.getMessage(), e);
}
}
try {
Expand Down Expand Up @@ -1634,12 +1634,12 @@ public void updateEntryEditorTabList() {
*
* @param filename String File to export to
*/
public void exportPreferences(String filename) throws IOException {
public void exportPreferences(String filename) throws JabRefException {
File f = new File(filename);
try (OutputStream os = new FileOutputStream(f)) {
prefs.exportSubtree(os);
} catch (BackingStoreException ex) {
throw new IOException(ex);
} catch (BackingStoreException | IOException ex) {
throw new JabRefException("Could not export preferences", Localization.lang("Could not export preferences"), ex);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,10 @@ public void actionPerformed(ActionEvent e) {

try {
prefs.exportPreferences(filename);
} catch (IOException ex) {
JOptionPane.showMessageDialog(PreferencesDialog.this,
Localization.lang("Could not export preferences")
+ ": " + ex.getMessage(), Localization.lang("Export preferences"),
JOptionPane.ERROR_MESSAGE);
} catch (JabRefException ex) {
LOGGER.warn(ex.getMessage(), ex);
JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE);
}
}

Expand All @@ -222,9 +221,9 @@ public void actionPerformed(ActionEvent e) {
frame.removeCachedEntryEditors();
Globals.prefs.updateEntryEditorTabList();
} catch (JabRefException ex) {
LOGGER.warn(ex.getMessage(), ex);
JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
Localization.lang("Import preferences"), JOptionPane.ERROR_MESSAGE);
LOGGER.warn(ex.getMessage(), ex);
}
}

Expand Down

0 comments on commit 8a554b3

Please sign in to comment.