annotate flys-client/src/main/java/de/intevation/flys/client/server/CSVExportServiceImpl.java @ 258:5091675676d6

Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations. flys-client/trunk@1871 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 10 May 2011 06:48:46 +0000
parents 5e1c1b7d6516
children 50a95db68e66
rev   line source
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import java.util.List;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import java.io.Reader;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 import java.io.InputStream;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import java.io.InputStreamReader;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import java.io.IOException;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import org.w3c.dom.Document;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import org.w3c.dom.Element;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import au.com.bytecode.opencsv.CSVReader;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import de.intevation.artifacts.common.ArtifactNamespaceContext;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import de.intevation.artifacts.common.utils.XMLUtils;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import de.intevation.artifacts.httpclient.http.HttpClient;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 import de.intevation.flys.client.shared.exceptions.ServerException;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 import de.intevation.flys.client.client.services.CSVExportService;
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 /**
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 */
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 public class CSVExportServiceImpl
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 extends RemoteServiceServlet
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 implements CSVExportService
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 {
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 public static final String ERROR_NO_EXPORT_FOUND =
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 "error_no_export_found";
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 public List getCSV(
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 String url,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 String locale,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 String uuid,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 String name)
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 throws ServerException
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 {
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 System.out.println("CSVExportServiceImpl.getCSV");
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 Document requestDoc = XMLUtils.newDocument();
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 requestDoc,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 ArtifactNamespaceContext.NAMESPACE_URI,
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 ArtifactNamespaceContext.NAMESPACE_PREFIX);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 if (name.startsWith("output.")) {
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 name = name.substring(name.indexOf(".") + 1);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56
258
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
57 Element action = ec.create("action");
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
58 ec.addAttr(action, "type", "csv", true);
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
59 ec.addAttr(action, "name", name, true);
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 requestDoc.appendChild(action);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 HttpClient client = new HttpClientImpl(url, locale);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 try {
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 InputStream in = client.collectionOut(requestDoc, uuid, "export");
258
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
66 Reader reader = new InputStreamReader (in, "UTF-8");
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 CSVReader csvReader = new CSVReader (reader);
258
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
68
5091675676d6 Fixed attributes/namespaces in the XML document that is used to fetch the CSV export of WINFO computations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 256
diff changeset
69 return csvReader.readAll ();
256
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 catch (IOException ce) {
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 System.err.println(ce.getLocalizedMessage());
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 throw new ServerException(ERROR_NO_EXPORT_FOUND);
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 }
5e1c1b7d6516 Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org