Add support for generating parameterized image format in proxy requests
This commit is contained in:
@@ -53,6 +53,7 @@ import HTTPClient.ParseException;
|
||||
* See http://www.banapple.de/display/BANAPPLE/plantuml+user+macro
|
||||
*
|
||||
* Modified by Arnaud Roques
|
||||
* Modified by Pablo Lalloni
|
||||
* Packaged by Maxime Sinclair
|
||||
*
|
||||
*/
|
||||
@@ -60,10 +61,10 @@ import HTTPClient.ParseException;
|
||||
public class PlantUmlServlet extends HttpServlet {
|
||||
|
||||
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 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
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
@@ -80,8 +81,9 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
handleImage(response, source, uri);
|
||||
} else if (proxyMatcher.matches()) {
|
||||
String num = proxyMatcher.group(2);
|
||||
String source = proxyMatcher.group(3);
|
||||
handleImageProxy(response, num, source, uri);
|
||||
String format = proxyMatcher.group(4);
|
||||
String source = proxyMatcher.group(5);
|
||||
handleImageProxy(response, num, source, format, uri);
|
||||
} else if (oldStartumlMatcher.matches()) {
|
||||
String source = oldStartumlMatcher.group(1);
|
||||
handleImage(response, source, uri);
|
||||
@@ -90,8 +92,9 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
handleImageDecompress(response, source, uri);
|
||||
} else if (oldProxyMatcher.matches()) {
|
||||
String num = oldProxyMatcher.group(2);
|
||||
String source = oldProxyMatcher.group(3);
|
||||
handleImageProxy(response, num, source, uri);
|
||||
String format = oldProxyMatcher.group(4);
|
||||
String source = oldProxyMatcher.group(5);
|
||||
handleImageProxy(response, num, source, format, uri);
|
||||
} else {
|
||||
doPost(request, response);
|
||||
}
|
||||
@@ -109,7 +112,7 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
|
||||
Transcoder transcoder = getTranscoder();
|
||||
// the URL form has been submitted
|
||||
if ((url != null) && (!url.trim().isEmpty())) {
|
||||
if (url != null && !url.trim().isEmpty()) {
|
||||
// TODO Verify the url is correct
|
||||
Pattern p = Pattern.compile(".*/(.*)");
|
||||
Matcher m = p.matcher(url);
|
||||
@@ -119,7 +122,7 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
}
|
||||
}
|
||||
// the Text form has been submitted
|
||||
if ((text != null) && (!text.trim().isEmpty())) {
|
||||
if (text != null && !text.trim().isEmpty()) {
|
||||
encoded = transcoder.encode(text);
|
||||
}
|
||||
|
||||
@@ -158,11 +161,15 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
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));
|
||||
int n = num == null ? 0 : Integer.parseInt(num);
|
||||
// Write the first image to "os"
|
||||
reader.generateImage(response.getOutputStream(), n);
|
||||
// Write the requested image to "os"
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user