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 |
|
|
41 |
public AdocHandler(String absoluteDirectoryPathAndName) { |
|
42 |
super(absoluteDirectoryPathAndName); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public void handle(HttpExchange e) throws IOException { |
5ca813
|
47 |
URI uri = e.getRequestURI(); |
U |
48 |
logger.fine(uri.toString()); |
|
49 |
String query = uri.getQuery(); |
|
50 |
//String[] params = query.split("?&"); // hier noch Regex ermitteln |
|
51 |
String requestPathStr = uri.getPath(); |
|
52 |
//logger.fine("filter: " + requestUriStr); |
|
53 |
if(requestPathStr.toLowerCase().endsWith(AdocFilter.ADOC)) { |
f5adf5
|
54 |
AdocActor actor = new AdocActor(); |
U |
55 |
actor.handle(e, fileBase, getFileName(e)); |
|
56 |
/* |
5ca813
|
57 |
File adocfile = new File(fileBase, getFileName(e)); |
4ed0b2
|
58 |
logger.fine("adocfile: " + adocfile.getAbsolutePath()); |
5ca813
|
59 |
AdocActor actor = new AdocActor(); |
U |
60 |
File outfile = actor.getTargetFile(adocfile, AdocActor.HTML); |
4ed0b2
|
61 |
logger.fine("outfile: " + outfile.getAbsolutePath()); |
5ca813
|
62 |
HttpResponder fs = new HttpResponder(); |
U |
63 |
fs.serveFile(e, outfile); |
f5adf5
|
64 |
*/ |
5ca813
|
65 |
} else { |
U |
66 |
super.handle(e); // andere Inhalte zu FileHandler delegieren |
|
67 |
} |
9c5db9
|
68 |
} |
U |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
} |