From cf173715c28c6ac820df44009dd5bc3222af46fb Mon Sep 17 00:00:00 2001 From: ulrich Date: Sun, 10 Nov 2024 16:14:57 +0000 Subject: [PATCH] an AsciidoctorJ Version 3 angepasst --- src/de/uhilger/neon/adoc/AdocFilter.java | 36 ++++++++++++++++++++---------------- 1 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/de/uhilger/neon/adoc/AdocFilter.java b/src/de/uhilger/neon/adoc/AdocFilter.java index 3d0bb4a..f02a607 100644 --- a/src/de/uhilger/neon/adoc/AdocFilter.java +++ b/src/de/uhilger/neon/adoc/AdocFilter.java @@ -18,10 +18,13 @@ package de.uhilger.neon.adoc; import com.sun.net.httpserver.Filter; +import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpExchange; import de.uhilger.neon.FileServer; +import de.uhilger.neon.HttpHelper; import java.io.File; import java.io.IOException; +import java.net.URI; /** * AdocFilter prueft, ob fuer eine Asciidoctor-Quelldatei bereits eine HTML-Version vorliegt. Wenn @@ -34,24 +37,25 @@ @Override public void doFilter(HttpExchange exchange, Chain chain) throws IOException { - String fileBase = exchange.getHttpContext().getAttributes() - .get(FileServer.ATTR_FILE_BASE).toString(); - String fileName = exchange - .getRequestURI() - .getPath() - .substring(exchange - .getHttpContext() - .getPath() - .length()); - if(fileName.endsWith(".adoc")) { - String query = exchange.getRequestURI().getQuery(); - if (query instanceof String && query.contains("pdf=true")) { - processAdocFile(new File(fileBase, fileName), true); - } else { - processAdocFile(new File(fileBase, fileName), false); + URI uri = exchange.getRequestURI(); + try { + String fileName = new HttpHelper().getFileName(exchange); + if(fileName.endsWith(".adoc")) { + HttpContext ctx = exchange.getHttpContext(); + String fileBase = ctx.getAttributes().get(FileServer.ATTR_FILE_BASE).toString(); + String query = uri.getQuery(); + if (query instanceof String && query.contains("pdf=true")) { + processAdocFile(new File(fileBase, fileName), true); + } else { + processAdocFile(new File(fileBase, fileName), false); + } } + } catch (IllegalArgumentException ex) { + // ungueltiger Dateiname, keine Transformation noetig, also tue nichts + } finally { + chain.doFilter(exchange); } - chain.doFilter(exchange); + } /** -- Gitblit v1.9.3