[FEATURE] Proxy redesign, first step
This commit is contained in:
@@ -28,7 +28,6 @@ import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -52,34 +51,19 @@ import net.sourceforge.plantuml.SourceStringReader;
|
||||
@SuppressWarnings("serial")
|
||||
public class ProxyServlet extends HttpServlet {
|
||||
|
||||
private static final Pattern proxyPattern = Pattern.compile("/\\w+/proxy/((\\d+)/)?((\\w+)/)?(http://.*)");
|
||||
private String format;
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
final String uri = request.getRequestURI();
|
||||
|
||||
Matcher proxyMatcher = proxyPattern.matcher(uri);
|
||||
if (proxyMatcher.matches()) {
|
||||
String num = proxyMatcher.group(2); // Optional number of the diagram source
|
||||
format = proxyMatcher.group(4); // Expected format of the generated diagram
|
||||
String sourceURL = proxyMatcher.group(5);
|
||||
handleImageProxy(response, num, sourceURL);
|
||||
} else {
|
||||
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", "ERROR Invalid proxy syntax : " + uri);
|
||||
request.removeAttribute("net.sourceforge.plantuml.servlet.encoded");
|
||||
|
||||
// forward to index.jsp
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleImageProxy(HttpServletResponse response, String num, String source) throws IOException {
|
||||
final String source = request.getParameter("src");
|
||||
final String index = request.getParameter("idx");
|
||||
|
||||
// TODO Check if the src URL is valid
|
||||
|
||||
// generate the response
|
||||
SourceStringReader reader = new SourceStringReader(getSource(source));
|
||||
int n = num == null ? 0 : Integer.parseInt(num);
|
||||
|
||||
int n = index == null ? 0 : Integer.parseInt(index);
|
||||
reader.generateImage(response.getOutputStream(), n, new FileFormatOption(getOutputFormat(), false));
|
||||
}
|
||||
|
||||
@@ -111,7 +95,7 @@ public class ProxyServlet extends HttpServlet {
|
||||
return FileFormat.SVG;
|
||||
}
|
||||
if (format.equals("txt")) {
|
||||
return FileFormat.ATXT;
|
||||
return FileFormat.UTXT;
|
||||
}
|
||||
return FileFormat.PNG;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user