Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package org.jabref.gui.exporter;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.fieldeditors.WriteMetadataToSinglePdfAction;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.BackgroundTask;
Expand Down Expand Up @@ -178,7 +183,10 @@ public Void call() {
filePreferences,
xmpPreferences);
entriesChanged++;
} catch (Exception e) {
} catch (IOException
| TransformerException
| SaveException
| ParserConfigurationException e) {
LOGGER.error("Error while writing XMP data to pdf '{}'", file, e);
failedWrittenFiles.add(file);
errors++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.Exception;
import com.sun.star.uno.XComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -73,7 +74,7 @@ private XDesktop simpleBootstrap(Path loPath)
Object desktop;
try {
desktop = sem.createInstanceWithContext("com.sun.star.frame.Desktop", context);
} catch (com.sun.star.uno.Exception e) {
} catch (Exception e) {
throw new CreationException(e.getMessage());
}
return UnoCast.cast(XDesktop.class, desktop).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jabref.model.study.StudyDatabase;
import org.jabref.model.study.StudyQuery;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -195,7 +196,7 @@ public SlrStudyAndDirectory saveStudy() {

try {
new GitHandler(studyDirectory).createCommitOnCurrentBranch("Update study definition", false);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
LOGGER.error("Could not commit study definition file in directory {}", studyDirectory, e);
dialogService.notify(Localization.lang("Please enter a valid file path.") +
": " + studyDirectory);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.ListIterator;
Expand Down Expand Up @@ -34,7 +35,10 @@ public static void refilterListReflection(FilteredList<BibEntryTableViewModel> f
initReflection();
}
REFILTER_METHOD.invoke(filteredList);
} catch (Exception e) {
} catch (IllegalAccessException
| InvocationTargetException
| NoSuchMethodException
| NoSuchFieldException e) {
LOGGER.warn("Could not refilter list", e);
}
}
Expand Down
1 change: 1 addition & 0 deletions jabkit/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
requires org.tinylog.api;
requires org.tinylog.api.slf4j;
requires org.tinylog.impl;
requires java.xml;
}
10 changes: 9 additions & 1 deletion jabkit/src/main/java/org/jabref/cli/Convert.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package org.jabref.cli;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.jabref.logic.exporter.Exporter;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -102,7 +107,10 @@ protected void exportFile(@NonNull ParserResult parserResult, @NonNull Path outp
parserResult.getDatabaseContext().getDatabase().getEntries(),
fileDirForDatabase,
Injector.instantiateModelOrService(JournalAbbreviationRepository.class));
} catch (Exception ex) {
} catch (IOException
| SaveException
| ParserConfigurationException
| TransformerException ex) {
LOGGER.error("Could not export file '{}'.", outputFile, ex);
}
}
Expand Down
15 changes: 13 additions & 2 deletions jabkit/src/main/java/org/jabref/cli/PdfUpdate.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.jabref.cli;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.jabref.logic.FilePreferences;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.exporter.EmbeddedBibFilePdfExporter;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.exporter.XmpPdfExporter;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.journals.JournalAbbreviationRepository;
Expand Down Expand Up @@ -180,7 +185,10 @@ private static void writeMetadataToPDFsOfEntry(BibDatabaseContext databaseContex
System.out.println(Localization.lang("Cannot embed metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey));
}
}
} catch (Exception e) {
} catch (IOException
| ParserConfigurationException
| SaveException
| TransformerException e) {
LOGGER.error("Failed writing metadata on a linked file of {}.", citeKey);
}
}
Expand Down Expand Up @@ -248,7 +256,10 @@ private static void writeMetadataToPdfByFileNames(BibDatabaseContext databaseCon
System.out.println(Localization.lang("File %0 is not linked to any entry in library.", filePath));
}
}
} catch (Exception e) {
} catch (IOException
| ParserConfigurationException
| SaveException
| TransformerException e) {
LOGGER.error("Error writing entry to {}.", filePath);
}
}
Expand Down
9 changes: 8 additions & 1 deletion jabkit/src/main/java/org/jabref/cli/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import java.util.List;
import java.util.Optional;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.jabref.logic.exporter.Exporter;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -123,7 +127,10 @@ public void run() {
matches,
List.of(),
Injector.instantiateModelOrService(JournalAbbreviationRepository.class));
} catch (Exception ex) {
} catch (IOException
| SaveException
| ParserConfigurationException
| TransformerException ex) {
LOGGER.error("Could not export file '{}}'", outputFile.toAbsolutePath(), ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static void generateCitationStyleCatalog() {
List<CitationStyle> styles = discoverStyles(stylesDirectory);

generateCatalog(styles);
} catch (Exception e) {
} catch (URISyntaxException | IOException e) {
LOGGER.error("Error generating citation style catalog", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public static void main(String[] args) {
*/
private static Path downloadLtwaFile() throws IOException, URISyntaxException {
LOGGER.info("Downloading LTWA file from {}.", LtwaListMvGenerator.LTWA_URL);
InputStream inputStream = new URI(LTWA_URL).toURL().openStream();
Path path = Files.writeString(
Files.createTempFile("ltwa", ".csv"),
new String(inputStream.readAllBytes()),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
inputStream.close();
return path;
try (InputStream inputStream = new URI(LTWA_URL).toURL().openStream()) {
Path path = Files.writeString(
Files.createTempFile("ltwa", ".csv"),
new String(inputStream.readAllBytes()),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
return path;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.ai.chatting.model;

import java.io.IOException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
Expand Down Expand Up @@ -88,7 +89,7 @@ public ChatResponse chat(List<ChatMessage> list) {
.tokenUsage(new TokenUsage(0, 0))
.finishReason(FinishReason.OTHER)
.build();
} catch (Exception e) {
} catch (IOException | InterruptedException e) {
LOGGER.error("Error generating message from Gpt4All", e);
throw new RuntimeException("Failed to generate AI message", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.ai.ingestion;

import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.Optional;
Expand Down Expand Up @@ -51,7 +52,7 @@ private Optional<Document> fromPdfFile(Path path) {
}

return fromString(writer.toString());
} catch (Exception e) {
} catch (IOException e) {
LOGGER.error("An error occurred while reading the PDF file: {}", path, e);
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public BstPreviewLayout(Path path) {
}
try {
bstVM = new BstVM(path);
} catch (Exception e) {
} catch (IOException e) {
LOGGER.error("Could not read {}.", path.toAbsolutePath(), e);
error = Localization.lang("Error opening file '%0'", path.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,8 @@ private void loadExternalStyles() {

List<String> stylePaths = openOfficePreferences.getExternalCslStyles();
for (String stylePath : stylePaths) {
try {
Optional<CitationStyle> style = CSLStyleUtils.createCitationStyleFromFile(stylePath);
style.ifPresent(EXTERNAL_STYLES::add);
} catch (Exception e) {
LOGGER.info("Problem reading external style file {}", stylePath, e);
}
Optional<CitationStyle> style = CSLStyleUtils.createCitationStyleFromFile(stylePath);
style.ifPresent(EXTERNAL_STYLES::add);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void close() throws IOException {
if (Files.exists(targetFile)) {
try {
Files.copy(targetFile, backupFile, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
} catch (IOException e) {
LOGGER.warn("Could not create backup file {}", backupFile);
}
if (FileUtil.IS_POSIX_COMPLIANT) {
Expand All @@ -229,7 +229,7 @@ public void close() throws IOException {
try {
// Move temporary file (replace original if it exists)
Files.move(temporaryFile, targetFile, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
} catch (IOException e) {
LOGGER.warn("Could not move temporary file", e);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.jabref.logic.bibtex.comparator.FieldComparator;
import org.jabref.logic.bibtex.comparator.FieldComparatorStack;
Expand Down Expand Up @@ -34,7 +34,7 @@ class OOCalcDatabase {

private final List<BibEntry> entries = new ArrayList<>();
private final List<Field> toExportFields = Stream.concat(FieldFactory.getStandardFieldsWithCitationKey().stream(), Stream.of(REPORT_TYPE_FIELD))
.collect(Collectors.toList());
.toList();

public OOCalcDatabase(BibDatabase bibtex, List<BibEntry> entries) {
this.entries.addAll(entries != null ? entries : bibtex.getEntries());
Expand Down Expand Up @@ -68,7 +68,7 @@ public Document getDOMrepresentation() {
for (BibEntry entry : entries) {
addEntryRow(entry, table, document);
}
} catch (Exception e) {
} catch (ParserConfigurationException e) {
LOGGER.warn("Exception caught...", e);
}
return document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.jabref.logic.bibtex.comparator.FieldComparator;
import org.jabref.logic.bibtex.comparator.FieldComparatorStack;
Expand Down Expand Up @@ -190,7 +191,7 @@ public Document getDOMrepresentation() {
collection.appendChild(body);

result.appendChild(collection);
} catch (Exception e) {
} catch (ParserConfigurationException e) {
LOGGER.warn("Exception caught...", e);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
Expand Down Expand Up @@ -113,7 +114,7 @@ private static void exportOpenDocumentSpreadsheetXML(File tmpFile, BibDatabase d
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.transform(source, result);
} catch (Exception e) {
} catch (TransformerException | IOException e) {
throw new Error(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
Expand Down Expand Up @@ -95,7 +96,7 @@ private static void exportOpenOfficeCalcXML(File tmpFile, BibDatabase database,
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.transform(source, result);
} catch (Exception e) {
} catch (TransformerException | IOException e) {
throw new Error(e);
}
}
Expand Down
Loading