File tree 2 files changed +18
-9
lines changed
2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -469,7 +469,7 @@ private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException {
469
469
return List .of ();
470
470
}
471
471
URLDownload urlDownload = new URLDownload (pdfUrl );
472
- String filename = deriveFileNameFromUrl (pdfUrl );
472
+ String filename = URLUtil . getFileNameFromUrl (pdfUrl );
473
473
Path targetFile = targetDirectory .get ().resolve (filename );
474
474
try {
475
475
urlDownload .toFile (targetFile );
@@ -501,12 +501,4 @@ private List<BibEntry> handlePdfUrl(String pdfUrl) throws IOException {
501
501
return List .of ();
502
502
}
503
503
}
504
-
505
- private String deriveFileNameFromUrl (String url ) {
506
- String fileName = url .substring (url .lastIndexOf ('/' ) + 1 );
507
- if (fileName .isBlank ()) {
508
- fileName = "downloaded.pdf" ;
509
- }
510
- return FileUtil .getValidFileName (fileName );
511
- }
512
504
}
Original file line number Diff line number Diff line change 9
9
import java .util .Objects ;
10
10
import java .util .regex .Pattern ;
11
11
12
+ import org .jabref .logic .util .io .FileUtil ;
13
+
12
14
/**
13
15
* URL utilities for URLs in the JabRef logic.
14
16
* <p>
@@ -122,4 +124,19 @@ public static URI createUri(String url) {
122
124
throw new IllegalArgumentException (e );
123
125
}
124
126
}
127
+
128
+ /**
129
+ * Extracts the filename from a URL.
130
+ * If the URL doesn't have a filename (ends with '/'), returns a default name.
131
+ *
132
+ * @param url the URL string to extract the filename from
133
+ * @return the extracted filename or a default name if none found
134
+ */
135
+ public static String getFileNameFromUrl (String url ) {
136
+ String fileName = url .substring (url .lastIndexOf ('/' ) + 1 );
137
+ if (fileName .isBlank ()) {
138
+ fileName = "downloaded.pdf" ;
139
+ }
140
+ return FileUtil .getValidFileName (fileName );
141
+ }
125
142
}
You can’t perform that action at this time.
0 commit comments