Normalization of the format for the proxy feature.
New syntax is : plantuml/proxy/[id/][format/]remoteURL where id is a number identifying the diagram definition when the remote URL contains more than one diagram, and format specify the output : img, txt or svg.
This commit is contained in:
@@ -52,6 +52,9 @@ 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
|
||||||
*
|
*
|
||||||
|
* This class is the old all-in-one historic implementation of the PlantUml server.
|
||||||
|
* See package.html for the new design. It's a work in progress.
|
||||||
|
*
|
||||||
* Modified by Arnaud Roques
|
* Modified by Arnaud Roques
|
||||||
* Modified by Pablo Lalloni
|
* Modified by Pablo Lalloni
|
||||||
* Packaged by Maxime Sinclair
|
* Packaged by Maxime Sinclair
|
||||||
@@ -164,14 +167,23 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
String source, String format, 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 requested image to "os"
|
|
||||||
if (format != null) {
|
reader.generateImage(response.getOutputStream(), n, getFormat(format));
|
||||||
reader.generateImage(response.getOutputStream(), n, new FileFormatOption(FileFormat.valueOf(format)));
|
|
||||||
} else {
|
|
||||||
reader.generateImage(response.getOutputStream(), n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FileFormatOption getFormat(String f) {
|
||||||
|
if (f==null) {
|
||||||
|
return new FileFormatOption(FileFormat.PNG);
|
||||||
|
}
|
||||||
|
if (f.equals("svg")) {
|
||||||
|
return new FileFormatOption(FileFormat.SVG);
|
||||||
|
}
|
||||||
|
if (f.equals("txt")) {
|
||||||
|
return new FileFormatOption(FileFormat.ATXT);
|
||||||
|
}
|
||||||
|
return new FileFormatOption(FileFormat.PNG);
|
||||||
|
}
|
||||||
|
|
||||||
private void sendImage(HttpServletResponse response, String text, String uri)
|
private void sendImage(HttpServletResponse response, String text, String uri)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final String uml;
|
final String uml;
|
||||||
|
|||||||
@@ -37,6 +37,21 @@ public class TestProxy extends WebappTestCase {
|
|||||||
assertTrue( diagramLen < 1700);
|
assertTrue( diagramLen < 1700);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testProxyWithFormat() throws Exception {
|
||||||
|
WebConversation conversation = new WebConversation();
|
||||||
|
WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/svg/"
|
||||||
|
+ getServerUrl() + "welcome");
|
||||||
|
WebResponse response = conversation.getResource( request);
|
||||||
|
// Analyze response
|
||||||
|
// Verifies the Content-Type header
|
||||||
|
// TODO assertEquals( "Response content type is not SVG", "image/svg+xml", response.getContentType());
|
||||||
|
// Get the content and verify its size
|
||||||
|
String diagram = response.getText();
|
||||||
|
int diagramLen = diagram.length();
|
||||||
|
assertTrue( diagramLen > 1700);
|
||||||
|
assertTrue( diagramLen < 1800);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that the HTTP header of a diagram incites the browser to cache it.
|
* Verifies that the HTTP header of a diagram incites the browser to cache it.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user