commit | author | age
|
9c5db9
|
1 |
/* |
U |
2 |
http-adoc - Asciidoctor extensions to jdk.httpserver |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.httpserver.adoc; |
|
19 |
|
|
20 |
import com.sun.net.httpserver.Filter; |
|
21 |
import com.sun.net.httpserver.HttpExchange; |
|
22 |
import com.sun.net.httpserver.HttpHandler; |
|
23 |
import java.io.File; |
|
24 |
import java.io.IOException; |
|
25 |
import java.net.URI; |
|
26 |
import java.util.logging.Logger; |
|
27 |
|
|
28 |
/** |
|
29 |
* AdocFilter prueft, ob fuer eine |
|
30 |
* Asciidoctor-Quelldatei bereits eine HTML-Version vorliegt. Wenn nicht, |
|
31 |
* verwendet der AdocFilter den AdocActor, um eine HTML-Version zu erzeugen. |
|
32 |
* |
|
33 |
* @author Ulrich Hilger |
|
34 |
* @version 1, 16.06.2021 |
|
35 |
*/ |
|
36 |
public class AdocFilter extends Filter { |
|
37 |
|
|
38 |
private static final Logger logger = Logger.getLogger(AdocFilter.class.getName()); |
|
39 |
|
|
40 |
public static final String DESCRIPTION = "Asciidoctor Filter"; |
|
41 |
|
|
42 |
public static final String ADOC = ".adoc"; |
|
43 |
|
|
44 |
@Override |
|
45 |
public void doFilter(HttpExchange exchange, Chain chain) throws IOException { |
|
46 |
URI uri = exchange.getRequestURI(); |
|
47 |
String query = uri.getQuery(); |
|
48 |
//String[] params = query.split("?&"); // hier noch Regex ermitteln |
|
49 |
String requestPathStr = uri.getPath(); |
|
50 |
//logger.fine("filter: " + requestUriStr); |
|
51 |
|
|
52 |
if(requestPathStr.toLowerCase().endsWith(ADOC)) { |
|
53 |
logger.fine("filter: " + requestPathStr); |
|
54 |
HttpHandler handler = exchange.getHttpContext().getHandler(); |
|
55 |
if(handler instanceof AdocHandler) { |
|
56 |
AdocHandler adocHandler = (AdocHandler) handler; |
|
57 |
String fileBase = adocHandler.getFileBase(); |
|
58 |
AdocActor actor = new AdocActor(); |
|
59 |
actor.processAdocFile(new File(fileBase, adocHandler.getFileName(exchange)), Boolean.FALSE.toString()); |
|
60 |
} |
5ca813
|
61 |
} |
9c5db9
|
62 |
chain.doFilter(exchange); |
U |
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public String description() { |
|
67 |
return DESCRIPTION; |
|
68 |
} |
|
69 |
|
|
70 |
} |