aboutsummaryrefslogtreecommitdiff
path: root/markdown-plugin
diff options
context:
space:
mode:
authorritchie <ritchie@gmx.at>2015-05-14 09:02:50 +0200
committerritchie <ritchie@gmx.at>2015-05-14 09:02:50 +0200
commit5e2e2f19e06b9f4a01c6da83a2297eb18fe2b546 (patch)
treeebf8b2e1d2cd0516de354b3f417ac79f905278dc /markdown-plugin
parent6a77bee0dad6e34e9789b5065c4367286f619efd (diff)
downloadnanohttpd-5e2e2f19e06b9f4a01c6da83a2297eb18fe2b546.tar.gz
reponces now created by factorymethods that can be overwritten, solves
#94
Diffstat (limited to 'markdown-plugin')
-rw-r--r--markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPlugin.java19
-rw-r--r--markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPluginInfo.java8
2 files changed, 18 insertions, 9 deletions
diff --git a/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPlugin.java b/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPlugin.java
index 43d081c..24bc08a 100644
--- a/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPlugin.java
+++ b/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPlugin.java
@@ -8,18 +8,18 @@ package fi.iki.elonen;
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. Neither the name of the nanohttpd nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -36,9 +36,11 @@ package fi.iki.elonen;
import static fi.iki.elonen.NanoHTTPD.Response.Status.OK;
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -107,6 +109,13 @@ public class MarkdownWebServerPlugin implements WebServerPlugin {
@Override
public NanoHTTPD.Response serveFile(String uri, Map<String, String> headers, NanoHTTPD.IHTTPSession session, File file, String mimeType) {
String markdownSource = readSource(file);
- return markdownSource == null ? null : new NanoHTTPD.Response(OK, NanoHTTPD.MIME_HTML, this.processor.markdownToHtml(markdownSource));
+ byte[] bytes;
+ try {
+ bytes = this.processor.markdownToHtml(markdownSource).getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ MarkdownWebServerPlugin.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
+ bytes = new byte[0];
+ }
+ return markdownSource == null ? null : new NanoHTTPD.Response(OK, NanoHTTPD.MIME_HTML, new ByteArrayInputStream(bytes), bytes.length);
}
}
diff --git a/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPluginInfo.java b/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPluginInfo.java
index 29cdc1e..66c2f19 100644
--- a/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPluginInfo.java
+++ b/markdown-plugin/src/main/java/fi/iki/elonen/MarkdownWebServerPluginInfo.java
@@ -8,18 +8,18 @@ package fi.iki.elonen;
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. Neither the name of the nanohttpd nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.