diff --git a/.classpath b/.classpath
index 0853198..bcc389d 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,9 @@
This application provides a servlet which serves images createdby PlantUML.
"); + + String text = request.getParameter("text"); + String url = request.getParameter("url"); + String encode = ""; + + Transcoder transcoder = getTranscoder(); + if (url != null) { + Pattern p = Pattern.compile(".*/(.*)"); + Matcher m = p.matcher(url); + if (m.find()) { + url = m.group(1); + } + text = transcoder.decode(url); + } + writer.print(""); + writer.print(""); + + String host = "http://" + request.getServerName()+ ":" + request.getServerPort(); + String total = host + "/plantuml/uml/image/" + encode; + + writer.print("
"); + + if (text != null) { + writer.print("");
+
+ String urlPart = "\"" + total + "\"";
+ writer.print("");
+ writer.print("");
+ writer.print("<img src=" + urlPart + " >");
+ writer.print("
");
+
+ writer.print("");
+ writer.print("");
+ writer.print("");
+ }
+ writer.print("");
+ writer.flush();
+ }
+
+ private Transcoder getTranscoder() {
+ return TranscoderUtil.getDefaultTranscoder();
+ }
+
+
+ private void handleImage(HttpServletResponse response, String source)
+ throws IOException {
+ source = URLDecoder.decode(source, "UTF-8");
+ StringBuilder plantUmlSource = new StringBuilder();
+
+ StringTokenizer tokenizer = new StringTokenizer(source, "/@");
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ plantUmlSource.append(token).append("\n");
+ }
+ sendImage(response, plantUmlSource.toString());
+
+ }
+
+ private void handleImageDecompress(HttpServletResponse response,
+ String source) throws IOException {
+ source = URLDecoder.decode(source, "UTF-8");
+ Transcoder transcoder = getTranscoder();
+ String text2 = transcoder.decode(source);
+ sendImage(response, text2);
+ }
+
+ private void handleImageProxy(HttpServletResponse response, String num,
+ String source) throws IOException {
+ String s = getContent(source);
+ SourceStringReader reader = new SourceStringReader(s);
+ int n = num == null ? 0 : Integer.parseInt(num);
+ // Write the first image to "os"
+ reader.generateImage(response.getOutputStream(), n);
+ }
+
+ private void sendImage(HttpServletResponse response, String text)
+ throws IOException {
+ StringBuilder plantUmlSource = new StringBuilder();
+ plantUmlSource.append("@startuml\n");
+ plantUmlSource.append(text);
+ plantUmlSource.append("\n@enduml");
+
+ SourceStringReader reader = new SourceStringReader(plantUmlSource
+ .toString());
+ // Write the first image to "os"
+ response.setContentType("image/png");
+ reader.generateImage(response.getOutputStream());
+ response.flushBuffer();
+ }
+
+ public 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());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml
new file mode 100644
index 0000000..06353fe
--- /dev/null
+++ b/WEB-INF/web.xml
@@ -0,0 +1,15 @@
+
+