diff flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java @ 445:a7947972fdeb

Added a new class that supports formatters for different types of data. flys-artifacts/trunk@1937 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 17 May 2011 14:22:27 +0000
parents e0fec407a280
children 45cd58a2a2bb
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Tue May 17 11:53:02 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Tue May 17 14:22:27 2011 +0000
@@ -3,8 +3,6 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.text.NumberFormat;
-import java.util.Locale;
 
 import org.w3c.dom.Document;
 
@@ -15,6 +13,9 @@
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
 import de.intevation.flys.artifacts.resources.Resources;
 
 
@@ -39,6 +40,9 @@
     /** The default separator for the CSV export.*/
     public static final char DEFAULT_CSV_SEPARATOR = ',';
 
+    /** XPath that points to the desired export facet.*/
+    public static final String XPATH_FACET = "/art:action/@art:type";
+
 
     /** The document of the incoming out() request.*/
     protected Document request;
@@ -141,21 +145,44 @@
     protected boolean isFacetValid(String facet) {
         logger.debug("AbstractExporter.isFacetValid");
 
-        if (facet == null || facet.length() == 0) {
+        String thisFacet = getFacet();
+
+        if (thisFacet == null || thisFacet.length() == 0) {
             return false;
         }
-        else if (this.facet == null || this.facet.length() == 0) {
-            logger.debug("Set the facet of this export: " + facet);
-            this.facet = facet;
-
-            return true;
+        else if (facet == null || facet.length() == 0) {
+            return false;
         }
         else {
-            return this.facet.equals(facet);
+            return thisFacet.equals(facet);
         }
     }
 
 
+    /**
+     * Returns the name of the desired facet.
+     *
+     * @return the name of the desired facet.
+     */
+    protected String getFacet() {
+        if (facet == null) {
+            facet = getFacetFromRequest();
+        }
+
+        return facet;
+    }
+
+
+    /**
+     * Extracts the name of the requested facet from request document.
+     *
+     * @return the name of the requested facet.
+     */
+    protected String getFacetFromRequest() {
+        return XMLUtils.xpathString(
+            request, XPATH_FACET, ArtifactNamespaceContext.INSTANCE);
+    }
+
 
     protected String msg(String key, String def) {
         return Resources.getMsg(context.getMeta(), key, def);
@@ -181,16 +208,5 @@
 
         writer.close();
     }
-
-
-    protected NumberFormat getFormatter(int min, int max) {
-        Locale       locale = Resources.getLocale(context.getMeta());
-        NumberFormat nf     = NumberFormat.getInstance(locale);
-
-        nf.setMaximumFractionDigits(max);
-        nf.setMinimumFractionDigits(min);
-
-        return nf;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org