From 38929aa1f4f4a017be4d2e93c32165b9e51f635d Mon Sep 17 00:00:00 2001
From: ulrich
Date: Tue, 21 Jul 2020 13:21:17 +0000
Subject: [PATCH] In Arbeit: PDF Theme

---
 src/de/uhilger/wbx/web/AdocServlet.java |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/de/uhilger/wbx/web/AdocServlet.java b/src/de/uhilger/wbx/web/AdocServlet.java
index 68a0eaa..2b55c81 100644
--- a/src/de/uhilger/wbx/web/AdocServlet.java
+++ b/src/de/uhilger/wbx/web/AdocServlet.java
@@ -33,6 +33,8 @@
 
 import static org.asciidoctor.Asciidoctor.Factory.create;
 import org.asciidoctor.Asciidoctor;
+import static org.asciidoctor.AttributesBuilder.attributes;
+import static org.asciidoctor.OptionsBuilder.options;
 
 
 
@@ -72,8 +74,8 @@
     String fname = nameext.substring(0, nameext.lastIndexOf(DOT));
     File htmlfile = new File(adocfile.getParentFile(), fname + DOT + HTML);
     File outfile = htmlfile; // Standardmaessig wird HTML zurueckgegeben
-    response.setContentType("text/html;charset=UTF-8");
-
+    response.setCharacterEncoding("UTF-8");
+    
     /*
       nach HTML transformieren, wenn die Quelle sich geandert hat oder 
       die HTML-Datei noch nicht existiert
@@ -91,7 +93,6 @@
     if(null != pdf && pdf.equalsIgnoreCase(Boolean.TRUE.toString())) {
       File pdffile = new File(adocfile.getParentFile(), fname + DOT + PDF);
       outfile = pdffile; // PDF soll zurueckgegeben werden
-      response.setContentType("application/pdf;charset=UTF-8");
       if(!pdffile.exists() || adocfile.lastModified() > pdffile.lastModified()) {
         transform(absname, PDF);
       }
@@ -100,7 +101,7 @@
     try (PrintWriter out = response.getWriter()) {
       // abhaengig vom Parameter pdf HTML- oder PDF-Datei ausgeben
       FileInputStream in = new FileInputStream(outfile);
-      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+      BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
       String line;
       while ((line = reader.readLine()) != null) {
         out.println(line);
@@ -124,18 +125,21 @@
    * nach PDF transformiert werden soll
    */
   private void transform(String fileName, String backend) {    
-    Map<String, Object> attributes = new HashMap<>();
-    attributes.put("no_footer", false);
-    attributes.put("source_highlighter", "highlightjs");
-
-    Map<String, Object> options = new HashMap<>();
-    options.put("attributes", attributes); 
-    options.put("in_place", false); 
+    File outFile = new File(fileName);
+    Map<String, Object> attributes = attributes().attribute("pdf-themesdir", outFile.getParent()).attribute("pdf-theme","test").sourceHighlighter("highlightjs")
+                                       .asMap();
+    Map<String, Object> options;
     if(null != backend) {
-      options.put("backend", backend);
+      options = options().inPlace(false)
+              .backend(backend).attributes(attributes).asMap();
+      
+    } else {
+      options = options().inPlace(false)
+              .attributes(attributes).asMap();
     }
     
     Asciidoctor asciidoctor = create();    
+    asciidoctor.requireLibrary("asciidoctor-diagram");
     asciidoctor.convertFile(new File(fileName), options);    
   }
 

--
Gitblit v1.9.3