Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java @ 549:e74bf6bfeeb6
Use the same code to create the attribute document for the chart creation in ChartOutputService and ChartInfoService.
flys-client/trunk@2060 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 07 Jun 2011 10:03:19 +0000 |
parents | 95a7f9cb3d58 |
children | 6050d49eaba3 |
comparison
equal
deleted
inserted
replaced
548:aff225e07720 | 549:e74bf6bfeeb6 |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.io.InputStream; | 3 import java.io.InputStream; |
4 import java.io.IOException; | 4 import java.io.IOException; |
5 import java.util.Map; | |
5 | 6 |
6 import javax.xml.xpath.XPathConstants; | 7 import javax.xml.xpath.XPathConstants; |
7 | 8 |
8 import org.w3c.dom.Document; | 9 import org.w3c.dom.Document; |
9 import org.w3c.dom.Element; | |
10 import org.w3c.dom.Node; | 10 import org.w3c.dom.Node; |
11 | 11 |
12 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | 12 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
13 | 13 |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 14 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
15 import de.intevation.artifacts.common.utils.ClientProtocolUtils; | 15 import de.intevation.artifacts.common.utils.ClientProtocolUtils; |
16 import de.intevation.artifacts.common.utils.XMLUtils; | 16 import de.intevation.artifacts.common.utils.XMLUtils; |
17 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
18 | 17 |
19 import de.intevation.artifacts.httpclient.http.HttpClient; | 18 import de.intevation.artifacts.httpclient.http.HttpClient; |
20 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | 19 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
21 | 20 |
22 import de.intevation.flys.client.shared.Transform2D; | 21 import de.intevation.flys.client.shared.Transform2D; |
41 | 40 |
42 public static final String EXCEPTION_STRING = "error_chart_info_service"; | 41 public static final String EXCEPTION_STRING = "error_chart_info_service"; |
43 | 42 |
44 | 43 |
45 public Transform2D getChartInfo( | 44 public Transform2D getChartInfo( |
46 Collection collection, | 45 Collection collection, |
47 String url, | 46 String url, |
48 String locale, | 47 String locale, |
49 String type, | 48 String type, |
50 int width, | 49 Map<String, String> attr) |
51 int height) | |
52 throws ServerException | 50 throws ServerException |
53 { | 51 { |
54 System.out.println("ChartInfoServiceImpl.getChartInfo"); | 52 System.out.println("ChartInfoServiceImpl.getChartInfo"); |
55 | 53 |
56 Document request = ClientProtocolUtils.newOutCollectionDocument( | 54 Document request = ClientProtocolUtils.newOutCollectionDocument( |
57 collection.identifier(), | 55 collection.identifier(), |
58 type, | 56 type, |
59 type, | 57 type, |
60 getChartAttributes(width, height)); | 58 ChartServiceHelper.getChartAttributes(attr)); |
61 | 59 |
62 try { | 60 try { |
63 HttpClient client = new HttpClientImpl(url, locale); | 61 HttpClient client = new HttpClientImpl(url, locale); |
64 InputStream in = client.collectionOut( | 62 InputStream in = client.collectionOut( |
65 request, | 63 request, |
75 } | 73 } |
76 | 74 |
77 System.err.println("Error while fetching chart info."); | 75 System.err.println("Error while fetching chart info."); |
78 | 76 |
79 throw new ServerException(EXCEPTION_STRING); | 77 throw new ServerException(EXCEPTION_STRING); |
80 } | |
81 | |
82 | |
83 /** | |
84 * This method returns a document which might contain parameters to adjust | |
85 * chart settings. The document is created using the information that are | |
86 * contained in the request object. | |
87 * | |
88 * @param req The request document. | |
89 * | |
90 * @return a document to adjust chart settings. | |
91 */ | |
92 protected Document getChartAttributes(int width, int height) { | |
93 Document doc = XMLUtils.newDocument(); | |
94 | |
95 ElementCreator ec = new ElementCreator( | |
96 doc, | |
97 ArtifactNamespaceContext.NAMESPACE_URI, | |
98 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
99 | |
100 Element attr = ec.create("attributes"); | |
101 Element size = ec.create("size"); | |
102 | |
103 ec.addAttr(size, "width", String.valueOf(width), true); | |
104 ec.addAttr(size, "height", String.valueOf(height), true); | |
105 | |
106 attr.appendChild(size); | |
107 doc.appendChild(attr); | |
108 | |
109 return doc; | |
110 } | 78 } |
111 | 79 |
112 | 80 |
113 /** | 81 /** |
114 * Parses the chart info document and extract the Transform2D values. | 82 * Parses the chart info document and extract the Transform2D values. |