mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-12-22 08:48:54 +00:00
[TASK] Old URL pattern is no more supported
Related code cleaned
This commit is contained in:
parent
24da19bf96
commit
d7192bf8e0
@ -24,7 +24,6 @@
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Matcher;
|
||||
@ -43,11 +42,6 @@ import net.sourceforge.plantuml.StringUtils;
|
||||
import net.sourceforge.plantuml.code.Transcoder;
|
||||
import net.sourceforge.plantuml.code.TranscoderUtil;
|
||||
import net.sourceforge.plantuml.api.PlantumlUtils;
|
||||
import HTTPClient.CookieModule;
|
||||
import HTTPClient.HTTPConnection;
|
||||
import HTTPClient.HTTPResponse;
|
||||
import HTTPClient.ModuleException;
|
||||
import HTTPClient.ParseException;
|
||||
|
||||
/*
|
||||
* Original idea from Achim Abeling for Confluence macro
|
||||
@ -68,42 +62,15 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
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/(.*)");
|
||||
private static final Pattern oldImagePattern = Pattern.compile("/\\w+/uml/image/(.*)");
|
||||
private static final Pattern oldProxyPattern = Pattern.compile("/\\w+/uml/proxy/((\\d+)/)?((\\w+)/)?(http://.*)");
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
final String uri = request.getRequestURI();
|
||||
Matcher startumlMatcher = startumlPattern.matcher(uri);
|
||||
Matcher proxyMatcher = proxyPattern.matcher(uri);
|
||||
Matcher oldStartumlMatcher = oldStartumlPattern.matcher(uri);
|
||||
Matcher oldImageMatcher = oldImagePattern.matcher(uri);
|
||||
Matcher oldProxyMatcher = oldProxyPattern.matcher(uri);
|
||||
if (startumlMatcher.matches()) {
|
||||
String source = startumlMatcher.group(1);
|
||||
handleImage(response, source, uri);
|
||||
} else if (proxyMatcher.matches()) {
|
||||
String num = proxyMatcher.group(2);
|
||||
String format = proxyMatcher.group(4);
|
||||
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);
|
||||
handleImageProxy(response, num, source, format, uri);
|
||||
} else {
|
||||
doPost(request, response);
|
||||
}
|
||||
@ -171,34 +138,6 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
|
||||
}
|
||||
|
||||
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 {
|
||||
SourceStringReader reader = new SourceStringReader(getContent(source));
|
||||
int n = num == null ? 0 : Integer.parseInt(num);
|
||||
|
||||
reader.generateImage(response.getOutputStream(), n, getFormat(format));
|
||||
}
|
||||
|
||||
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) throws IOException {
|
||||
final String uml;
|
||||
if (text.startsWith("@startuml")) {
|
||||
@ -228,25 +167,4 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
reader.generateImage(response.getOutputStream(), new FileFormatOption(FileFormat.PNG));
|
||||
}
|
||||
|
||||
private String getContent(String adress) throws IOException {
|
||||
// HTTPConnection.setProxyServer("proxy", 8080);
|
||||
CookieModule.setCookiePolicyHandler(null);
|
||||
|
||||
final Pattern p = Pattern.compile("http://[^/]+(/?.*)");
|
||||
final Matcher m = p.matcher(adress);
|
||||
if (m.find() == false) {
|
||||
throw new IOException(adress);
|
||||
}
|
||||
final URL url = new URL(adress);
|
||||
final HTTPConnection httpConnection = new HTTPConnection(url);
|
||||
try {
|
||||
final HTTPResponse resp = httpConnection.Get(m.group(1));
|
||||
return resp.getText();
|
||||
} catch (ModuleException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch (ParseException e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user