view gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVDefaultArtifact.java @ 1117:dec4257ad570

Changed imports to fit new positions of XMLUtils and Config gnv-artifacts/trunk@1478 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 15 Mar 2011 16:13:39 +0000
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.artifacts;

import de.intevation.artifactdatabase.DefaultArtifact;
import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.artifacts.ArtifactNamespaceContext;
import de.intevation.artifacts.CallContext;
import de.intevation.artifacts.CallMeta;

import de.intevation.gnv.artifacts.ressource.RessourceFactory;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * The default gnv artifact. The only thing defined here is a method to append
 * the selected fis to the describe document.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class GNVDefaultArtifact extends DefaultArtifact {

    private static Logger logger = Logger.getLogger(GNVDefaultArtifact.class);

    /**
     *
     */
    public static final String EXCEPTION_NO_INPUT = "no.input.data";


    /**
     * Constructor.
     */
    public GNVDefaultArtifact() {
        super();
    }


    /**
     * Append the selected fis to the describe document.
     *
     * @param document
     * @param staticNode
     * @param context
     * @param fisName
     */
    protected void appendFis(
        Document    document,
        Element     staticNode,
        CallContext context,
        String      fisName
    ) {
        RessourceFactory resource = RessourceFactory.getInstance();
        CallMeta callMeta         = (CallMeta) context.getMeta();

        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
            document,
            XMLUtils.XFORM_URL,
            XMLUtils.XFORM_PREFIX
        );

        XMLUtils.ElementCreator artCreator = new XMLUtils.ElementCreator(
            document,
            ArtifactNamespaceContext.NAMESPACE_URI,
            ArtifactNamespaceContext.NAMESPACE_PREFIX
        );

        Element selectNode = creator.create("select1");
        artCreator.addAttr(selectNode, "fis", "true", true);

        Element labelNode = creator.create("label");
        labelNode.setTextContent(
            resource.getRessource(callMeta.getLanguages(), "fis", "fis")
        );

        Element choicesNode = creator.create("choices");

        Element itemNode = creator.create("item");
        creator.addAttr(itemNode, "selected", "true");

        Element choiceLabel = creator.create("label");
        choiceLabel.setTextContent(resource.getRessource(
            callMeta.getLanguages(),
            fisName,
            fisName
        ));

        Element choiceValue = creator.create("value");
        choiceValue.setTextContent(fisName);

        itemNode.appendChild(choiceLabel);
        itemNode.appendChild(choiceValue);
        choicesNode.appendChild(itemNode);

        selectNode.appendChild(labelNode);
        selectNode.appendChild(choicesNode);

        staticNode.appendChild(selectNode);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org