Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/server/ReportServiceImpl.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java@bafb2e81a14a |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
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; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | |
13 | |
14 import org.apache.commons.lang.StringEscapeUtils; | |
15 | |
16 import de.intevation.flys.client.client.services.ReportService; | |
17 | |
18 import de.intevation.artifacts.common.utils.XMLUtils; | |
19 import de.intevation.artifacts.common.utils.ClientProtocolUtils; | |
20 | |
21 import de.intevation.artifacts.httpclient.http.HttpClient; | |
22 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
23 | |
24 public class ReportServiceImpl | |
25 extends RemoteServiceServlet | |
26 implements ReportService | |
27 { | |
28 private static final Logger logger = | |
29 Logger.getLogger(ReportServiceImpl.class); | |
30 | |
31 | |
32 @Override | |
33 public String report( | |
34 String collectionId, | |
35 String locale, | |
36 String out | |
37 ) { | |
38 logger.info("report: " + collectionId + " " + out); | |
39 | |
40 String url = getServletContext().getInitParameter("server-url"); | |
41 | |
42 Document request = ClientProtocolUtils.newOutCollectionDocument( | |
43 collectionId, | |
44 out, | |
45 "report"); | |
46 | |
47 InputStream in = null; | |
48 try { | |
49 HttpClient client = new HttpClientImpl(url, locale); | |
50 in = client.collectionOut(request, collectionId, out); | |
51 | |
52 if (in == null) { | |
53 logger.debug("report: no report"); | |
54 return null; | |
55 } | |
56 | |
57 Document report = XMLUtils.parseDocument(in); | |
58 | |
59 return buildReport(report); | |
60 } | |
61 catch (IOException ioe) { | |
62 ioe.printStackTrace(); | |
63 } | |
64 catch (Exception e) { | |
65 e.printStackTrace(); | |
66 } | |
67 finally { | |
68 if (in != null) { | |
69 try { | |
70 in.close(); | |
71 } | |
72 catch (IOException ioe) { | |
73 } | |
74 } | |
75 } | |
76 | |
77 return "error processing error report"; | |
78 } | |
79 | |
80 | |
81 /** Returns String containing markup that shows the report message. */ | |
82 protected static String buildReport(Document document) { | |
83 | |
84 NodeList problems = document.getElementsByTagName("problem"); | |
85 | |
86 StringBuilder global = new StringBuilder(); | |
87 StringBuilder kms = new StringBuilder(); | |
88 | |
89 for (int i = 0, N = problems.getLength(); i < N; ++i) { | |
90 | |
91 Element element = (Element)problems.item(i); | |
92 | |
93 String km = element.getAttribute("km"); | |
94 String msg = element.getTextContent(); | |
95 | |
96 if (km.length() > 0) { | |
97 kms.append("<li><strong>KM ") | |
98 .append(StringEscapeUtils.escapeHtml(km)) | |
99 .append("</strong>: ") | |
100 .append(StringEscapeUtils.escapeHtml(msg)) | |
101 .append("</li>"); | |
102 } | |
103 else { | |
104 global.append("<li>") | |
105 .append(StringEscapeUtils.escapeHtml(msg)) | |
106 .append("</li>"); | |
107 } | |
108 } | |
109 | |
110 StringBuilder sb = new StringBuilder("<ul>") | |
111 .append(global) | |
112 .append(kms) | |
113 .append("</ul>"); | |
114 | |
115 return sb.toString(); | |
116 } | |
117 } | |
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |