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