diff flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java @ 870:d5fb88ba99d2

Display status message and progress information in the WSPLGEN loading panel. flys-client/trunk@2690 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 09 Sep 2011 15:08:15 +0000
parents c9549074ecd1
children ab8eb2f544f2
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java	Thu Sep 08 12:49:24 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java	Fri Sep 09 15:08:15 2011 +0000
@@ -1,6 +1,13 @@
 package de.intevation.flys.client.server;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.xpath.XPathConstants;
+
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.artifacts.common.ArtifactNamespaceContext;
@@ -8,6 +15,7 @@
 import de.intevation.artifacts.httpclient.utils.ArtifactCreator;
 
 import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.CalculationMessage;
 import de.intevation.flys.client.shared.model.DefaultArtifact;
 import de.intevation.flys.client.shared.model.WINFOArtifact;
 
@@ -32,8 +40,12 @@
 
     /** The XPath to the value that determines if the artifact is processing in
      * background.*/
+    public static final String XPATH_BACKGROUND_VALUE =
+        "/art:result/art:background-processing/@art:value";
+
+    /** The XPath that points to the (if existing) background messages.*/
     public static final String XPATH_BACKGROUND =
-        "/art:result/art:background-processing/@art:value";
+        "/art:result/art:background-processing";
 
 
     /**
@@ -82,30 +94,82 @@
             doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE);
 
         String backgroundStr = XMLUtils.xpathString(
-            doc, XPATH_BACKGROUND, ArtifactNamespaceContext.INSTANCE);
+            doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE);
 
         boolean background = false;
         if (backgroundStr != null && backgroundStr.length() > 0) {
             background = Boolean.valueOf(backgroundStr);
         }
 
+        List<CalculationMessage> msg = parseBackgroundMessages(doc);
+
         System.out.println("NEW Artifact UUID: " + uuid);
         System.out.println("NEW Artifact HASH: " + hash);
         System.out.println("NEW Artifact NAME: " + name);
         System.out.println("NEW Artifact IN BACKGROUND: " + background);
 
         if (name == null) {
-            return new DefaultArtifact(uuid, hash, background);
+            return new DefaultArtifact(uuid, hash, background, msg);
         }
 
         name = name.trim();
 
         if (name.length() > 0 && name.equals("winfo")) {
             System.out.println("+++++ NEW WINFO ARTIFACT.");
-            return new WINFOArtifact(uuid, hash, background);
+            return new WINFOArtifact(uuid, hash, background, msg);
         }
 
-        return new DefaultArtifact(uuid, hash, background);
+        return new DefaultArtifact(uuid, hash, background, msg);
+    }
+
+
+    public static List<CalculationMessage> parseBackgroundMessages(Document d) {
+        NodeList list = (NodeList) XMLUtils.xpath(
+            d, XPATH_BACKGROUND, XPathConstants.NODESET,
+            ArtifactNamespaceContext.INSTANCE);
+
+        int len = list != null ? list.getLength() : 0;
+
+        System.out.println("Found " + len + " background messages.");
+
+        List<CalculationMessage> res = new ArrayList<CalculationMessage>(len);
+
+        for (int i = 0; i < len; i++) {
+            CalculationMessage msg = parseBackgroundMessage(
+                (Element) list.item(i));
+
+            if (msg != null) {
+                res.add(msg);
+            }
+        }
+
+        return res;
+    }
+
+
+    public static CalculationMessage parseBackgroundMessage(Element e) {
+        String steps       = e.getAttribute("art:steps");
+        String currentStep = e.getAttribute("art:currentStep");
+        String message     = e.getTextContent();
+
+        int lenCurStep = currentStep != null ? currentStep.length() : 0;
+        int lenSteps   = steps       != null ? steps.length()       : 0;
+        int lenMessage = message     != null ? message.length()     : 0;
+
+        if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) {
+            try {
+                return new CalculationMessage(
+                    Integer.parseInt(steps),
+                    Integer.parseInt(currentStep),
+                    message);
+
+            }
+            catch (NumberFormatException nfe) {
+                nfe.printStackTrace();
+            }
+        }
+
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org