mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-12-22 08:48:54 +00:00
Code formatted, encoded text checked and warning added
The old url syntax is announced as deprecated.
This commit is contained in:
parent
d7ecaaa992
commit
90fe8924f7
@ -57,12 +57,14 @@ import HTTPClient.ParseException;
|
||||
*
|
||||
* Modified by Arnaud Roques
|
||||
* Modified by Pablo Lalloni
|
||||
* Packaged by Maxime Sinclair
|
||||
* Modified by Maxime Sinclair
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class PlantUmlServlet extends HttpServlet {
|
||||
|
||||
private static final Pattern urlPattern = Pattern.compile(".*/(.*)"); // Last part of the URL
|
||||
private static final Pattern encodedPattern = Pattern.compile("^[a-zA-Z0-9\\-\\_]+$"); // Format of a compressed diagram
|
||||
private static final Pattern startumlPattern = Pattern.compile("/\\w+/start/(.*)");
|
||||
private static final Pattern proxyPattern = Pattern.compile("/\\w+/proxy/((\\d+)/)?((\\w+)/)?(http://.*)");
|
||||
private static final Pattern oldStartumlPattern = Pattern.compile("/\\w+/uml/startuml/(.*)");
|
||||
@ -70,8 +72,7 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
private static final Pattern oldProxyPattern = Pattern.compile("/\\w+/uml/proxy/((\\d+)/)?((\\w+)/)?(http://.*)");
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
final String uri = request.getRequestURI();
|
||||
Matcher startumlMatcher = startumlPattern.matcher(uri);
|
||||
@ -88,12 +89,15 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
String source = proxyMatcher.group(5);
|
||||
handleImageProxy(response, num, source, format, uri);
|
||||
} else if (oldStartumlMatcher.matches()) {
|
||||
System.out.println("PlantUML WARNING This URL syntax is deprecated, please delete the '/uml/' part.");
|
||||
String source = oldStartumlMatcher.group(1);
|
||||
handleImage(response, source, uri);
|
||||
} else if (oldImageMatcher.matches()) {
|
||||
System.out.println("PlantUML WARNING This URL syntax is deprecated, please delete the '/uml/' part.");
|
||||
String source = oldImageMatcher.group(1);
|
||||
handleImageDecompress(response, source, uri);
|
||||
} else if (oldProxyMatcher.matches()) {
|
||||
System.out.println("PlantUML WARNING This URL syntax is deprecated, please delete the '/uml/' part.");
|
||||
String num = oldProxyMatcher.group(2);
|
||||
String format = oldProxyMatcher.group(4);
|
||||
String source = oldProxyMatcher.group(5);
|
||||
@ -103,10 +107,9 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
|
||||
IOException {
|
||||
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
String text = request.getParameter("text");
|
||||
@ -116,12 +119,18 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
Transcoder transcoder = getTranscoder();
|
||||
// the URL form has been submitted
|
||||
if (url != null && !url.trim().isEmpty()) {
|
||||
// TODO Verify the url is correct
|
||||
Pattern p = Pattern.compile(".*/(.*)");
|
||||
Matcher m = p.matcher(url);
|
||||
if (m.find()) {
|
||||
url = m.group(1);
|
||||
// Catch the last part of the URL
|
||||
Matcher m1 = urlPattern.matcher(url);
|
||||
if (m1.find()) {
|
||||
// Check it's a valid compressed text
|
||||
url = m1.group(1);
|
||||
Matcher m2 = encodedPattern.matcher(url);
|
||||
if (m2.find()) {
|
||||
url = m2.group(0);
|
||||
text = transcoder.decode(url);
|
||||
} else {
|
||||
System.out.println("PlantUML ERROR Not a valid compressed string : " + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
// the Text form has been submitted
|
||||
@ -142,8 +151,7 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
return TranscoderUtil.getDefaultTranscoder();
|
||||
}
|
||||
|
||||
private void handleImage(HttpServletResponse response, String source, String uri)
|
||||
throws IOException {
|
||||
private void handleImage(HttpServletResponse response, String source, String uri) throws IOException {
|
||||
source = URLDecoder.decode(source, "UTF-8");
|
||||
StringBuilder plantUmlSource = new StringBuilder();
|
||||
|
||||
@ -156,16 +164,15 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
|
||||
}
|
||||
|
||||
private void handleImageDecompress(HttpServletResponse response,
|
||||
String source, String uri) throws IOException {
|
||||
private void handleImageDecompress(HttpServletResponse response, String source, String uri) throws IOException {
|
||||
source = URLDecoder.decode(source, "UTF-8");
|
||||
Transcoder transcoder = getTranscoder();
|
||||
String text2 = transcoder.decode(source);
|
||||
sendImage(response, text2, uri);
|
||||
}
|
||||
|
||||
private void handleImageProxy(HttpServletResponse response, String num,
|
||||
String source, String format, String uri) throws IOException {
|
||||
private void handleImageProxy(HttpServletResponse response, String num, String source, String format, String uri)
|
||||
throws IOException {
|
||||
SourceStringReader reader = new SourceStringReader(getContent(source));
|
||||
int n = num == null ? 0 : Integer.parseInt(num);
|
||||
|
||||
@ -185,8 +192,7 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
return new FileFormatOption(FileFormat.PNG);
|
||||
}
|
||||
|
||||
private void sendImage(HttpServletResponse response, String text, String uri)
|
||||
throws IOException {
|
||||
private void sendImage(HttpServletResponse response, String text, String uri) throws IOException {
|
||||
final String uml;
|
||||
if (text.startsWith("@startuml")) {
|
||||
uml = text;
|
||||
|
Loading…
Reference in New Issue
Block a user