| | |
| | | */ |
| | | package de.uhilger.httpserver.adoc; |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.httpserver.base.HttpResponder; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | |
| | | public static final String HTML = "html"; |
| | | public static final String PDF = "pdf"; |
| | | |
| | | public void handle(HttpExchange e, String fileBase, String fileName) throws IOException { |
| | | File adocfile = new File(fileBase, fileName); |
| | | logger.fine("adocfile: " + adocfile.getAbsolutePath()); |
| | | AdocActor actor = new AdocActor(); |
| | | File outfile = actor.getTargetFile(adocfile, AdocActor.HTML); |
| | | logger.fine("outfile: " + outfile.getAbsolutePath()); |
| | | HttpResponder fs = new HttpResponder(); |
| | | fs.serveFile(e, outfile); |
| | | } |
| | | |
| | | public File getTargetFile(File adocfile, String ext) { |
| | | String nameext = adocfile.getName(); |
| | | String fname = nameext.substring(0, nameext.lastIndexOf(DOT)); |
| | |
| | | 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()); |
| | | //response.setCharacterEncoding("UTF-8"); |
| | | File outfile = getTargetFile(adocfile, HTML); |
| | | File htmlfile = outfile; |
| | | |
| | |
| | | die HTML-Datei noch nicht existiert |
| | | */ |
| | | if(!htmlfile.exists() || adocfile.lastModified() > htmlfile.lastModified()) { |
| | | logger.fine("calling transform for " + absname); |
| | | transform(absname); |
| | | } |
| | | |
| | |
| | | //response.setContentType("application/pdf"); |
| | | transform(absname, PDF); |
| | | } |
| | | //ServletOutputStream os = response.getOutputStream(); |
| | | //InputStream bytes = new FileInputStream(outfile); |
| | | //int b = bytes.read(); |
| | | //while(b > -1 ) { |
| | | // os.write(b); |
| | | // b = bytes.read(); |
| | | //} |
| | | } else { |
| | | //PrintWriter out = response.getWriter(); |
| | | //InputStreamReader in = new InputStreamReader(new FileInputStream(outfile), "UTF-8"); |
| | | //in.transferTo(out); |
| | | } |
| | | } |
| | | |
| | |
| | | * nach PDF transformiert werden soll |
| | | */ |
| | | private void transform(String fileName, String backend) { |
| | | logger.fine("fileName: " + fileName + ", backend: " + backend); |
| | | Map<String, Object> attributes; |
| | | File outFile = new File(fileName); |
| | | String thisDirName = outFile.getParent(); |
| | |
| | | .attributes(attributes).asMap(); |
| | | } |
| | | |
| | | File adcf = new File(fileName); |
| | | logger.fine("before asciidoctor create, adcf: " + adcf.getAbsolutePath()); |
| | | Asciidoctor asciidoctor = create(); |
| | | logger.fine("asciidoctor created."); |
| | | asciidoctor.requireLibrary("asciidoctor-diagram"); |
| | | asciidoctor.convertFile(new File(fileName), options); |
| | | logger.fine("asciidoctor requireLibrary diagram passed."); |
| | | logger.fine("calling asciidoctor.convert for file " + adcf.getAbsolutePath()); |
| | | asciidoctor.convertFile(adcf, options); |
| | | } |
| | | |
| | | } |