Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java @ 772:cd64ab8a46a7
Put time to live of an artifact into meta document which is created while wms publishing (issue197).
gnv-artifacts/trunk@829 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 09:21:31 +0000 |
parents | 452fad121560 |
children | 5fb1ea68e19c |
comparison
equal
deleted
inserted
replaced
771:a0e63136954e | 772:cd64ab8a46a7 |
---|---|
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.FileNotFoundException; | 4 import java.io.FileNotFoundException; |
5 import java.io.FileOutputStream; | 5 import java.io.FileOutputStream; |
6 import java.io.IOException; | 6 import java.io.IOException; |
7 import java.io.OutputStream; | 7 import java.io.OutputStream; |
8 import java.util.Date; | |
8 | 9 |
9 import org.apache.log4j.Logger; | 10 import org.apache.log4j.Logger; |
10 import org.w3c.dom.Document; | 11 import org.w3c.dom.Document; |
11 import org.w3c.dom.Element; | 12 import org.w3c.dom.Element; |
12 | 13 |
24 private static Logger logger = Logger.getLogger(MetaWriter.class); | 25 private static Logger logger = Logger.getLogger(MetaWriter.class); |
25 | 26 |
26 public static final String NODE_MAPSERVER = "mapserver"; | 27 public static final String NODE_MAPSERVER = "mapserver"; |
27 public static final String NODE_SERVER = "server"; | 28 public static final String NODE_SERVER = "server"; |
28 public static final String NODE_MAP = "map"; | 29 public static final String NODE_MAP = "map"; |
30 public static final String NODE_TTL = "ttl"; | |
29 | 31 |
30 public static final String META_FILE_NAME = "meta.xml"; | 32 public static final String META_FILE_NAME = "meta.xml"; |
31 public static final String ISOLINES_NAME = "isolines.shp"; | 33 public static final String ISOLINES_NAME = "isolines.shp"; |
32 public static final String POLYGON_NAME = "polygons.shp"; | 34 public static final String POLYGON_NAME = "polygons.shp"; |
33 public static final String LAYER_DATA_NAME = "data.shp"; | 35 public static final String LAYER_DATA_NAME = "data.shp"; |
154 context.get(GNVArtifactContext.MAPSERVER_SERVER_PATH_KEY); | 156 context.get(GNVArtifactContext.MAPSERVER_SERVER_PATH_KEY); |
155 | 157 |
156 String map = (String) | 158 String map = (String) |
157 context.get(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY); | 159 context.get(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY); |
158 | 160 |
159 logger.debug("MAPSERVER PATH: " + server); | 161 if (logger.isDebugEnabled()) { |
160 logger.debug("MAP PATH: " + map); | 162 logger.debug("MAPSERVER PATH: " + server); |
163 logger.debug("MAP PATH: " + map); | |
164 } | |
161 | 165 |
162 Element mapserver = creator.create(NODE_MAPSERVER); | 166 Element mapserver = creator.create(NODE_MAPSERVER); |
163 Element serverPath = creator.create(NODE_SERVER); | 167 Element serverPath = creator.create(NODE_SERVER); |
164 Element mapPath = creator.create(NODE_MAP); | 168 Element mapPath = creator.create(NODE_MAP); |
165 | 169 |
170 mapserver.appendChild(mapPath); | 174 mapserver.appendChild(mapPath); |
171 meta.appendChild(mapserver); | 175 meta.appendChild(mapserver); |
172 } | 176 } |
173 | 177 |
174 protected static void writeLayerMeta( | 178 protected static void writeLayerMeta( |
175 CallContext context, | 179 CallContext callContext, |
176 Document document, | 180 Document document, |
177 Element meta, | 181 Element meta, |
178 String uuid, | 182 String uuid, |
179 String paramType, | 183 String paramType, |
180 String layerType | 184 String layerType |
182 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | 186 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
183 document, | 187 document, |
184 ArtifactNamespaceContext.NAMESPACE_URI, | 188 ArtifactNamespaceContext.NAMESPACE_URI, |
185 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 189 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
186 | 190 |
187 Element layer = creator.create(LayerInfo.LAYER); | 191 Long time = callContext.getTimeToLive(); |
188 Element model = creator.create(LayerInfo.LAYER_MODEL); | 192 time += new Date().getTime(); |
189 Element name = creator.create(LayerInfo.LAYER_NAME); | 193 String ttl = time != null ? time.toString() : null; |
190 Element type = creator.create(LayerInfo.LAYER_TYPE); | 194 |
191 Element status = creator.create(LayerInfo.LAYER_STATUS); | 195 logger.debug("Artifacts time to live: " + ttl); |
192 Element data = creator.create(LayerInfo.LAYER_DATA); | 196 |
197 Element layer = creator.create(LayerInfo.LAYER); | |
198 Element model = creator.create(LayerInfo.LAYER_MODEL); | |
199 Element name = creator.create(LayerInfo.LAYER_NAME); | |
200 Element type = creator.create(LayerInfo.LAYER_TYPE); | |
201 Element status = creator.create(LayerInfo.LAYER_STATUS); | |
202 Element data = creator.create(LayerInfo.LAYER_DATA); | |
203 Element timeToLive = creator.create(NODE_TTL); | |
193 | 204 |
194 model.setTextContent(paramType); | 205 model.setTextContent(paramType); |
195 name.setTextContent(uuid); | 206 name.setTextContent(uuid); |
196 type.setTextContent(layerType); | 207 type.setTextContent(layerType); |
197 status.setTextContent("OFF"); | 208 status.setTextContent("OFF"); |
198 data.setTextContent(LAYER_DATA_NAME); | 209 data.setTextContent(LAYER_DATA_NAME); |
210 timeToLive.setTextContent(ttl); | |
199 | 211 |
200 layer.appendChild(model); | 212 layer.appendChild(model); |
201 layer.appendChild(name); | 213 layer.appendChild(name); |
202 layer.appendChild(type); | 214 layer.appendChild(type); |
203 layer.appendChild(status); | 215 layer.appendChild(status); |
204 layer.appendChild(data); | 216 layer.appendChild(data); |
217 layer.appendChild(timeToLive); | |
205 | 218 |
206 meta.appendChild(layer); | 219 meta.appendChild(layer); |
207 } | 220 } |
208 | 221 |
209 | 222 |
218 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | 231 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
219 document, | 232 document, |
220 ArtifactNamespaceContext.NAMESPACE_URI, | 233 ArtifactNamespaceContext.NAMESPACE_URI, |
221 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 234 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
222 | 235 |
236 Long time = context.getTimeToLive(); | |
237 time += new Date().getTime(); | |
238 String ttl = time != null ? time.toString() : null; | |
239 | |
240 logger.debug("Artifacts time to live: " + ttl); | |
241 | |
223 Element layer = creator.create(LayerInfo.LAYER); | 242 Element layer = creator.create(LayerInfo.LAYER); |
224 Element model = creator.create(LayerInfo.LAYER_MODEL); | 243 Element model = creator.create(LayerInfo.LAYER_MODEL); |
225 Element name = creator.create(LayerInfo.LAYER_NAME); | 244 Element name = creator.create(LayerInfo.LAYER_NAME); |
226 Element title = creator.create(LayerInfo.LAYER_TITLE); | 245 Element title = creator.create(LayerInfo.LAYER_TITLE); |
227 Element type = creator.create(LayerInfo.LAYER_TYPE); | 246 Element type = creator.create(LayerInfo.LAYER_TYPE); |
228 Element status = creator.create(LayerInfo.LAYER_STATUS); | 247 Element status = creator.create(LayerInfo.LAYER_STATUS); |
229 Element data = creator.create(LayerInfo.LAYER_DATA); | 248 Element data = creator.create(LayerInfo.LAYER_DATA); |
249 Element timeToLive = creator.create(NODE_TTL); | |
230 | 250 |
231 model.setTextContent(paramType); | 251 model.setTextContent(paramType); |
232 name.setTextContent(uuid); | 252 name.setTextContent(uuid); |
233 title.setTextContent( | 253 title.setTextContent( |
234 (String) context.getContextValue(CONTEXT_LAYER_TITLE)); | 254 (String) context.getContextValue(CONTEXT_LAYER_TITLE)); |
235 type.setTextContent("POLYGON"); | 255 type.setTextContent("POLYGON"); |
236 status.setTextContent("OFF"); | 256 status.setTextContent("OFF"); |
237 data.setTextContent(POLYGON_NAME); | 257 data.setTextContent(POLYGON_NAME); |
258 timeToLive.setTextContent(ttl); | |
238 | 259 |
239 layer.appendChild(model); | 260 layer.appendChild(model); |
240 layer.appendChild(name); | 261 layer.appendChild(name); |
241 layer.appendChild(title); | 262 layer.appendChild(title); |
242 layer.appendChild(type); | 263 layer.appendChild(type); |
243 layer.appendChild(status); | 264 layer.appendChild(status); |
244 layer.appendChild(data); | 265 layer.appendChild(data); |
266 layer.appendChild(timeToLive); | |
245 | 267 |
246 meta.appendChild(layer); | 268 meta.appendChild(layer); |
247 } | 269 } |
248 | 270 |
249 | 271 |
258 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | 280 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
259 document, | 281 document, |
260 ArtifactNamespaceContext.NAMESPACE_URI, | 282 ArtifactNamespaceContext.NAMESPACE_URI, |
261 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 283 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
262 | 284 |
285 Long time = context.getTimeToLive(); | |
286 time += new Date().getTime(); | |
287 String ttl = time != null ? time.toString() : null; | |
288 | |
289 logger.debug("Artifacts time to live: " + ttl); | |
290 | |
263 Element layer = creator.create(LayerInfo.LAYER); | 291 Element layer = creator.create(LayerInfo.LAYER); |
264 Element model = creator.create(LayerInfo.LAYER_MODEL); | 292 Element model = creator.create(LayerInfo.LAYER_MODEL); |
265 Element name = creator.create(LayerInfo.LAYER_NAME); | 293 Element name = creator.create(LayerInfo.LAYER_NAME); |
266 Element title = creator.create(LayerInfo.LAYER_TITLE); | 294 Element title = creator.create(LayerInfo.LAYER_TITLE); |
267 Element type = creator.create(LayerInfo.LAYER_TYPE); | 295 Element type = creator.create(LayerInfo.LAYER_TYPE); |
268 Element status = creator.create(LayerInfo.LAYER_STATUS); | 296 Element status = creator.create(LayerInfo.LAYER_STATUS); |
269 Element data = creator.create(LayerInfo.LAYER_DATA); | 297 Element data = creator.create(LayerInfo.LAYER_DATA); |
298 Element timeToLive = creator.create(NODE_TTL); | |
270 | 299 |
271 model.setTextContent(paramType+"_isolines"); | 300 model.setTextContent(paramType+"_isolines"); |
272 name.setTextContent(uuid); | 301 name.setTextContent(uuid); |
273 title.setTextContent( | 302 title.setTextContent( |
274 (String) context.getContextValue(CONTEXT_LAYER_TITLE)); | 303 (String) context.getContextValue(CONTEXT_LAYER_TITLE)); |
275 type.setTextContent("LINE"); | 304 type.setTextContent("LINE"); |
276 status.setTextContent("OFF"); | 305 status.setTextContent("OFF"); |
277 data.setTextContent(ISOLINES_NAME); | 306 data.setTextContent(ISOLINES_NAME); |
307 timeToLive.setTextContent(ttl); | |
278 | 308 |
279 layer.appendChild(model); | 309 layer.appendChild(model); |
280 layer.appendChild(name); | 310 layer.appendChild(name); |
281 layer.appendChild(title); | 311 layer.appendChild(title); |
282 layer.appendChild(type); | 312 layer.appendChild(type); |
283 layer.appendChild(status); | 313 layer.appendChild(status); |
284 layer.appendChild(data); | 314 layer.appendChild(data); |
315 layer.appendChild(timeToLive); | |
285 | 316 |
286 meta.appendChild(layer); | 317 meta.appendChild(layer); |
287 } | 318 } |
288 } | 319 } |
289 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 320 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |