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.HttpExchange; |
|
21 |
import de.uhilger.httpserver.base.handler.FileHandler; |
|
22 |
import java.io.IOException; |
5ca813
|
23 |
import java.net.URI; |
9c5db9
|
24 |
import java.util.logging.Logger; |
U |
25 |
|
|
26 |
/** |
|
27 |
* Der AdocHandler verwendet den FileHandler zur Auslieferung statischer |
|
28 |
* Inhalte und einen AdocFilter, um vorab zu pruefen, ob fuer eine |
|
29 |
* Asciidoctor-Quelldatei bereits eine HTML-Version vorliegt. Wenn nicht, |
|
30 |
* verwendet der AdocFilter den AdocActor, um eine HTML-Version zu erzeugen, |
|
31 |
* die dann vom AdocHandler mit Hilfe der Methoden des FileHandler |
|
32 |
* ausgeliefert werden kann. |
|
33 |
* |
|
34 |
* @author Ulrich Hilger |
|
35 |
* @version 1, 16.06.2021 |
|
36 |
*/ |
|
37 |
public class AdocHandler extends FileHandler { |
|
38 |
|
|
39 |
private static final Logger logger = Logger.getLogger(AdocHandler.class.getName()); |
|
40 |
|
90c249
|
41 |
/** |
U |
42 |
* Benoetigt das Attribut |
|
43 |
* FileHandler.ATTR_FILE_BASE |
|
44 |
*/ |
|
45 |
public AdocHandler() { |
|
46 |
//super(absoluteDirectoryPathAndName); |
9c5db9
|
47 |
} |
U |
48 |
|
|
49 |
@Override |
|
50 |
public void handle(HttpExchange e) throws IOException { |
5ca813
|
51 |
URI uri = e.getRequestURI(); |
U |
52 |
logger.fine(uri.toString()); |
|
53 |
String query = uri.getQuery(); |
|
54 |
//String[] params = query.split("?&"); // hier noch Regex ermitteln |
|
55 |
String requestPathStr = uri.getPath(); |
|
56 |
//logger.fine("filter: " + requestUriStr); |
|
57 |
if(requestPathStr.toLowerCase().endsWith(AdocFilter.ADOC)) { |
f5adf5
|
58 |
AdocActor actor = new AdocActor(); |
90c249
|
59 |
actor.handle(e, e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString(), getFileName(e)); |
f5adf5
|
60 |
/* |
5ca813
|
61 |
File adocfile = new File(fileBase, getFileName(e)); |
4ed0b2
|
62 |
logger.fine("adocfile: " + adocfile.getAbsolutePath()); |
5ca813
|
63 |
AdocActor actor = new AdocActor(); |
U |
64 |
File outfile = actor.getTargetFile(adocfile, AdocActor.HTML); |
4ed0b2
|
65 |
logger.fine("outfile: " + outfile.getAbsolutePath()); |
5ca813
|
66 |
HttpResponder fs = new HttpResponder(); |
U |
67 |
fs.serveFile(e, outfile); |
f5adf5
|
68 |
*/ |
5ca813
|
69 |
} else { |
U |
70 |
super.handle(e); // andere Inhalte zu FileHandler delegieren |
|
71 |
} |
9c5db9
|
72 |
} |
U |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
} |