Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java @ 3812:f788d2d901d6
merged flys-artifacts/pre2.6-2011-12-05
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:53 +0200 |
parents | fde3db5e68e8 |
children | 8afd6a9bb244 |
comparison
equal
deleted
inserted
replaced
3808:5fab0fe3c445 | 3812:f788d2d901d6 |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.w3c.dom.Document; | |
9 | |
10 import de.intevation.artifacts.Artifact; | |
11 import de.intevation.artifacts.ArtifactFactory; | |
12 import de.intevation.artifacts.CallMeta; | |
13 | |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
15 import de.intevation.artifacts.common.utils.XMLUtils; | |
16 | |
17 import de.intevation.artifactdatabase.data.DefaultStateData; | |
18 import de.intevation.artifactdatabase.state.DefaultOutput; | |
19 import de.intevation.artifactdatabase.state.Facet; | |
20 import de.intevation.artifactdatabase.state.State; | |
21 | |
22 import de.intevation.flys.artifacts.states.WMSBackgroundState; | |
23 | |
24 | |
25 public class ExternalWMSArtifact extends StaticFLYSArtifact { | |
26 | |
27 public static final String XPATH_IDS = "/art:action/art:ids/@value"; | |
28 | |
29 public static final String NAME = "external_wms"; | |
30 | |
31 private static final Logger logger = | |
32 Logger.getLogger(ExternalWMSArtifact.class); | |
33 | |
34 | |
35 @Override | |
36 public String getName() { | |
37 return NAME; | |
38 } | |
39 | |
40 | |
41 @Override | |
42 public void setup( | |
43 String identifier, | |
44 ArtifactFactory factory, | |
45 Object context, | |
46 CallMeta callMeta, | |
47 Document data) | |
48 { | |
49 logger.info("ExternalWMSArtifact.setup"); | |
50 | |
51 super.setup(identifier, factory, context, callMeta, data); | |
52 | |
53 String ids = XMLUtils.xpathString( | |
54 data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); | |
55 | |
56 if (ids != null && ids.length() > 0) { | |
57 addData("ids", new DefaultStateData("ids", null, null, ids)); | |
58 } | |
59 else { | |
60 throw new IllegalArgumentException("No attribute 'ids' found!"); | |
61 } | |
62 | |
63 List<Facet> fs = new ArrayList<Facet>(); | |
64 | |
65 WMSBackgroundState s = (WMSBackgroundState) getCurrentState(context); | |
66 s.computeInit(this, hash(), context, callMeta, fs); | |
67 | |
68 if (!fs.isEmpty()) { | |
69 facets.put(getCurrentStateId(), fs); | |
70 } | |
71 } | |
72 | |
73 | |
74 @Override | |
75 protected void initialize( | |
76 Artifact artifact, | |
77 Object context, | |
78 CallMeta callMeta) | |
79 { | |
80 // do nothing | |
81 } | |
82 | |
83 | |
84 @Override | |
85 public State getCurrentState(Object cc) { | |
86 State s = new ExternalWMSState(this); | |
87 | |
88 List<Facet> fs = facets.get(getCurrentStateId()); | |
89 | |
90 DefaultOutput o = new DefaultOutput( | |
91 "floodmap", | |
92 "floodmap", | |
93 "image/png", | |
94 fs, | |
95 "map"); | |
96 | |
97 s.getOutputs().add(o); | |
98 | |
99 return s; | |
100 } | |
101 | |
102 | |
103 /** | |
104 * Get a list containing the one and only State. | |
105 * @param context ignored. | |
106 * @return list with one and only state. | |
107 */ | |
108 @Override | |
109 protected List<State> getStates(Object context) { | |
110 ArrayList<State> states = new ArrayList<State>(); | |
111 states.add(getCurrentState(context)); | |
112 | |
113 return states; | |
114 } | |
115 | |
116 | |
117 public static class ExternalWMSState extends WMSBackgroundState { | |
118 | |
119 protected ExternalWMSArtifact artifact; | |
120 | |
121 protected String ids; | |
122 | |
123 | |
124 public ExternalWMSState(ExternalWMSArtifact artifact) { | |
125 super(); | |
126 this.artifact = artifact; | |
127 } | |
128 | |
129 protected String getIds() { | |
130 if (ids == null || ids.length() == 0) { | |
131 ids = artifact.getDataAsString("ids"); | |
132 } | |
133 | |
134 return ids; | |
135 } | |
136 | |
137 @Override | |
138 protected String getFacetType() { | |
139 return FLOODMAP_EXTERNAL_WMS; | |
140 } | |
141 | |
142 @Override | |
143 protected String getSrid() { | |
144 return ""; | |
145 } | |
146 | |
147 @Override | |
148 protected String getUrl() { | |
149 String ids = getIds(); | |
150 String[] parts = ids.split(";"); | |
151 | |
152 return parts[0]; | |
153 } | |
154 | |
155 @Override | |
156 protected String getLayer() { | |
157 String ids = getIds(); | |
158 String[] parts = ids.split(";"); | |
159 | |
160 return parts[1]; | |
161 } | |
162 | |
163 @Override | |
164 protected String getTitle(CallMeta meta) { | |
165 String ids = getIds(); | |
166 String[] parts = ids.split(";"); | |
167 | |
168 return parts[2]; | |
169 } | |
170 } // end of class ExternalWMSState | |
171 } | |
172 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |