# HG changeset patch # User Sascha L. Teichmann # Date 1308820314 0 # Node ID 84d3c5fde5bb8b0bd48bae1f7995e396bd3f7298 # Parent 8cb98fa4987f1c037c9c28175d904e29d208bf90 First version of error reports. flys-client/trunk@2211 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 8cb98fa4987f -r 84d3c5fde5bb flys-client/ChangeLog --- a/flys-client/ChangeLog Wed Jun 22 15:34:52 2011 +0000 +++ b/flys-client/ChangeLog Thu Jun 23 09:11:54 2011 +0000 @@ -1,3 +1,14 @@ +2011-06-23 Sascha L. Teichmann + + * pom.xml: Added dependency to Apache Commons Lang 2.6 http://commons.apache.org/lang/ + Used for proper HTML string escaping. + + * src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java: Generate + error reports as HTML lists. + + * src/main/java/de/intevation/flys/client/client/ui/ParameterList.java: Set report + in corresponding panel. + 2011-06-22 Sascha L. Teichmann * src/main/java/de/intevation/flys/client/client/services/ReportService.java, diff -r 8cb98fa4987f -r 84d3c5fde5bb flys-client/pom.xml --- a/flys-client/pom.xml Wed Jun 22 15:34:52 2011 +0000 +++ b/flys-client/pom.xml Thu Jun 23 09:11:54 2011 +0000 @@ -64,6 +64,11 @@ 4.4 test + + commons-lang + commons-lang + 2.6 + diff -r 8cb98fa4987f -r 84d3c5fde5bb flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Wed Jun 22 15:34:52 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Thu Jun 23 09:11:54 2011 +0000 @@ -44,11 +44,13 @@ import de.intevation.flys.client.client.event.StepForwardEvent; import de.intevation.flys.client.client.event.StepForwardHandler; import de.intevation.flys.client.client.services.AdvanceService; +import de.intevation.flys.client.client.services.ReportService; import de.intevation.flys.client.client.services.AdvanceServiceAsync; import de.intevation.flys.client.client.services.ArtifactService; import de.intevation.flys.client.client.services.ArtifactServiceAsync; import de.intevation.flys.client.client.services.StepForwardService; import de.intevation.flys.client.client.services.StepForwardServiceAsync; +import de.intevation.flys.client.client.services.ReportServiceAsync; public class ParameterList @@ -73,6 +75,10 @@ GWT.create(AdvanceService.class); + protected ReportServiceAsync reportService = + GWT.create(ReportService.class); + + /** The list of ParameterizationChangeHandler.*/ protected List parameterHandlers; @@ -167,7 +173,6 @@ left.addMember(report); reportPanel = new Canvas(); - //reportPanel.setContents("I was here!"); reportPanel.setHeight("*"); report.addMember(reportPanel); @@ -583,10 +588,39 @@ int num = reports != null ? reports.size() : 0; GWT.log("Update report modes: " + num); + if (num == 0) { + reportPanel.setContents(""); + return; + } + + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String locale = config.getLocale(); + + String cid = c.identifier(); + for (ReportMode report: reports) { GWT.log("report '" + report.toString() + "'"); + + reportService.report(cid, url, locale, report.getName(), + new AsyncCallback() { + public void onFailure(Throwable caught) { + SC.warn(caught.getMessage()); + } + + public void onSuccess(String msg) { + setReportMessage(msg); + } + }); } + } + protected void setReportMessage(String msg) { + GWT.log("returned from service: " + msg); + if (msg == null) { + msg = ""; + } + reportPanel.setContents(msg); } diff -r 8cb98fa4987f -r 84d3c5fde5bb flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java Wed Jun 22 15:34:52 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ReportServiceImpl.java Thu Jun 23 09:11:54 2011 +0000 @@ -1,9 +1,24 @@ package de.intevation.flys.client.server; +import java.io.InputStream; +import java.io.IOException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import org.apache.commons.lang.StringEscapeUtils; + import de.intevation.flys.client.client.services.ReportService; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.ClientProtocolUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + public class ReportServiceImpl extends RemoteServiceServlet implements ReportService @@ -16,7 +31,79 @@ String out ) { System.err.println("report: " + collectionId + " " + out); - return out; + + Document request = ClientProtocolUtils.newOutCollectionDocument( + collectionId, + out, + "report"); + + InputStream in = null; + try { + HttpClient client = new HttpClientImpl(url, locale); + in = client.collectionOut(request, collectionId, out); + + if (in == null) { + System.err.println("report: no report"); + return null; + } + + Document report = XMLUtils.parseDocument(in); + + return buildReport(report); + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + catch (Exception e) { + e.printStackTrace(); + } + finally { + if (in != null) { + try { + in.close(); + } + catch (IOException ioe) { + } + } + } + + return "error processing error report"; + } + + protected static String buildReport(Document document) { + + NodeList problems = document.getElementsByTagName("problem"); + + StringBuilder global = new StringBuilder(); + StringBuilder kms = new StringBuilder(); + + for (int i = 0, N = problems.getLength(); i < N; ++i) { + + Element element = (Element)problems.item(i); + + String km = element.getAttribute("km"); + String msg = element.getTextContent(); + + if (km.length() > 0) { + kms.append("
  • ") + .append(StringEscapeUtils.escapeHtml(km)) + .append(": ") + .append(StringEscapeUtils.escapeHtml(msg)) + .append("
  • "); + } + else { + global.append("
  • ") + .append(StringEscapeUtils.escapeHtml(msg)) + .append("
  • "); + } + } + + StringBuilder sb = new StringBuilder("
      ") + .append(global) + .append(kms) + .append("
    "); + + return sb.toString(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :