version 2017.09

This commit is contained in:
Arnaud Roques
2017-04-05 21:57:35 +02:00
parent 8735b22339
commit 67e9aeb992
9 changed files with 108 additions and 55 deletions

View File

@@ -24,6 +24,8 @@
package net.sourceforge.plantuml.servlet;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.IIOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -43,12 +45,21 @@ public abstract class UmlDiagramService extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// build the UML source from the compressed request parameter
String uml = UmlExtractor.getUmlSource(getSource(request.getRequestURI()));
final String[] sourceAndIdx = getSourceAndIdx(request.getRequestURI());
final String uml;
try {
uml = UmlExtractor.getUmlSource(sourceAndIdx[0]);
} catch (Exception e) {
e.printStackTrace();
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad Request");
return;
}
// generate the response
DiagramResponse dr = new DiagramResponse(response, getOutputFormat());
DiagramResponse dr = new DiagramResponse(response, getOutputFormat(), request);
final int idx = Integer.parseInt(sourceAndIdx[1]);
try {
dr.sendDiagram(uml);
dr.sendDiagram(uml, idx);
} catch (IIOException iioe) {
// Browser has closed the connection, so the HTTP OutputStream is closed
// Silently catch the exception to avoid annoying log
@@ -56,6 +67,8 @@ public abstract class UmlDiagramService extends HttpServlet {
dr = null;
}
private static final Pattern RECOVER_UML_PATTERN = Pattern.compile("/\\w+/\\w+/(\\d+/)?(.*)");
/**
* Extracts the compressed UML source from the HTTP URI.
*
@@ -63,7 +76,23 @@ public abstract class UmlDiagramService extends HttpServlet {
* the complete URI as returned by request.getRequestURI()
* @return the compressed UML source
*/
abstract public String getSource(String uri);
public final String[] getSourceAndIdx(String uri) {
final Matcher recoverUml = RECOVER_UML_PATTERN.matcher(uri);
// the URL form has been submitted
if (recoverUml.matches()) {
final String data = recoverUml.group(2);
if (data.length() >= 4) {
String idx = recoverUml.group(1);
if (idx == null) {
idx = "0";
} else {
idx = idx.substring(0, idx.length() - 1);
}
return new String[]{data, idx };
}
}
return new String[]{"", "0" };
}
/**
* Gives the wished output format of the diagram. This value is used by the DiagramResponse class.