diff --git a/src/main/java/net/sourceforge/plantuml/servlet/Base64Servlet.java b/src/main/java/net/sourceforge/plantuml/servlet/Base64Servlet.java
new file mode 100644
index 0000000..fcb191f
--- /dev/null
+++ b/src/main/java/net/sourceforge/plantuml/servlet/Base64Servlet.java
@@ -0,0 +1,40 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * PlantUML is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PlantUML distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+package net.sourceforge.plantuml.servlet;
+
+import net.sourceforge.plantuml.FileFormat;
+
+/*
+ * Base64 servlet of the webapp.
+ * This servlet produces the UML diagram in Base64 format.
+ */
+@SuppressWarnings("serial")
+public class Base64Servlet extends UmlDiagramService {
+
+ @Override
+ public FileFormat getOutputFormat() {
+ return FileFormat.BASE64;
+ }
+
+}
diff --git a/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java
index cafe2b4..6f19de1 100644
--- a/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java
+++ b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java
@@ -25,6 +25,7 @@ package net.sourceforge.plantuml.servlet;
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.ByteArrayOutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +39,7 @@ import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.NullOutputStream;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.StringUtils;
+import net.sourceforge.plantuml.code.Base64Coder;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.ImageData;
@@ -64,6 +66,7 @@ class DiagramResponse {
map.put(FileFormat.SVG, "image/svg+xml");
map.put(FileFormat.EPS, "application/postscript");
map.put(FileFormat.UTXT, "text/plain;charset=UTF-8");
+ map.put(FileFormat.BASE64, "text/plain; charset=x-user-defined");
CONTENT_TYPE = Collections.unmodifiableMap(map);
}
@@ -76,6 +79,15 @@ class DiagramResponse {
void sendDiagram(String uml, int idx) throws IOException {
response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
+ if (format == FileFormat.BASE64) {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final DiagramDescription result = reader.outputImage(baos, idx, new FileFormatOption(FileFormat.PNG));
+ baos.close();
+ final String encodedBytes = "data:image/png;base64,"
+ + Base64Coder.encodeLines(baos.toByteArray()).replaceAll("\\s", "");
+ response.getOutputStream().write(encodedBytes.getBytes());
+ return;
+ }
final BlockUml blockUml = reader.getBlocks().get(0);
if (notModified(blockUml)) {
addHeaderForCache(blockUml);
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 6b0db38..a926a74 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -31,6 +31,10 @@
epstextservlet
net.sourceforge.plantuml.servlet.EpsTextServlet
+
+ base64servlet
+ net.sourceforge.plantuml.servlet.Base64Servlet
+
asciiservlet
net.sourceforge.plantuml.servlet.AsciiServlet
@@ -84,6 +88,10 @@
epstextservlet
/epstext/*
+
+ base64servlet
+ /base64/*
+
asciiservlet
/txt/*