Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | f953c9a559d8 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.exports; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.io.ParseException; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.state.exception.StateException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.log4j.Logger; /** * This class is a specialization of {@link ShapeDataCollector} and turns * furthermore a given datetime string into a specific format. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class SimpleOdvDataCollector extends ShapeDataCollector { /** * Logger used for logging with log4j. */ private static Logger log = Logger.getLogger(SimpleOdvDataCollector.class); /** * Constant field which defines the source format of a given datetime. */ public static final String SRC_FORMAT = "yyyy.MM.dd HH:mm:ss"; /** * Constant field which defines the target format of a given datetime. */ public static final String DEST_FORMAT = "yyyy-MM-dd HH:mm"; /** * Source format. */ public static DateFormat srcFormat = new SimpleDateFormat(SRC_FORMAT); /** * Target format. */ public static DateFormat destFormat = new SimpleDateFormat(DEST_FORMAT); /** * Constructor * * @param names See {@link #names} */ public SimpleOdvDataCollector(String[] names) { super(names); } /** * Given datetime values which corresponds to the attribute key 'TIMEVALUE' * are transformed from {@link #SRC_FORMAT} into {@link #DEST_FORMAT}. * * @see de.intevation.gnv.exports.Export.DataCollector#getData(Result) */ public String[] getData(Result result) throws StateException { if (rd == null) init(result); try { String [] entries = new String[names.length+1]; int j = 0; for (int i = 0; i < names.length; i++) { if (names[i].equals("SHAPE")) { Point p = (Point)wktReader.read(result.getString("SHAPE")); entries[j++] = ""+p.getX(); entries[j++] = ""+p.getY(); } // Change the datetime format from yyyy.MM.dd HH:mm:ss to // yyyy-MM-dd HH:mm else if (names[i].equals("TIMEVALUE")) { Date source = srcFormat.parse(result.getString(names[i])); entries[j++] = destFormat.format(source); } else { entries[j++] = result.getString(names[i]); } } return entries; } catch (ParseException pe) { log.error(pe, pe); throw new StateException( "Error occured while parsing source data."); } catch (java.text.ParseException pe) { log.error(pe, pe); throw new StateException( "Error occured while parsing source data."); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :