view artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java @ 9402:e511eb935ccd

Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names
author mschaefer
date Tue, 14 Aug 2018 14:04:01 +0200
parents 4a6cc7c6716a
children e2da9c8a7c57
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.artifacts.datacage.templating;

import java.util.List;
import java.util.UUID;

import javax.xml.xpath.XPathFunction;
import javax.xml.xpath.XPathFunctionException;

import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.access.RiverAccess;
import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZone;
import org.dive4elements.river.utils.RiverUtils;

/**
 * Very specialized function that fetches the default vegetation zones for the river specified by an artifact
 *
 * @author Gernot Belger
 */
public class DefaultVegetationZoneXPathFunction implements XPathFunction {

    public static final String ID = "defaultvegetationzone";

    public static final int ARITY = 1;

    private final CallContext context;

    public DefaultVegetationZoneXPathFunction(final CallContext context) {
        this.context = context;
    }

    @Override
    public Object evaluate(final List args) throws XPathFunctionException {

        final UUID uuid = (UUID) args.get(0);
        if (uuid == null)
            return null;

        final D4EArtifact artifact = RiverUtils.getArtifact(uuid.toString(), this.context);

        final RiverAccess access = new RiverAccess(artifact);

        return VegetationZone.parseListToDataString(VegetationZone.getStandardList(access.getRiver(), this.context));
    }
}

http://dive4elements.wald.intevation.org