Add support for generating parameterized image format in proxy requests
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* ========================================================================
|
* ========================================================================
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.sourceforge.net
|
* Project Info: http://plantuml.sourceforge.net
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@@ -48,22 +48,23 @@ import HTTPClient.HTTPResponse;
|
|||||||
import HTTPClient.ModuleException;
|
import HTTPClient.ModuleException;
|
||||||
import HTTPClient.ParseException;
|
import HTTPClient.ParseException;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Original idea from Achim Abeling for Confluence macro
|
* Original idea from Achim Abeling for Confluence macro
|
||||||
* See http://www.banapple.de/display/BANAPPLE/plantuml+user+macro
|
* See http://www.banapple.de/display/BANAPPLE/plantuml+user+macro
|
||||||
*
|
*
|
||||||
* Modified by Arnaud Roques
|
* Modified by Arnaud Roques
|
||||||
|
* Modified by Pablo Lalloni
|
||||||
* Packaged by Maxime Sinclair
|
* Packaged by Maxime Sinclair
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class PlantUmlServlet extends HttpServlet {
|
public class PlantUmlServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final Pattern startumlPattern = Pattern.compile("/\\w+/start/(.*)");
|
private static final Pattern startumlPattern = Pattern.compile("/\\w+/start/(.*)");
|
||||||
private static final Pattern proxyPattern = Pattern.compile("/\\w+/proxy/((\\d+)/)?(http://.*)");
|
private static final Pattern proxyPattern = Pattern.compile("/\\w+/proxy/((\\d+)/)?((\\w+)/)?(http://.*)");
|
||||||
private static final Pattern oldStartumlPattern = Pattern.compile("/\\w+/uml/startuml/(.*)");
|
private static final Pattern oldStartumlPattern = Pattern.compile("/\\w+/uml/startuml/(.*)");
|
||||||
private static final Pattern oldImagePattern = Pattern.compile("/\\w+/uml/image/(.*)");
|
private static final Pattern oldImagePattern = Pattern.compile("/\\w+/uml/image/(.*)");
|
||||||
private static final Pattern oldProxyPattern = Pattern.compile("/\\w+/uml/proxy/((\\d+)/)?(http://.*)");
|
private static final Pattern oldProxyPattern = Pattern.compile("/\\w+/uml/proxy/((\\d+)/)?((\\w+)/)?(http://.*)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
@@ -80,8 +81,9 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
handleImage(response, source, uri);
|
handleImage(response, source, uri);
|
||||||
} else if (proxyMatcher.matches()) {
|
} else if (proxyMatcher.matches()) {
|
||||||
String num = proxyMatcher.group(2);
|
String num = proxyMatcher.group(2);
|
||||||
String source = proxyMatcher.group(3);
|
String format = proxyMatcher.group(4);
|
||||||
handleImageProxy(response, num, source, uri);
|
String source = proxyMatcher.group(5);
|
||||||
|
handleImageProxy(response, num, source, format, uri);
|
||||||
} else if (oldStartumlMatcher.matches()) {
|
} else if (oldStartumlMatcher.matches()) {
|
||||||
String source = oldStartumlMatcher.group(1);
|
String source = oldStartumlMatcher.group(1);
|
||||||
handleImage(response, source, uri);
|
handleImage(response, source, uri);
|
||||||
@@ -90,8 +92,9 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
handleImageDecompress(response, source, uri);
|
handleImageDecompress(response, source, uri);
|
||||||
} else if (oldProxyMatcher.matches()) {
|
} else if (oldProxyMatcher.matches()) {
|
||||||
String num = oldProxyMatcher.group(2);
|
String num = oldProxyMatcher.group(2);
|
||||||
String source = oldProxyMatcher.group(3);
|
String format = oldProxyMatcher.group(4);
|
||||||
handleImageProxy(response, num, source, uri);
|
String source = oldProxyMatcher.group(5);
|
||||||
|
handleImageProxy(response, num, source, format, uri);
|
||||||
} else {
|
} else {
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
@@ -109,7 +112,7 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
|
|
||||||
Transcoder transcoder = getTranscoder();
|
Transcoder transcoder = getTranscoder();
|
||||||
// the URL form has been submitted
|
// the URL form has been submitted
|
||||||
if ((url != null) && (!url.trim().isEmpty())) {
|
if (url != null && !url.trim().isEmpty()) {
|
||||||
// TODO Verify the url is correct
|
// TODO Verify the url is correct
|
||||||
Pattern p = Pattern.compile(".*/(.*)");
|
Pattern p = Pattern.compile(".*/(.*)");
|
||||||
Matcher m = p.matcher(url);
|
Matcher m = p.matcher(url);
|
||||||
@@ -119,13 +122,13 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// the Text form has been submitted
|
// the Text form has been submitted
|
||||||
if ((text != null) && (!text.trim().isEmpty())) {
|
if (text != null && !text.trim().isEmpty()) {
|
||||||
encoded = transcoder.encode(text);
|
encoded = transcoder.encode(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", text);
|
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", text);
|
||||||
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", encoded);
|
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", encoded);
|
||||||
|
|
||||||
// forward to index.jsp
|
// forward to index.jsp
|
||||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
||||||
dispatcher.forward(request, response);
|
dispatcher.forward(request, response);
|
||||||
@@ -158,11 +161,15 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleImageProxy(HttpServletResponse response, String num,
|
private void handleImageProxy(HttpServletResponse response, String num,
|
||||||
String source, String uri) throws IOException {
|
String source, String format, String uri) throws IOException {
|
||||||
SourceStringReader reader = new SourceStringReader( getContent(source));
|
SourceStringReader reader = new SourceStringReader( getContent(source));
|
||||||
int n = num == null ? 0 : Integer.parseInt(num);
|
int n = num == null ? 0 : Integer.parseInt(num);
|
||||||
// Write the first image to "os"
|
// Write the requested image to "os"
|
||||||
reader.generateImage(response.getOutputStream(), n);
|
if (format != null) {
|
||||||
|
reader.generateImage(response.getOutputStream(), n, new FileFormatOption(FileFormat.valueOf(format)));
|
||||||
|
} else {
|
||||||
|
reader.generateImage(response.getOutputStream(), n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendImage(HttpServletResponse response, String text, String uri)
|
private void sendImage(HttpServletResponse response, String text, String uri)
|
||||||
@@ -195,7 +202,7 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
reader.generateImage(response.getOutputStream(), new FileFormatOption(FileFormat.PNG));
|
reader.generateImage(response.getOutputStream(), new FileFormatOption(FileFormat.PNG));
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getContent(String adress) throws IOException {
|
private String getContent(String adress) throws IOException {
|
||||||
// HTTPConnection.setProxyServer("proxy", 8080);
|
// HTTPConnection.setProxyServer("proxy", 8080);
|
||||||
CookieModule.setCookiePolicyHandler(null);
|
CookieModule.setCookiePolicyHandler(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user