Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/server/CSVExportServiceImpl.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/CSVExportServiceImpl.java@1f2f08211a5f |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.server; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import java.io.Reader; | |
7 import java.io.InputStream; | |
8 import java.io.InputStreamReader; | |
9 import java.io.IOException; | |
10 | |
11 import org.w3c.dom.Document; | |
12 import org.w3c.dom.Element; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 | |
16 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | |
17 | |
18 import au.com.bytecode.opencsv.CSVReader; | |
19 | |
20 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
21 import de.intevation.artifacts.common.utils.XMLUtils; | |
22 | |
23 import de.intevation.artifacts.httpclient.http.HttpClient; | |
24 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
25 | |
26 import de.intevation.flys.client.shared.exceptions.ServerException; | |
27 import de.intevation.flys.client.client.services.CSVExportService; | |
28 | |
29 | |
30 /** | |
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
32 */ | |
33 public class CSVExportServiceImpl | |
34 extends RemoteServiceServlet | |
35 implements CSVExportService | |
36 { | |
37 private static final Logger logger = | |
38 Logger.getLogger(CSVExportServiceImpl.class); | |
39 | |
40 | |
41 public static final String ERROR_NO_EXPORT_FOUND = | |
42 "error_no_export_found"; | |
43 | |
44 public List<String[]> getCSV( | |
45 String locale, | |
46 String uuid, | |
47 String name) | |
48 throws ServerException | |
49 { | |
50 logger.info("CSVExportServiceImpl.getCSV"); | |
51 | |
52 String url = getServletContext().getInitParameter("server-url"); | |
53 | |
54 Document requestDoc = XMLUtils.newDocument(); | |
55 | |
56 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
57 requestDoc, | |
58 ArtifactNamespaceContext.NAMESPACE_URI, | |
59 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
60 | |
61 Element action = ec.create("action"); | |
62 ec.addAttr(action, "type", "csv", true); | |
63 ec.addAttr(action, "name", name, true); | |
64 | |
65 requestDoc.appendChild(action); | |
66 | |
67 HttpClient client = new HttpClientImpl(url, locale); | |
68 | |
69 try { | |
70 InputStream in = client.collectionOut(requestDoc, uuid, "export"); | |
71 Reader reader = new InputStreamReader (in, "UTF-8"); | |
72 CSVReader csvReader = new CSVReader (reader); | |
73 | |
74 List<String[]> lines = new ArrayList<String[]>(); | |
75 String[] line = null; | |
76 | |
77 while ((line = csvReader.readNext()) != null) { | |
78 if (line != null) { | |
79 if (!line[0].startsWith("#") && line.length > 0) { | |
80 if (line[0].replace("'", "").length() > 0) { | |
81 lines.add(line); | |
82 } | |
83 } | |
84 } | |
85 } | |
86 | |
87 return lines; | |
88 } | |
89 catch (IOException ce) { | |
90 logger.error(ce.getLocalizedMessage()); | |
91 } | |
92 | |
93 throw new ServerException(ERROR_NO_EXPORT_FOUND); | |
94 } | |
95 } | |
96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |