| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | import static org.asciidoctor.Asciidoctor.Factory.create; |
| | | import org.asciidoctor.Asciidoctor; |
| | |
| | | */ |
| | | public class AdocActor { |
| | | |
| | | private static final Logger logger = Logger.getLogger(AdocActor.class.getName()); |
| | | |
| | | private static final String DOT = "."; |
| | | public static final String HTML = "html"; |
| | | public static final String PDF = "pdf"; |
| | | |
| | | public void handle(HttpExchange e, String fileBase, String fileName, boolean pdf) throws IOException { |
| | | File adocfile = new File(fileBase, fileName); |
| | | logger.fine("adocfile: " + adocfile.getAbsolutePath()); |
| | | //logger.fine("adocfile: " + adocfile.getAbsolutePath()); |
| | | AdocActor actor = new AdocActor(); |
| | | File outfile; |
| | | if(pdf) { |
| | |
| | | } else { |
| | | outfile = actor.getTargetFile(adocfile, AdocActor.HTML); |
| | | } |
| | | logger.fine("outfile: " + outfile.getAbsolutePath()); |
| | | //logger.fine("outfile: " + outfile.getAbsolutePath()); |
| | | HttpResponder fs = new HttpResponder(); |
| | | fs.serveFile(e, outfile); |
| | | } |
| | |
| | | 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()); |
| | | //logger.log(Level.FINE, "out: {0}", outfile.getAbsolutePath()); |
| | | return outfile; |
| | | } |
| | | |
| | | public void processAdocFile(File adocfile, String pdf) { |
| | | |
| | | String absname = adocfile.getAbsolutePath(); |
| | | logger.log(Level.FINE, "in: {0}", absname); |
| | | //logger.log(Level.FINE, "in: {0}", absname); |
| | | |
| | | // HTML-Datei ermitteln |
| | | File outfile = getTargetFile(adocfile, HTML); |
| | |
| | | die HTML-Datei noch nicht existiert |
| | | */ |
| | | if(!htmlfile.exists() || adocfile.lastModified() > htmlfile.lastModified()) { |
| | | logger.fine("calling transform for " + absname); |
| | | //logger.fine("calling transform for " + absname); |
| | | transform(absname); |
| | | } |
| | | |
| | |
| | | * nach PDF transformiert werden soll |
| | | */ |
| | | private void transform(String fileName, String backend) { |
| | | logger.fine("fileName: " + fileName + ", backend: " + backend); |
| | | //logger.fine("fileName: " + fileName + ", backend: " + backend); |
| | | Map<String, Object> attributes; |
| | | File outFile = new File(fileName); |
| | | String thisDirName = outFile.getParent(); |
| | |
| | | } |
| | | |
| | | File adcf = new File(fileName); |
| | | logger.fine("before asciidoctor create, adcf: " + adcf.getAbsolutePath()); |
| | | //logger.fine("before asciidoctor create, adcf: " + adcf.getAbsolutePath()); |
| | | Asciidoctor asciidoctor = create(); |
| | | logger.fine("asciidoctor created."); |
| | | //logger.fine("asciidoctor created."); |
| | | asciidoctor.requireLibrary("asciidoctor-diagram"); |
| | | logger.fine("asciidoctor requireLibrary diagram passed."); |
| | | logger.fine("calling asciidoctor.convert for file " + adcf.getAbsolutePath()); |
| | | //logger.fine("asciidoctor requireLibrary diagram passed."); |
| | | //logger.fine("calling asciidoctor.convert for file " + adcf.getAbsolutePath()); |
| | | asciidoctor.convertFile(adcf, options); |
| | | } |
| | | |