Skip to content

Commit

Permalink
Templater v7.0.0
Browse files Browse the repository at this point in the history
Java API renames (remove I prefix from interfaces)
  • Loading branch information
zapov committed Apr 19, 2022
1 parent c1d193c commit 2b65f3b
Show file tree
Hide file tree
Showing 194 changed files with 362 additions and 363 deletions.
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/CsvStreaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.13.0" targetFramework="net40-Client" />
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>csv-streaming-example</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>CSV streaming</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hr.ngs.templater.example;

import hr.ngs.templater.Configuration;
import hr.ngs.templater.IDocumentFactoryBuilder;
import hr.ngs.templater.ITemplateDocument;
import hr.ngs.templater.DocumentFactoryBuilder;
import hr.ngs.templater.TemplateDocument;

import java.awt.Desktop;
import java.io.*;
Expand All @@ -18,7 +18,7 @@

public class CsvStreamingExample {

static class Quoter implements IDocumentFactoryBuilder.LowLevelReplacer {
static class Quoter implements DocumentFactoryBuilder.LowLevelReplacer {

@Override
public Object replace(Object value, String tag, String[] metadata) {
Expand All @@ -32,7 +32,7 @@ public Object replace(Object value, String tag, String[] metadata) {
return value;
}
}
static class NumberAsComma implements IDocumentFactoryBuilder.LowLevelReplacer {
static class NumberAsComma implements DocumentFactoryBuilder.LowLevelReplacer {

@Override
public Object replace(Object value, String tag, String[] metadata) {
Expand Down Expand Up @@ -115,7 +115,7 @@ public static void main(final String[] args) throws Exception {
ins.execute();
}
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM csv_data");
IDocumentFactoryBuilder config = Configuration.builder().include(new Quoter());
DocumentFactoryBuilder config = Configuration.builder().include(new Quoter());
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.getDefault());
//if we are using a culture which has comma as decimal separator, change the output to dot
//we could apply this always, but it adds a bit of overhead, so let's apply it conditionally
Expand All @@ -125,7 +125,7 @@ public static void main(final String[] args) throws Exception {
//we can stream directly into a zipped stream/file
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmp));
zos.putNextEntry(new ZipEntry("output.csv"));
ITemplateDocument doc = config.build().open(templateStream, "csv", zos);
TemplateDocument doc = config.build().open(templateStream, "csv", zos);
//streaming processing assumes we have only a single collection, which means we first need to process all other tags
doc.process(new Object() { public Object filter = new Object() { public String date = "All"; public String user = "All"; }; });
//to do a streaming processing we need to process collection in chunks
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/DepartmentReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
</Reference>
<Reference Include="NReco.LambdaParser">
<HintPath>..\..\packages\NReco.LambdaParser.1.0.10\lib\portable-net40+sl5+win8+wp8+wpa81\NReco.LambdaParser.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
<package id="NReco.LambdaParser" version="1.0.10" targetFramework="net40" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>department-report-example</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>DepartmentReportExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hr.ngs.templater.example;

import hr.ngs.templater.Configuration;
import hr.ngs.templater.IDocumentFactoryBuilder;
import hr.ngs.templater.ITemplateDocument;
import hr.ngs.templater.DocumentFactoryBuilder;
import hr.ngs.templater.TemplateDocument;

import javax.script.*;
import java.awt.Desktop;
Expand Down Expand Up @@ -89,7 +89,7 @@ public static void main(final String[] args) throws Exception {

Company company = getCompany();
FileOutputStream fos = new FileOutputStream(tmp);
ITemplateDocument tpl = Configuration
TemplateDocument tpl = Configuration
.builder()
.withMatcher("[\\w\\s \\.,:?!+\\*-<>=()]+")
.navigateSeparator(':', null)
Expand Down Expand Up @@ -119,7 +119,7 @@ public static void main(final String[] args) throws Exception {

//this is just a simplistic implementation
//a better implementation would take care of methods, dictionaries and various other types
static class SortExpression implements IDocumentFactoryBuilder.Navigate {
static class SortExpression implements DocumentFactoryBuilder.Navigate {
@Override
public Object navigate(Object parent, Object value, String member, String metadata) {
if (!metadata.startsWith("sort(") || value instanceof Object[] == false) return value;
Expand Down Expand Up @@ -149,9 +149,10 @@ public Object navigate(Object parent, Object value, String member, String metada
}
}

//Java 15 removed the support for Javascript, in which case explicit dependency needs to be taken: https://github.com/openjdk/nashorn
private static final ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");

static class FilterExpression implements IDocumentFactoryBuilder.Navigate {
static class FilterExpression implements DocumentFactoryBuilder.Navigate {
@Override
public Object navigate(Object parent, Object value, String member, String metadata) {
if (!metadata.startsWith("filter(") || value instanceof List == false) return value;
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/DoubleProcessing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>double-processing-example</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>DoubleProcessingExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.mockrunner.mock.jdbc.MockResultSet;
import hr.ngs.templater.Configuration;
import hr.ngs.templater.IDocumentFactory;
import hr.ngs.templater.ITemplateDocument;
import hr.ngs.templater.DocumentFactory;
import hr.ngs.templater.TemplateDocument;

import java.awt.Desktop;
import java.io.*;
Expand All @@ -27,10 +27,10 @@ public static void main(final String[] args) throws Exception {

ResultSet units = prepareStarcraftUnits();

IDocumentFactory factory = Configuration.factory();
DocumentFactory factory = Configuration.factory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
//let's do a horizontal resize so document is prepared for second pass
ITemplateDocument doc1 = factory.open(templateStream, "xlsx", os);
TemplateDocument doc1 = factory.open(templateStream, "xlsx", os);
//[[equals]] at the beginning of the cell causes conversion to formula
//this is processed at the end of processing, but since this tag is newly introduced, it's processed at the second pass
doc1.process(new HashMap<String, Object>() {{ put("Person", person); put("formula", "[[equals]]"); }});
Expand Down Expand Up @@ -61,7 +61,7 @@ public static void main(final String[] args) throws Exception {
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
FileOutputStream fos = new FileOutputStream(tmp);
//let's do a second pass with our prepared object
ITemplateDocument doc2 = factory.open(is, "xlsx", fos);
TemplateDocument doc2 = factory.open(is, "xlsx", fos);
doc2.process(complex);
doc2.process(new HashMap<String, Object>() {{ put("starcraft", units); }});
doc2.close();
Expand Down
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/PowerQuery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>power-query-example</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>PowerQueryExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class PowerQueryExample {

private static IDocumentFactory factory = Configuration.builder()
private static DocumentFactory factory = Configuration.builder()
//Excel will complain about corrupted file unless Templater is initialized with a valid license
.build("Customer email", "Customer license");

Expand Down Expand Up @@ -103,9 +103,9 @@ public static void main(final String[] args) throws Exception {
data.csv = generateData(100_000);
data.sheet = generateData(50_000);

try(InputStream is = PowerQueryExample.class.getResourceAsStream("/PowerQuery.xlsx");
OutputStream os = Files.newOutputStream(tmp.toPath());
ITemplateDocument tpl = factory.open(is, "xlsx", os)) {
try (InputStream is = PowerQueryExample.class.getResourceAsStream("/PowerQuery.xlsx");
OutputStream os = Files.newOutputStream(tmp.toPath());
TemplateDocument tpl = factory.open(is, "xlsx", os)) {
tpl.process(data);
}

Expand Down
2 changes: 1 addition & 1 deletion Advanced/SalesOrderMVP (.NET)/SalesOrderMVP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/SalesOrderMVP (.NET)/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fluent.Ribbon" version="3.6.1.236" targetFramework="net40-Client" />
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/SheetReport/SheetReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/SheetReport/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SharpZipLib" version="0.86.0" targetFramework="net40-Client" />
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/SheetReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>sheet-report-example</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>SheetReportExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hr.ngs.templater.example;

import hr.ngs.templater.Configuration;
import hr.ngs.templater.ITemplateDocument;
import hr.ngs.templater.TemplateDocument;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand All @@ -17,19 +17,16 @@
public class SheetReportExample {

public static void main(final String[] args) throws Exception {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
InputStream templateStream = SheetReportExample.class.getResourceAsStream("/Report.xlsx");
File tmp = File.createTempFile("table", ".xlsx");

FileOutputStream fos = new FileOutputStream(tmp);
ITemplateDocument tpl = Configuration.factory().open(templateStream, "xlsx", fos);

InputData data = loadXml(dbFactory);

tpl.process(data);

tpl.close();
fos.close();
try (FileOutputStream fos = new FileOutputStream(tmp);
TemplateDocument tpl = Configuration.factory().open(templateStream, "xlsx", fos)) {
tpl.process(data);
}
Desktop.getDesktop().open(tmp);
}

Expand Down
2 changes: 1 addition & 1 deletion Advanced/TemplaterServer/TemplaterServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Templater" Version="6.2.0" />
<PackageReference Include="Templater" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Advanced/TemplaterServer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>templater-server</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>TemplaterServer</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ static class TemplateInfo {
}

private final int timeoutLimit;
private final IDocumentFactory documentFactory;
private final IDocumentFactory debugFactory;
private final IDocumentFactory schemaFactory;
private final DocumentFactory documentFactory;
private final DocumentFactory debugFactory;
private final DocumentFactory schemaFactory;
private final Logger logger;
private final HttpServer server;
private final Map<String, PdfConverter> pdfConverters;
Expand Down Expand Up @@ -271,8 +271,8 @@ private byte[] processTemplate(final byte[] templateBytes, final Object data, fi
final InputStream is = new ByteArrayInputStream(templateBytes);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//we can process template regularly or just to embed schema inside
IDocumentFactory factory = asSchema ? schemaFactory : debugLog ? debugFactory : documentFactory;
IDocumentFactory.CancellationToken cancellationToken = new IDocumentFactory.CancellationToken() {
DocumentFactory factory = asSchema ? schemaFactory : debugLog ? debugFactory : documentFactory;
DocumentFactory.CancellationToken cancellationToken = new DocumentFactory.CancellationToken() {
private final long runUntil = System.currentTimeMillis() + timeoutLimit * 1000L;

@Override
Expand All @@ -282,7 +282,7 @@ public boolean isCanceled() {
return timeoutLimit > 0 && System.currentTimeMillis() > runUntil;
}
};
try (ITemplateDocument doc = factory.open(is, ext, baos, cancellationToken)) {
try (TemplateDocument doc = factory.open(is, ext, baos, cancellationToken)) {
doc.process(data);
}
status = "success";
Expand Down
2 changes: 1 addition & 1 deletion Advanced/XmlBinding/XmlBinding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.6.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.7.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/XmlBinding/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="6.2.0" targetFramework="net40-Client" />
<package id="Templater" version="7.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/XmlBinding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>xml-binding-example</artifactId>
<packaging>jar</packaging>
<version>6.2.0</version>
<version>7.0.0</version>
<name>XmlBindingExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Loading

0 comments on commit 2b65f3b

Please sign in to comment.