diff flys-aft/src/main/java/de/intevation/aft/Sync.java @ 4083:44dc38ca8492

Added an optional XSL transformation to fix the raw DIPS files. flys-aft/trunk@3513 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 21 Dec 2011 14:56:29 +0000
parents 97de7a552b79
children 859b4781554a
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/Sync.java	Tue Dec 20 14:36:36 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java	Wed Dec 21 14:56:29 2011 +0000
@@ -6,6 +6,8 @@
 
 import org.w3c.dom.Document;
 
+import org.apache.log4j.Logger;
+
 import javax.xml.xpath.XPathConstants;
 
 import de.intevation.utils.XML;
@@ -14,10 +16,13 @@
 
 public class Sync
 {
+    private static Logger log = Logger.getLogger(Sync.class);
+
     public static final String FLYS = "flys";
     public static final String AFT  = "aft";
 
-    public static final String XPATH_DIPS = "/sync/dips/@file";
+    public static final String XPATH_DIPS   = "/sync/dips/file/text()";
+    public static final String XPATH_REPAIR = "/sync/dips/repair/text()";
 
     public static final String CONFIG_FILE =
         System.getProperty("config.file", "config.xml");
@@ -27,14 +32,14 @@
         File configFile = new File(CONFIG_FILE);
 
         if (!configFile.isFile() || !configFile.canRead()) {
-            System.err.println("cannot read config file");
+            log.error("cannot read config file");
             System.exit(1);
         }
 
         Document config = XML.parseDocument(configFile, Boolean.FALSE);
 
         if (config == null) {
-            System.err.println("cannot load config");
+            log.error("Cannot load config file.");
             System.exit(1);
         }
 
@@ -42,24 +47,44 @@
             config, XPATH_DIPS, XPathConstants.STRING, null, null);
 
         if (dipsF == null || dipsF.length() == 0) {
-            System.err.println("Cannot find path to DiPS xml in config.");
+            log.error("Cannot find path to DIPS XML in config.");
             System.exit(1);
         }
 
         File dipsFile = new File(dipsF);
 
         if (!dipsFile.isFile() || !dipsFile.canRead()) {
-            System.err.println("Cannot find '" + dipsF + "'");
+            log.error("Cannot find '" + dipsF + "'");
             System.exit(1);
         }
 
         Document dips = XML.parseDocument(dipsFile, Boolean.FALSE);
 
         if (dips == null) {
-            System.err.println("Cannot load DiPs document.");
+            log.error("Cannot load DIPS document.");
             System.exit(1);
         }
 
+        String repairF = (String)XML.xpath(
+            config, XPATH_REPAIR, XPathConstants.STRING, null, null);
+
+        if (repairF != null && repairF.length() > 0) {
+            File repairFile = new File(repairF);
+            if (!repairFile.isFile() || !repairFile.canRead()) {
+                log.warn("Cannot open DIPS repair XSLT file.");
+            }
+            else {
+                Document fixed = XML.transform(dips, repairFile);
+                if (fixed == null) {
+                    log.warn("Fixing DIPS failed");
+                }
+                else {
+                    dips = fixed;
+                }
+            }
+        }
+ 
+
         ConnectionBuilder aftConnectionBuilder =
             new ConnectionBuilder(AFT, config);
 
@@ -76,8 +101,7 @@
             rivers.sync(syncContext);
         }
         catch (SQLException sqle) {
-            sqle.printStackTrace();
-            System.err.println("syncing failed: " + sqle.getMessage());
+            log.error("syncing failed", sqle);
         }
         finally {
             if (syncContext != null) {

http://dive4elements.wald.intevation.org