mirror of
https://github.com/octoleo/plantuml-server.git
synced 2025-01-03 05:00:14 +00:00
Add support for generating parameterized image format in proxy requests
This commit is contained in:
parent
d494bc91f4
commit
4f80244a2b
@ -53,6 +53,7 @@ import HTTPClient.ParseException;
|
|||||||
* 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
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -60,10 +61,10 @@ import HTTPClient.ParseException;
|
|||||||
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,7 +122,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,12 +161,16 @@ 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"
|
||||||
|
if (format != null) {
|
||||||
|
reader.generateImage(response.getOutputStream(), n, new FileFormatOption(FileFormat.valueOf(format)));
|
||||||
|
} else {
|
||||||
reader.generateImage(response.getOutputStream(), n);
|
reader.generateImage(response.getOutputStream(), n);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void sendImage(HttpServletResponse response, String text, String uri)
|
private void sendImage(HttpServletResponse response, String text, String uri)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user