Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java @ 4198:1cdbd8a0c994
Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation.
The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks.
In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to
specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1
icon, RANGE 2 icons for lower and upper.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Oct 2012 13:31:25 +0200 |
parents | d78b7c06e061 |
children | 442fbb290fa8 |
rev | line source |
---|---|
2639 | 1 package de.intevation.flys.artifacts.services; |
2 | |
3 import java.io.File; | |
4 import java.io.FileOutputStream; | |
5 import java.io.IOException; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import org.apache.commons.codec.binary.Base64; | |
10 | |
11 import org.w3c.dom.Document; | |
12 import org.w3c.dom.Element; | |
13 | |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
15 import de.intevation.artifacts.common.utils.XMLUtils; | |
16 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
17 import de.intevation.artifacts.common.utils.FileTools; | |
18 | |
19 import de.intevation.artifacts.CallMeta; | |
20 import de.intevation.artifacts.GlobalContext; | |
21 | |
22 import de.intevation.flys.utils.FLYSUtils; | |
23 | |
24 /** | |
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
26 */ | |
27 public class FileUploadService extends FLYSService { | |
28 | |
29 /** The logger used in this service.*/ | |
30 private static Logger logger = Logger.getLogger(FileUploadService.class); | |
31 | |
32 /** XPath that points to the artifact uuid.*/ | |
33 public static final String XPATH_ARTIFACT_UUID = | |
34 "/upload/artifact-uuid/text()"; | |
35 | |
36 /** XPath that points to the base64 encoded data.*/ | |
37 public static final String XPATH_DATA = "/upload/data/text()"; | |
38 | |
39 public FileUploadService() { | |
40 } | |
41 | |
42 | |
43 @Override | |
44 protected Document doProcess( | |
45 Document data, | |
46 GlobalContext context, | |
47 CallMeta callMeta | |
48 ) { | |
49 logger.debug("FileUploadService.process"); | |
50 | |
51 String uuid = extractUuid(data); | |
52 | |
53 byte[] fileData = extractData(data); | |
54 if (fileData != null) { | |
55 try { | |
56 String shapePath = FLYSUtils.getXPathString( | |
57 FLYSUtils.XPATH_SHAPEFILE_DIR); | |
58 | |
59 File artifactDir = FileTools.getDirectory(shapePath, uuid); | |
60 FileOutputStream fos = | |
2641
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
61 new FileOutputStream( |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
62 new File(artifactDir, "user-rgd.zip")); |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
63 try { |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
64 fos.write(fileData); |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
65 } |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
66 finally { |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
67 fos.close(); |
2bad13107161
Make file upload cross platform.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2640
diff
changeset
|
68 } |
2639 | 69 } |
70 catch (IOException ioe) { | |
71 logger.warn(ioe, ioe); | |
72 } | |
73 } | |
74 else { | |
2640
b484318ca9c6
Make it compilable again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2639
diff
changeset
|
75 logger.debug("No data in uploaded xml."); |
2639 | 76 } |
77 | |
78 Document doc = XMLUtils.newDocument(); | |
79 ElementCreator ec = new ElementCreator(doc, null, null); | |
80 Element resp = ec.create("response"); | |
81 doc.appendChild(resp); | |
82 | |
83 return doc; | |
84 } | |
85 | |
86 | |
87 protected String extractUuid(Document data) { | |
88 return XMLUtils.xpathString( | |
89 data, XPATH_ARTIFACT_UUID, ArtifactNamespaceContext.INSTANCE); | |
90 } | |
91 | |
92 | |
93 protected byte[] extractData(Document data) { | |
94 String b64Data = XMLUtils.xpathString( | |
95 data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE); | |
96 | |
3084
d78b7c06e061
Fixed string comparision for identity.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3083
diff
changeset
|
97 if (b64Data != null && b64Data.length() > 0) { |
2639 | 98 byte[] fileData = Base64.decodeBase64(b64Data); |
99 return fileData; | |
100 } | |
101 return null; | |
102 } | |
103 } | |
3083
4bd3d8bbb60c
Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2646
diff
changeset
|
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |