Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java @ 2618:3a93bbbe2ec7
Fix for 'W free' validation and theme names.
flys-artifacts/trunk@4203 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 05 Apr 2012 15:29:25 +0000 |
parents | b0597a63fe70 |
children | cc0fa1798a3c |
line wrap: on
line source
package de.intevation.flys.artifacts.services; import java.util.List; import de.intevation.artifactdatabase.DefaultService; import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.GlobalContext; import de.intevation.artifacts.Service; import de.intevation.flys.artifacts.model.FixingsFilterBuilder; import de.intevation.flys.artifacts.model.FixingsOverview; import de.intevation.flys.artifacts.model.FixingsColumn; import de.intevation.flys.artifacts.model.FixingsColumnFactory; import de.intevation.flys.artifacts.model.FixingsOverviewFactory; import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; import de.intevation.flys.backend.SessionHolder; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class FixingsKMChartService extends DefaultService { private static final Logger log = Logger.getLogger(FixingsKMChartService.class); public static final byte [] EMPTY = { (byte)0x89, (byte)0x50, (byte)0x4e, (byte)0x47, (byte)0x0d, (byte)0x0a, (byte)0x1a, (byte)0x0a, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x3a, (byte)0x7e, (byte)0x9b, (byte)0x55, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x73, (byte)0x52, (byte)0x47, (byte)0x42, (byte)0x00, (byte)0xae, (byte)0xce, (byte)0x1c, (byte)0xe9, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x09, (byte)0x70, (byte)0x48, (byte)0x59, (byte)0x73, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x13, (byte)0x00, (byte)0x00, (byte)0x0b, (byte)0x13, (byte)0x01, (byte)0x00, (byte)0x9a, (byte)0x9c, (byte)0x18, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x74, (byte)0x49, (byte)0x4d, (byte)0x45, (byte)0x07, (byte)0xdc, (byte)0x04, (byte)0x04, (byte)0x10, (byte)0x30, (byte)0x15, (byte)0x7d, (byte)0x77, (byte)0x36, (byte)0x0b, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x74, (byte)0x45, (byte)0x58, (byte)0x74, (byte)0x43, (byte)0x6f, (byte)0x6d, (byte)0x6d, (byte)0x65, (byte)0x6e, (byte)0x74, (byte)0x00, (byte)0xf6, (byte)0xcc, (byte)0x96, (byte)0xbf, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0a, (byte)0x49, (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x08, (byte)0xd7, (byte)0x63, (byte)0xf8, (byte)0x0f, (byte)0x00, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x00, (byte)0x1b, (byte)0xb6, (byte)0xee, (byte)0x56, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4e, (byte)0x44, (byte)0xae, (byte)0x42, (byte)0x60, (byte)0x82 }; private static final Output empty() { return new Output(EMPTY, "image/png"); } @Override public Service.Output process( Document data, GlobalContext globalContext, CallMeta callMeta ) { log.debug("FixingsKMChartService.process"); SessionHolder.acquire(); try { return doProcess(data, globalContext, callMeta); } finally { SessionHolder.HOLDER.get().close(); SessionHolder.release(); } } protected Service.Output doProcess( Document data, GlobalContext globalContext, CallMeta callMeta ) { NodeList rivers = data.getElementsByTagName("river"); NodeList kms = data.getElementsByTagName("km"); if (rivers.getLength() == 0 || kms.getLength() == 0) { log.warn("Missing river and/or km."); return empty(); } String river = ((Element)rivers.item(0)).getAttribute("name"); String kmS = ((Element)kms .item(0)).getAttribute("value"); if (river.length() == 0 || kmS.length() == 0) { log.warn("River and/or km empty string."); return empty(); } double km; try { km = Double.parseDouble(kmS); } catch (NumberFormatException nfe) { log.warn("Km '" + kmS + " is not a valid number."); return empty(); } FixingsOverview overview = FixingsOverviewFactory.getOverview(river); if (overview == null) { log.warn("No overview found for river '" + river + "'"); return empty(); } FixingsFilterBuilder ffb = new FixingsFilterBuilder(data); List<Fixing.Column> columns = overview.filter( ffb.getRange(), ffb.getFilter()); for (Fixing.Column column: columns) { FixingsColumn columnData = FixingsColumnFactory.INSTANCE.getColumnData(column); if (columnData == null) { continue; } } // TODO: Implement chart generation! return empty(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :