Skip to content

Commit d3b3355

Browse files
committed
Upgrade dependencies
1 parent 96ace93 commit d3b3355

6 files changed

Lines changed: 26 additions & 21 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.project
33
.settings
44
.vscode
5+
.idea
56
target

examples/pdf birthday card/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rm ./*.pdf
2+
java -jar ../../target/csv2pdf.jar -csv_file persons.csv -ftl_file birthday_card.ftl -for_each -pdf 'happy birthday ${name}!.pdf'

examples/pdf simple catalog/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rm ./*.pdf
2+
java -jar ../../target/csv2pdf.jar -csv_file products.csv -ftl_file template.ftl -pdf catalog.pdf
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rm ./*.pdf
2+
java -jar ../../target/csv2pdf.jar -csv_file grades.csv -ftl_file template.ftl -pdf example.pdf

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>csv2pdf</groupId>
88
<artifactId>csv2pdf</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.0.3</version>
1010

1111
<name>csv2pdf</name>
1212

@@ -20,17 +20,17 @@
2020
<dependency>
2121
<groupId>commons-cli</groupId>
2222
<artifactId>commons-cli</artifactId>
23-
<version>1.4</version>
23+
<version>1.5.0</version>
2424
</dependency>
2525
<dependency>
2626
<groupId>net.sourceforge.csvjdbc</groupId>
2727
<artifactId>csvjdbc</artifactId>
28-
<version>1.0.36</version>
28+
<version>1.0.40</version>
2929
</dependency>
3030
<dependency>
3131
<groupId>org.freemarker</groupId>
3232
<artifactId>freemarker</artifactId>
33-
<version>2.3.30</version>
33+
<version>2.3.31</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>org.jsoup</groupId>
@@ -40,12 +40,12 @@
4040
<dependency>
4141
<groupId>org.xhtmlrenderer</groupId>
4242
<artifactId>flying-saucer-pdf-openpdf</artifactId>
43-
<version>9.1.20</version>
43+
<version>9.1.22</version>
4444
</dependency>
4545
<dependency>
4646
<groupId>org.apache.commons</groupId>
4747
<artifactId>commons-text</artifactId>
48-
<version>1.8</version>
48+
<version>1.10.0</version>
4949
</dependency>
5050
</dependencies>
5151

src/main/java/csv2pdf/App.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package csv2pdf;
22

33
import freemarker.template.Configuration;
4-
import freemarker.template.MalformedTemplateNameException;
54
import freemarker.template.Template;
6-
import java.io.FileOutputStream;
75
import java.io.OutputStream;
86
import java.io.StringWriter;
97
import java.nio.file.FileSystems;
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
1010
import java.sql.Connection;
1111
import java.sql.DriverManager;
1212
import java.sql.ResultSet;
@@ -26,10 +26,9 @@
2626

2727
public class App {
2828
private static String getUniqueFilename(String name) {
29-
String result = FileSystems.getDefault().getPath(name, new String[0]).toFile().exists()
29+
return FileSystems.getDefault().getPath(name).toFile().exists()
3030
? System.currentTimeMillis() + "_" + name
3131
: name;
32-
return result;
3332
}
3433

3534
private static ArrayList<HashMap<String, Object>> getData(String folder, String separator, String extension,
@@ -39,7 +38,7 @@ private static ArrayList<HashMap<String, Object>> getData(String folder, String
3938
Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + folder + "?separator=" + separator
4039
+ "&fileExtension=" + extension + "&charset=" + charset);
4140

42-
Statement stmt = conn.createStatement(1005, 1007);
41+
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
4342
ResultSet results = stmt.executeQuery(query);
4443
while (results.next()) {
4544
int columns = results.getMetaData().getColumnCount();
@@ -53,16 +52,15 @@ private static ArrayList<HashMap<String, Object>> getData(String folder, String
5352
}
5453

5554
public static void main(String[] args) throws ClassNotFoundException, SQLException,
56-
freemarker.template.TemplateNotFoundException, MalformedTemplateNameException,
57-
freemarker.core.ParseException, java.io.IOException, freemarker.template.TemplateException {
55+
java.io.IOException, freemarker.template.TemplateException {
5856
System.out.println("·------------------------------------------·");
5957
System.out.println("| ___ ______ |");
6058
System.out.println("| ___________ _|__ \\ ____ ____/ / __/ |");
6159
System.out.println("| / ___/ ___/ | / /_/ // __ \\/ __ / /_ |");
6260
System.out.println("| / /__(__ )| |/ / __// /_/ / /_/ / __/ |");
6361
System.out.println("| \\___/____/ |___/____/ .___/\\__,_/_/ |");
6462
System.out.println("| /_/ |");
65-
System.out.println("| v.1.0.2 |");
63+
System.out.println("| v.1.0.3 |");
6664
System.out.println("·------------------------------------------·");
6765

6866
Options options = new Options();
@@ -133,7 +131,7 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
133131
String ftlFile = cmd.getOptionValue("ftl_file");
134132
String ftlEncoding = cmd.getOptionValue("ftl_encoding", "UTF-8");
135133
Configuration cfg = new Configuration(Configuration.VERSION_2_3_30);
136-
cfg.setDirectoryForTemplateLoading(FileSystems.getDefault().getPath(".", new String[0]).toFile());
134+
cfg.setDirectoryForTemplateLoading(FileSystems.getDefault().getPath(".").toFile());
137135
cfg.setDefaultEncoding(ftlEncoding);
138136
Template template = cfg.getTemplate(ftlFile);
139137
ITextRenderer renderer = cmd.hasOption("pdf") ? new ITextRenderer() : null;
@@ -146,16 +144,16 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
146144
getUniqueFilename(StringSubstitutor.replace(cmd.getOptionValue("pdf"), row)):
147145
getUniqueFilename(StringSubstitutor.replace(cmd.getOptionValue("txt"), row));
148146
System.out.print("[+] Generating file: " + fileName);
149-
OutputStream outputStream = new FileOutputStream(fileName);
150-
if (renderer==null)
147+
OutputStream outputStream = Files.newOutputStream(Paths.get(fileName));
148+
if (renderer==null)
151149
outputStream.write(sw.toString().getBytes(cmd.getOptionValue("txt_charset", "UTF-8")));
152150
else {
153151
Document doc = Jsoup.parse(sw.toString());
154152
doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).prettyPrint(false);
155153
renderer.setDocumentFromString(doc.html());
156154
renderer.layout();
157155
renderer.createPDF(outputStream);
158-
}
156+
}
159157
outputStream.close();
160158
System.out.println(" OK");
161159
}
@@ -165,11 +163,11 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
165163
model.put("rows", rows);
166164
StringWriter sw = new StringWriter();
167165
template.process(model, sw);
168-
String fileName = (renderer != null)?
166+
String fileName = (renderer != null)?
169167
getUniqueFilename(cmd.getOptionValue("pdf")):
170168
getUniqueFilename(cmd.getOptionValue("txt"));
171169
System.out.print("[+] Generating file: " + fileName);
172-
OutputStream outputStream = new FileOutputStream(fileName);
170+
OutputStream outputStream = Files.newOutputStream(Paths.get(fileName));
173171
if (renderer==null)
174172
outputStream.write(sw.toString().getBytes(cmd.getOptionValue("txt_charset", "UTF-8")));
175173
else {
@@ -178,7 +176,7 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
178176
renderer.setDocumentFromString(doc.html());
179177
renderer.layout();
180178
renderer.createPDF(outputStream);
181-
}
179+
}
182180
outputStream.close();
183181
System.out.println(" OK");
184182
}

0 commit comments

Comments
 (0)