Asciidoctor mit Neon transformieren
ulrich
2021-06-20 5ca8131e61226dda11d3ff81e12f9fbd39b99a1a
Package testbereit
3 files modified
53 ■■■■ changed files
src/de/uhilger/httpserver/adoc/AdocActor.java 29 ●●●●● patch | view | raw | blame | history
src/de/uhilger/httpserver/adoc/AdocFilter.java 3 ●●●● patch | view | raw | blame | history
src/de/uhilger/httpserver/adoc/AdocHandler.java 21 ●●●● patch | view | raw | blame | history
src/de/uhilger/httpserver/adoc/AdocActor.java
@@ -19,6 +19,7 @@
import java.io.File;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.asciidoctor.Asciidoctor.Factory.create;
@@ -42,22 +43,31 @@
  private static final Logger logger = Logger.getLogger(AdocActor.class.getName());
  
  private static final String DOT = ".";
  private static final String HTML = "html";
  private static final String PDF = "pdf";
  public static final String HTML = "html";
  public static final String PDF = "pdf";
  
  public File getTargetFile(File adocfile, String ext) {
    String nameext = adocfile.getName();
    String fname = nameext.substring(0, nameext.lastIndexOf(DOT));
    File outfile = new File(adocfile.getParentFile(), fname + DOT + ext);
    logger.log(Level.FINE, "out: {0}", outfile.getAbsolutePath());
    return outfile;
  }
  
  public void processAdocFile(File adocfile, String pdf) {
    
    String absname = adocfile.getAbsolutePath();
    logger.fine("in: " + absname);
    logger.log(Level.FINE, "in: {0}", absname);
 
    // HTML-Datei ermitteln
    String nameext = adocfile.getName();
    String fname = nameext.substring(0, nameext.lastIndexOf(DOT));
    File htmlfile = new File(adocfile.getParentFile(), fname + DOT + HTML);
    File outfile = htmlfile; // Standardmaessig wird HTML zurueckgegeben
    logger.fine("out: " + outfile.getAbsolutePath());
    //String nameext = adocfile.getName();
    //String fname = nameext.substring(0, nameext.lastIndexOf(DOT));
    //File htmlfile = new File(adocfile.getParentFile(), fname + DOT + HTML);
    //File outfile = htmlfile; // Standardmaessig wird HTML zurueckgegeben
    //logger.fine("out: " + outfile.getAbsolutePath());
    //response.setCharacterEncoding("UTF-8");
    File outfile = getTargetFile(adocfile, HTML);
    File htmlfile = outfile;
    
    /*
      nach HTML transformieren, wenn die Quelle sich geandert hat oder 
@@ -74,7 +84,8 @@
    */
    
    if(null != pdf && pdf.equalsIgnoreCase(Boolean.TRUE.toString())) {
      File pdffile = new File(adocfile.getParentFile(), fname + DOT + PDF);
      //File pdffile = new File(adocfile.getParentFile(), fname + DOT + PDF);
      File pdffile = getTargetFile(adocfile, PDF);
      outfile = pdffile; // PDF soll zurueckgegeben werden
      if(!pdffile.exists() || adocfile.lastModified() > pdffile.lastModified()) {
        //response.setContentType("application/pdf");
src/de/uhilger/httpserver/adoc/AdocFilter.java
@@ -58,8 +58,7 @@
        AdocActor actor = new AdocActor();
        actor.processAdocFile(new File(fileBase, adocHandler.getFileName(exchange)), Boolean.FALSE.toString());
      }
    }
    }
    chain.doFilter(exchange);
  }
src/de/uhilger/httpserver/adoc/AdocHandler.java
@@ -18,8 +18,11 @@
package de.uhilger.httpserver.adoc;
import com.sun.net.httpserver.HttpExchange;
import de.uhilger.httpserver.base.HttpResponder;
import de.uhilger.httpserver.base.handler.FileHandler;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.logging.Logger;
/**
@@ -43,9 +46,21 @@
  @Override
  public void handle(HttpExchange e) throws IOException {
    logger.fine(e.getRequestURI().toString());
    // hier ggf. noch etwas eigenes machen...
    super.handle(e); // zu FileHandler delegieren
    URI uri = e.getRequestURI();
    logger.fine(uri.toString());
    String query = uri.getQuery();
    //String[] params = query.split("?&"); // hier noch Regex ermitteln
    String requestPathStr = uri.getPath();
    //logger.fine("filter: " + requestUriStr);
    if(requestPathStr.toLowerCase().endsWith(AdocFilter.ADOC)) {
      File adocfile = new File(fileBase, getFileName(e));
      AdocActor actor = new AdocActor();
      File outfile = actor.getTargetFile(adocfile, AdocActor.HTML);
      HttpResponder fs = new HttpResponder();
      fs.serveFile(e, outfile);
    } else {
      super.handle(e); // andere Inhalte zu FileHandler delegieren
    }
  }
  
  public String getFileBase() {