tom@8858: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde tom@8858: * Software engineering by Intevation GmbH tom@8858: * tom@8858: * This file is Free Software under the GNU AGPL (>=v3) tom@8858: * and comes with ABSOLUTELY NO WARRANTY! Check out the tom@8858: * documentation coming with Dive4Elements River for details. tom@8858: */ tom@8858: rrenkert@8251: package org.dive4elements.river.exports.injector; rrenkert@8251: tom@9726: import org.apache.logging.log4j.Logger; tom@9726: import org.apache.logging.log4j.LogManager; rrenkert@8251: import org.dive4elements.artifacts.Artifact; rrenkert@8251: import org.dive4elements.artifacts.CallContext; rrenkert@8251: import org.dive4elements.artifacts.ContextInjector; rrenkert@8251: import org.dive4elements.river.artifacts.D4EArtifact; rrenkert@8251: import org.dive4elements.river.artifacts.access.RangeAccess; rrenkert@8251: import org.w3c.dom.Document; rrenkert@8251: import org.w3c.dom.Element; rrenkert@8251: rrenkert@8251: import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; rrenkert@8251: tom@8349: public class KmFromLocationInjector rrenkert@8251: implements ContextInjector rrenkert@8251: { rrenkert@8251: tom@9726: private static Logger log = LogManager.getLogger(KmFromLocationInjector.class); rrenkert@8251: rrenkert@8251: @Override rrenkert@8251: public void setup(Element cfg) { rrenkert@8251: } rrenkert@8251: rrenkert@8251: @Override rrenkert@8251: public void injectContext( rrenkert@8251: CallContext ctx, rrenkert@8251: Artifact artifact, rrenkert@8251: Document doc rrenkert@8251: ) { tom@8367: if (ctx.getContextValue(CURRENT_KM) instanceof Number) { tom@8367: return; tom@8367: } tom@8367: rrenkert@8251: RangeAccess access = new RangeAccess((D4EArtifact)artifact); tom@8349: if (access.getLocations() != null && rrenkert@8326: access.getLocations().length > 0) { rrenkert@8326: ctx.putContextValue(CURRENT_KM, access.getLocations()[0]); tom@8349: return; tom@8310: } tom@8349: log.warn("No locations accessible."); rrenkert@8251: } rrenkert@8251: }