comparison flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java @ 604:84d3c5fde5bb

First version of error reports. flys-client/trunk@2211 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 Jun 2011 09:11:54 +0000
parents 8cb98fa4987f
children ab8eb2f544f2
comparison
equal deleted inserted replaced
603:8cb98fa4987f 604:84d3c5fde5bb
1 package de.intevation.flys.client.server; 1 package de.intevation.flys.client.server;
2
3 import java.io.InputStream;
4 import java.io.IOException;
5
6 import org.w3c.dom.Document;
7 import org.w3c.dom.Element;
8 import org.w3c.dom.NodeList;
2 9
3 import com.google.gwt.user.server.rpc.RemoteServiceServlet; 10 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
4 11
12 import org.apache.commons.lang.StringEscapeUtils;
13
5 import de.intevation.flys.client.client.services.ReportService; 14 import de.intevation.flys.client.client.services.ReportService;
15
16 import de.intevation.artifacts.common.utils.XMLUtils;
17 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
18
19 import de.intevation.artifacts.httpclient.http.HttpClient;
20 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
6 21
7 public class ReportServiceImpl 22 public class ReportServiceImpl
8 extends RemoteServiceServlet 23 extends RemoteServiceServlet
9 implements ReportService 24 implements ReportService
10 { 25 {
14 String url, 29 String url,
15 String locale, 30 String locale,
16 String out 31 String out
17 ) { 32 ) {
18 System.err.println("report: " + collectionId + " " + out); 33 System.err.println("report: " + collectionId + " " + out);
19 return out; 34
35 Document request = ClientProtocolUtils.newOutCollectionDocument(
36 collectionId,
37 out,
38 "report");
39
40 InputStream in = null;
41 try {
42 HttpClient client = new HttpClientImpl(url, locale);
43 in = client.collectionOut(request, collectionId, out);
44
45 if (in == null) {
46 System.err.println("report: no report");
47 return null;
48 }
49
50 Document report = XMLUtils.parseDocument(in);
51
52 return buildReport(report);
53 }
54 catch (IOException ioe) {
55 ioe.printStackTrace();
56 }
57 catch (Exception e) {
58 e.printStackTrace();
59 }
60 finally {
61 if (in != null) {
62 try {
63 in.close();
64 }
65 catch (IOException ioe) {
66 }
67 }
68 }
69
70 return "error processing error report";
71 }
72
73 protected static String buildReport(Document document) {
74
75 NodeList problems = document.getElementsByTagName("problem");
76
77 StringBuilder global = new StringBuilder();
78 StringBuilder kms = new StringBuilder();
79
80 for (int i = 0, N = problems.getLength(); i < N; ++i) {
81
82 Element element = (Element)problems.item(i);
83
84 String km = element.getAttribute("km");
85 String msg = element.getTextContent();
86
87 if (km.length() > 0) {
88 kms.append("<li><strong>")
89 .append(StringEscapeUtils.escapeHtml(km))
90 .append("</strong>: ")
91 .append(StringEscapeUtils.escapeHtml(msg))
92 .append("</li>");
93 }
94 else {
95 global.append("<li>")
96 .append(StringEscapeUtils.escapeHtml(msg))
97 .append("</li>");
98 }
99 }
100
101 StringBuilder sb = new StringBuilder("<ul>")
102 .append(global)
103 .append(kms)
104 .append("</ul>");
105
106 return sb.toString();
20 } 107 }
21 } 108 }
22 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org